| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Context\DerivativeContext; |
| 4 |
use MediaWiki\Context\RequestContext; |
| 5 |
use MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField; |
| 6 |
use MediaWiki\HTMLForm\HTMLForm; |
| 7 |
use MediaWiki\Request\FauxRequest; |
| 8 |
use MediaWiki\Title\Title; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class HTMLReCaptchaNoCaptchaFieldTest extends MediaWikiIntegrationTestCase { |
| 14 |
|
| 15 |
public function setUp(): void { |
| 16 |
parent::setUp(); |
| 17 |
|
| 18 |
$this->mergeMwGlobalArrayValue( |
| 19 |
'wgAutoloadClasses', |
| 20 |
[ |
| 21 |
'MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\HTMLReCaptchaNoCaptchaField' |
| 22 |
=> __DIR__ . '/../../ReCaptchaNoCaptcha/includes/HTMLReCaptchaNoCaptchaField.php' |
| 23 |
] |
| 24 |
); |
| 25 |
} |
| 26 |
|
| 27 |
public function testSubmit() { |
| 28 |
$request = new FauxRequest( [ |
| 29 |
'foo' => 'abc', |
| 30 |
'g-recaptcha-response' => 'def', |
| 31 |
], true ); |
| 32 |
$context = new DerivativeContext( RequestContext::getMain() ); |
| 33 |
$context->setRequest( $request ); |
| 34 |
|
| 35 |
$form = new HTMLForm( [ |
| 36 |
'foo' => [ |
| 37 |
'class' => HTMLReCaptchaNoCaptchaField::class, |
| 38 |
'key' => '123', |
| 39 |
], |
| 40 |
], $context ); |
| 41 |
|
| 42 |
$mockClosure = $this->getMockBuilder( stdClass::class ) |
| 43 |
->addMethods( [ '__invoke' ] )->getMock(); |
| 44 |
$mockClosure->expects( $this->once() )->method( '__invoke' ) |
| 45 |
->with( [ 'foo' => 'def' ] )->willReturn( true ); |
| 46 |
|
| 47 |
$form->setTitle( Title::newFromText( 'Title' ) ); |
| 48 |
$form->setSubmitCallback( $mockClosure ); |
| 49 |
$form->prepareForm(); |
| 50 |
$form->trySubmit(); |
| 51 |
} |
| 52 |
} |