mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-12-02 11:46:43 +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 ) {
|
protected function getForm( $params = [], WebRequest $request = null ) {
|
||||||
$params['class'] = HTMLFancyCaptchaField::class;
|
|
||||||
$form = new HTMLForm( [ 'captchaWord' => $params ] );
|
|
||||||
if ( $request ) {
|
if ( $request ) {
|
||||||
$context = new DerivativeContext( RequestContext::getMain() );
|
$context = new DerivativeContext( RequestContext::getMain() );
|
||||||
$context->setRequest( $request );
|
$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->setTitle( Title::newFromText( 'Foo' ) );
|
||||||
$form->prepareForm();
|
$form->prepareForm();
|
||||||
return $form;
|
return $form;
|
||||||
|
|
|
@ -5,25 +5,26 @@
|
||||||
*/
|
*/
|
||||||
class HTMLReCaptchaNoCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
class HTMLReCaptchaNoCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
||||||
public function testSubmit() {
|
public function testSubmit() {
|
||||||
|
$request = new FauxRequest( [
|
||||||
|
'foo' => 'abc',
|
||||||
|
'g-recaptcha-response' => 'def',
|
||||||
|
], true );
|
||||||
|
$context = new DerivativeContext( RequestContext::getMain() );
|
||||||
|
$context->setRequest( $request );
|
||||||
|
|
||||||
$form = new HTMLForm( [
|
$form = new HTMLForm( [
|
||||||
'foo' => [
|
'foo' => [
|
||||||
'class' => HTMLReCaptchaNoCaptchaField::class,
|
'class' => HTMLReCaptchaNoCaptchaField::class,
|
||||||
'key' => '123',
|
'key' => '123',
|
||||||
],
|
],
|
||||||
] );
|
], $context );
|
||||||
$request = new FauxRequest( [
|
|
||||||
'foo' => 'abc',
|
|
||||||
'g-recaptcha-response' => 'def',
|
|
||||||
], true );
|
|
||||||
$mockClosure = $this->getMockBuilder( stdClass::class )
|
$mockClosure = $this->getMockBuilder( stdClass::class )
|
||||||
->addMethods( [ '__invoke' ] )->getMock();
|
->addMethods( [ '__invoke' ] )->getMock();
|
||||||
$mockClosure->expects( $this->once() )->method( '__invoke' )
|
$mockClosure->expects( $this->once() )->method( '__invoke' )
|
||||||
->with( [ 'foo' => 'def' ] )->willReturn( true );
|
->with( [ 'foo' => 'def' ] )->willReturn( true );
|
||||||
|
|
||||||
$context = new DerivativeContext( RequestContext::getMain() );
|
|
||||||
$context->setRequest( $request );
|
|
||||||
$form->setTitle( Title::newFromText( 'Title' ) );
|
$form->setTitle( Title::newFromText( 'Title' ) );
|
||||||
$form->setContext( $context );
|
|
||||||
$form->setSubmitCallback( $mockClosure );
|
$form->setSubmitCallback( $mockClosure );
|
||||||
$form->prepareForm();
|
$form->prepareForm();
|
||||||
$form->trySubmit();
|
$form->trySubmit();
|
||||||
|
|
Loading…
Reference in a new issue