mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-29 02:14:27 +00:00
08bfd32590
Change-Id: Ide145e5755e0bec11fe19c18889c92a0e9d78037
46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../../FancyCaptcha/HTMLFancyCaptchaField.php';
|
|
|
|
/**
|
|
* @covers HTMLFancyCaptchaField
|
|
*/
|
|
class HTMLFancyCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
|
public function testGetHTML() {
|
|
$html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false );
|
|
$this->assertRegExp( '/"fancycaptcha-image"/', $html );
|
|
$this->assertRegExp( '#src="https://example.com/"#', $html );
|
|
$this->assertNotRegExp( '/"mw-createacct-captcha-assisted"/', $html );
|
|
|
|
$html = $this->getForm( [ 'imageUrl' => '', 'showCreateHelp' => true ] )->getHTML( false );
|
|
$this->assertRegExp( '/"mw-createacct-captcha-assisted"/', $html );
|
|
|
|
$html = $this->getForm( [ 'imageUrl' => '', 'label' => 'FooBarBaz' ] )->getHTML( false );
|
|
$this->assertRegExp( '/FooBarBaz/', $html );
|
|
}
|
|
|
|
public function testValue() {
|
|
$mockClosure = $this->getMockBuilder( 'object' )->setMethods( [ '__invoke' ] )->getMock();
|
|
$request = new FauxRequest( [ 'wpcaptchaWord' => 'abc' ], true );
|
|
$form = $this->getForm( [ 'imageUrl' => 'https://example.com/' ], $request );
|
|
$form->setSubmitCallback( $mockClosure );
|
|
|
|
$mockClosure->expects( $this->once() )->method( '__invoke' )
|
|
->with( [ 'captchaWord' => 'abc' ] )->willReturn( true );
|
|
$form->trySubmit();
|
|
}
|
|
|
|
protected function getForm( $params = [], WebRequest $request = null ) {
|
|
$params['class'] = HTMLFancyCaptchaField::class;
|
|
$form = new HTMLForm( [ 'captchaWord' => $params ] );
|
|
if ( $request ) {
|
|
$context = new DerivativeContext( RequestContext::getMain() );
|
|
$context->setRequest( $request );
|
|
$form->setContext( $context );
|
|
}
|
|
$form->setTitle( Title::newFromText( 'Foo' ) );
|
|
$form->prepareForm();
|
|
return $form;
|
|
}
|
|
}
|