mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-30 10:54:53 +00:00
tests: Pass context to HTMLForm constructor
Change-Id: I8777b2b2d6a87695f6517f259f31a177356ac8f5
This commit is contained in:
parent
58d604af5b
commit
5880031d1c
|
@ -30,13 +30,14 @@ class HTMLFancyCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
|||
}
|
||||
|
||||
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 );
|
||||
} else {
|
||||
$context = RequestContext::getMain();
|
||||
}
|
||||
$params['class'] = HTMLFancyCaptchaField::class;
|
||||
$form = new HTMLForm( [ 'captchaWord' => $params ], $context );
|
||||
$form->setTitle( Title::newFromText( 'Foo' ) );
|
||||
$form->prepareForm();
|
||||
return $form;
|
||||
|
|
|
@ -5,25 +5,26 @@
|
|||
*/
|
||||
class HTMLReCaptchaNoCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
||||
public function testSubmit() {
|
||||
$request = new FauxRequest( [
|
||||
'foo' => 'abc',
|
||||
'g-recaptcha-response' => 'def',
|
||||
], true );
|
||||
$context = new DerivativeContext( RequestContext::getMain() );
|
||||
$context->setRequest( $request );
|
||||
|
||||
$form = new HTMLForm( [
|
||||
'foo' => [
|
||||
'class' => HTMLReCaptchaNoCaptchaField::class,
|
||||
'key' => '123',
|
||||
],
|
||||
] );
|
||||
$request = new FauxRequest( [
|
||||
'foo' => 'abc',
|
||||
'g-recaptcha-response' => 'def',
|
||||
], true );
|
||||
], $context );
|
||||
|
||||
$mockClosure = $this->getMockBuilder( stdClass::class )
|
||||
->addMethods( [ '__invoke' ] )->getMock();
|
||||
$mockClosure->expects( $this->once() )->method( '__invoke' )
|
||||
->with( [ 'foo' => 'def' ] )->willReturn( true );
|
||||
|
||||
$context = new DerivativeContext( RequestContext::getMain() );
|
||||
$context->setRequest( $request );
|
||||
$form->setTitle( Title::newFromText( 'Title' ) );
|
||||
$form->setContext( $context );
|
||||
$form->setSubmitCallback( $mockClosure );
|
||||
$form->prepareForm();
|
||||
$form->trySubmit();
|
||||
|
|
Loading…
Reference in a new issue