mediawiki-extensions-Confir.../tests/phpunit/HTMLReCaptchaNoCaptchaFieldTest.php
Reedy a801949300 Remove class_alias calls and cleanup Autoloads
Existed since 1.39 in I3fa9747e0ea970c5de39e2da8603e1bba9388a69

Change-Id: I17a648aaf7644d00cd82966a88dab8f33d2e317f
2024-10-30 01:48:14 +00:00

41 lines
1.2 KiB
PHP

<?php
use MediaWiki\Context\DerivativeContext;
use MediaWiki\Context\RequestContext;
use MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField;
use MediaWiki\HTMLForm\HTMLForm;
use MediaWiki\Request\FauxRequest;
use MediaWiki\Title\Title;
/**
* @covers \MediaWiki\Extension\ConfirmEdit\ReCaptchaNoCaptcha\HTMLReCaptchaNoCaptchaField
*/
class HTMLReCaptchaNoCaptchaFieldTest extends MediaWikiIntegrationTestCase {
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',
],
], $context );
$mockClosure = $this->getMockBuilder( stdClass::class )
->addMethods( [ '__invoke' ] )->getMock();
$mockClosure->expects( $this->once() )->method( '__invoke' )
->with( [ 'foo' => 'def' ] )->willReturn( true );
$form->setTitle( Title::newFromText( 'Title' ) );
$form->setSubmitCallback( $mockClosure );
$form->prepareForm();
$form->trySubmit();
}
}