2016-04-25 20:58:18 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-23 23:59:08 +00:00
|
|
|
/**
|
|
|
|
* @covers HTMLFancyCaptchaField
|
|
|
|
*/
|
2018-02-15 09:34:50 +00:00
|
|
|
class HTMLFancyCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
2016-04-25 20:58:18 +00:00
|
|
|
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() {
|
2018-10-09 12:09:10 +00:00
|
|
|
$mockClosure = $this->getMockBuilder( stdClass::class )
|
2021-05-03 07:10:28 +00:00
|
|
|
->addMethods( [ '__invoke' ] )->getMock();
|
2016-04-25 20:58:18 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|