]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - extensions/ConfirmEdit/tests/phpunit/QuestyCaptchaTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / extensions / ConfirmEdit / tests / phpunit / QuestyCaptchaTest.php
diff --git a/extensions/ConfirmEdit/tests/phpunit/QuestyCaptchaTest.php b/extensions/ConfirmEdit/tests/phpunit/QuestyCaptchaTest.php
new file mode 100644 (file)
index 0000000..dada668
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+class QuestyCaptchaTest extends MediaWikiTestCase {
+       /**
+        * @covers QuestyCaptcha::getCaptcha
+        * @dataProvider provideGetCaptcha
+        */
+       public function testGetCaptcha( $config, $expected ) {
+               # setMwGlobals() requires $wgCaptchaQuestion to be set
+               if ( !isset( $GLOBALS['wgCaptchaQuestions'] ) ) {
+                       $GLOBALS['wgCaptchaQuestions'] = [];
+               }
+               $this->setMwGlobals( 'wgCaptchaQuestions', $config );
+               $this->mergeMwGlobalArrayValue(
+                       'wgAutoloadClasses',
+                       [ 'QuestyCaptcha' => __DIR__ . '/../../QuestyCaptcha/QuestyCaptcha.class.php' ]
+               );
+
+               $qc = new QuestyCaptcha();
+               $this->assertEquals( $expected, $qc->getCaptcha() );
+       }
+
+       public static function provideGetCaptcha() {
+               return [
+                       [
+                               [
+                                       [
+                                               'question' => 'FooBar',
+                                               'answer' => 'Answer!',
+                                       ],
+                               ],
+                               [
+                                       'question' => 'FooBar',
+                                       'answer' => 'Answer!',
+                               ],
+                       ],
+                       [
+                               [
+                                       'FooBar' => 'Answer!',
+                               ],
+                               [
+                                       'question' => 'FooBar',
+                                       'answer' => 'Answer!',
+                               ],
+                       ]
+               ];
+       }
+}