mediawiki-extensions-Confir.../tests/phpunit/HTMLFancyCaptchaFieldTest.php
Daimona Eaytoy 32f9cf26a6 Replace assertNotRegExp -> assertDoesNotMatchRegularExpression
Follow-up to I6859b48f7a9084101e981fb48449c1c1dc17a80c.

Bug: T243600
Change-Id: Ifdba0f9e98eb6bce4590b7eb73170c51a697d7c6
2022-10-07 16:52:36 +02:00

46 lines
1.7 KiB
PHP

<?php
/**
* @covers HTMLFancyCaptchaField
*/
class HTMLFancyCaptchaFieldTest extends MediaWikiIntegrationTestCase {
public function testGetHTML() {
$html = $this->getForm( [ 'imageUrl' => 'https://example.com/' ] )->getHTML( false );
$this->assertMatchesRegularExpression( '/"fancycaptcha-image"/', $html );
$this->assertMatchesRegularExpression( '#src="https://example.com/"#', $html );
$this->assertDoesNotMatchRegularExpression( '/"mw-createacct-captcha-assisted"/', $html );
$html = $this->getForm( [ 'imageUrl' => '', 'showCreateHelp' => true ] )->getHTML( false );
$this->assertMatchesRegularExpression( '/"mw-createacct-captcha-assisted"/', $html );
$html = $this->getForm( [ 'imageUrl' => '', 'label' => 'FooBarBaz' ] )->getHTML( false );
$this->assertMatchesRegularExpression( '/FooBarBaz/', $html );
}
public function testValue() {
$mockClosure = $this->getMockBuilder( stdClass::class )
->addMethods( [ '__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 ) {
if ( $request ) {
$context = new DerivativeContext( RequestContext::getMain() );
$context->setRequest( $request );
} else {
$context = RequestContext::getMain();
}
$params['class'] = HTMLFancyCaptchaField::class;
$form = new HTMLForm( [ 'captchaWord' => $params ], $context );
$form->setTitle( Title::newFromText( 'Foo' ) );
$form->prepareForm();
return $form;
}
}