3 use Wikimedia\ScopedCallback;
4 use Wikimedia\TestingAccessWrapper;
25 $this->setMwGlobals( [
26 'wgCaptchaTriggers' => [
27 $action => $expectedResult,
30 $this->assertEquals( $expectedResult, $captcha->triggersCaptcha( $action ) );
35 $captchaTriggers =
new ReflectionClass( CaptchaTriggers::class );
36 $constants = $captchaTriggers->getConstants();
37 foreach ( $constants as $const ) {
38 $data[] = [ $const,
true ];
39 $data[] = [ $const, false ];
49 $this->setMwGlobals( [
50 'wgCaptchaTriggers' => [
51 $trigger => !$expected,
53 'wgCaptchaTriggersOnNamespace' => [
55 $trigger => $expected,
60 $this->assertEquals( $expected, $captcha->triggersCaptcha( $trigger,
$title ) );
76 TestingAccessWrapper::newFromClass( ExtensionProcessor::class )->globalSettings;
78 foreach (
$keys as $key ) {
79 $globalsToStash[
"wg$key"] =
$GLOBALS[
"wg$key"];
81 $this->setMwGlobals( $globalsToStash );
89 'CaptchaTriggers' => [
93 'autoloaderPaths' => []
96 'CaptchaTriggers', [ $trigger => $value ]
106 $this->assertEquals( $value, $captcha->triggersCaptcha( $trigger ) );
120 $this->setMwGlobals( [
121 'wgCaptchaTriggers' => [
122 $trigger => $expected
127 $this->assertEquals( $expected, $captcha->triggersCaptcha( $trigger ) );
142 $user = $this->getMock( User::class );
143 $user->method(
'isAllowed' )->willReturn( $userIsAllowed );
147 $this->assertEquals( $expected, $actual );
165 $userIsMailConfirmed, $expected ) {
167 $user = $this->getMock( User::class );
168 $user->method(
'isEmailConfirmed' )->willReturn( $userIsMailConfirmed );
169 $config = $this->getMock( Config::class );
170 $config->method(
'get' )->willReturn( $allowUserConfirmEmail );
172 $actual = $testObject->canSkipCaptcha( $user, $config );
174 $this->assertEquals( $expected, $actual );
179 [
false,
false, false ],
180 [
false,
true, false ],
181 [
true,
false, false ],
182 [
true,
true,
true ],
195 $config = $this->getMock( Config::class );
196 $request = $this->getMock( WebRequest::class );
197 $request->method(
'getIP' )->willReturn( $requestIP );
199 $this->setMwGlobals( [
200 'wgRequest' => $request,
201 'wgCaptchaWhitelistIP' => $IPWhitelist
206 $this->assertEquals( $expected, $actual );
211 [
'127.0.0.1', [
'127.0.0.1',
'127.0.0.2' ],
true ],
212 [
'127.0.0.1', [],
false ]