2016-05-03 16:42:00 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-23 23:59:08 +00:00
|
|
|
/**
|
|
|
|
* @covers HTMLReCaptchaNoCaptchaField
|
|
|
|
*/
|
2018-02-15 09:34:50 +00:00
|
|
|
class HTMLReCaptchaNoCaptchaFieldTest extends PHPUnit\Framework\TestCase {
|
2016-05-03 16:42:00 +00:00
|
|
|
public function testSubmit() {
|
|
|
|
$form = new HTMLForm( [
|
|
|
|
'foo' => [
|
|
|
|
'class' => HTMLReCaptchaNoCaptchaField::class,
|
|
|
|
'key' => '123',
|
|
|
|
],
|
|
|
|
] );
|
|
|
|
$request = new FauxRequest( [
|
|
|
|
'foo' => 'abc',
|
|
|
|
'g-recaptcha-response' => 'def',
|
|
|
|
], true );
|
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 );
|
|
|
|
|
|
|
|
$context = new DerivativeContext( RequestContext::getMain() );
|
|
|
|
$context->setRequest( $request );
|
|
|
|
$form->setTitle( Title::newFromText( 'Title' ) );
|
|
|
|
$form->setContext( $context );
|
|
|
|
$form->setSubmitCallback( $mockClosure );
|
|
|
|
$form->prepareForm();
|
|
|
|
$form->trySubmit();
|
|
|
|
}
|
|
|
|
}
|