2016-04-25 20:58:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Auth\AuthenticationRequestTestCase;
|
2022-04-08 16:40:15 +00:00
|
|
|
use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
|
|
|
|
use MediaWiki\Extension\ConfirmEdit\SimpleCaptcha\SimpleCaptcha;
|
|
|
|
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaHashStore;
|
|
|
|
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
|
2016-04-25 20:58:18 +00:00
|
|
|
|
2018-01-23 23:59:08 +00:00
|
|
|
/**
|
2022-04-08 16:40:15 +00:00
|
|
|
* @covers \MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest
|
2018-01-23 23:59:08 +00:00
|
|
|
*/
|
2016-04-25 20:58:18 +00:00
|
|
|
class CaptchaAuthenticationRequestTest extends AuthenticationRequestTestCase {
|
2021-07-22 06:38:52 +00:00
|
|
|
public function setUp(): void {
|
2016-04-25 20:58:18 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->setMwGlobals( [
|
2019-03-02 18:39:36 +00:00
|
|
|
'wgCaptchaClass' => SimpleCaptcha::class,
|
2016-04-25 20:58:18 +00:00
|
|
|
'wgCaptchaStorageClass' => CaptchaHashStore::class,
|
|
|
|
] );
|
2016-07-28 13:51:51 +00:00
|
|
|
CaptchaStore::unsetInstanceForTests();
|
2016-04-25 20:58:18 +00:00
|
|
|
CaptchaStore::get()->clearAll();
|
|
|
|
CaptchaStore::get()->store( '345', [ 'question' => '2+2', 'answer' => '4' ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getInstance( array $args = [] ) {
|
|
|
|
return new CaptchaAuthenticationRequest( $args[0], $args[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideGetFieldInfo() {
|
|
|
|
return [
|
|
|
|
[ [ '123', [ 'question' => '1+2', 'answer' => '3' ] ] ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-05-19 20:26:53 +00:00
|
|
|
public static function provideLoadFromSubmission() {
|
2016-04-25 20:58:18 +00:00
|
|
|
return [
|
|
|
|
'no id' => [
|
|
|
|
[ '123', [ 'question' => '1+2', 'answer' => '3' ] ],
|
|
|
|
[],
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
'no answer' => [
|
|
|
|
[ '123', [ 'question' => '1+2', 'answer' => '3' ] ],
|
|
|
|
[ 'captchaId' => '345' ],
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
'missing' => [
|
|
|
|
[ '123', [ 'question' => '1+2', 'answer' => '3' ] ],
|
|
|
|
[ 'captchaId' => '234', 'captchaWord' => '5' ],
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
'normal' => [
|
|
|
|
[ '123', [ 'question' => '1+2', 'answer' => '3' ] ],
|
|
|
|
[ 'captchaId' => '345', 'captchaWord' => '5' ],
|
|
|
|
[ 'captchaId' => '345', 'captchaData' => [ 'question' => '2+2', 'answer' => '4' ],
|
|
|
|
'captchaWord' => '5' ],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|