2016-05-03 16:42:00 +00:00
|
|
|
<?php
|
|
|
|
|
2024-06-08 21:46:45 +00:00
|
|
|
use MediaWiki\Context\DerivativeContext;
|
|
|
|
use MediaWiki\Context\RequestContext;
|
2022-04-08 16:53:12 +00:00
|
|
|
use MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField;
|
2024-06-08 21:46:45 +00:00
|
|
|
use MediaWiki\HTMLForm\HTMLForm;
|
2023-05-19 10:23:59 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2023-08-19 04:14:21 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-04-08 16:53:12 +00:00
|
|
|
|
2018-01-23 23:59:08 +00:00
|
|
|
/**
|
2022-04-08 16:53:12 +00:00
|
|
|
* @covers \MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField
|
2018-01-23 23:59:08 +00:00
|
|
|
*/
|
2022-04-08 16:53:12 +00:00
|
|
|
class HTMLReCaptchaNoCaptchaFieldTest extends MediaWikiIntegrationTestCase {
|
2024-01-17 04:46:58 +00:00
|
|
|
|
|
|
|
public function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->mergeMwGlobalArrayValue(
|
|
|
|
'wgAutoloadClasses',
|
|
|
|
[
|
|
|
|
'MediaWiki\\Extension\\ConfirmEdit\\ReCaptchaNoCaptcha\\HTMLReCaptchaNoCaptchaField'
|
|
|
|
=> __DIR__ . '/../../ReCaptchaNoCaptcha/includes/HTMLReCaptchaNoCaptchaField.php'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-03 16:42:00 +00:00
|
|
|
public function testSubmit() {
|
2022-05-15 21:35:03 +00:00
|
|
|
$request = new FauxRequest( [
|
|
|
|
'foo' => 'abc',
|
|
|
|
'g-recaptcha-response' => 'def',
|
|
|
|
], true );
|
|
|
|
$context = new DerivativeContext( RequestContext::getMain() );
|
|
|
|
$context->setRequest( $request );
|
|
|
|
|
2016-05-03 16:42:00 +00:00
|
|
|
$form = new HTMLForm( [
|
|
|
|
'foo' => [
|
|
|
|
'class' => HTMLReCaptchaNoCaptchaField::class,
|
|
|
|
'key' => '123',
|
|
|
|
],
|
2022-05-15 21:35:03 +00:00
|
|
|
], $context );
|
|
|
|
|
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-05-03 16:42:00 +00:00
|
|
|
$mockClosure->expects( $this->once() )->method( '__invoke' )
|
|
|
|
->with( [ 'foo' => 'def' ] )->willReturn( true );
|
|
|
|
|
|
|
|
$form->setTitle( Title::newFromText( 'Title' ) );
|
|
|
|
$form->setSubmitCallback( $mockClosure );
|
|
|
|
$form->prepareForm();
|
|
|
|
$form->trySubmit();
|
|
|
|
}
|
|
|
|
}
|