mediawiki-extensions-Confir.../tests/phpunit/QuestyCaptchaTest.php
Umherirrender 79b09f4995 Register QuestyCaptcha class ealier in unit tests
The captchas in production are registered conditional, in tests the
class needs to be added to the autoloader.
Moved this register up to setUp to detect the existing @covers correctly
by the new testValidCovers from
I1d564bcae2bfbedb004c440b90db6341148ed4ba

Change-Id: I79f225126d7bbbfd436ab165bb98a0ed9517b8bc
2017-12-27 21:59:34 +01:00

55 lines
1 KiB
PHP

<?php
class QuestyCaptchaTest extends MediaWikiTestCase {
public function setUp() {
parent::setUp();
$this->mergeMwGlobalArrayValue(
'wgAutoloadClasses',
[ 'QuestyCaptcha' => __DIR__ . '/../../QuestyCaptcha/QuestyCaptcha.class.php' ]
);
}
/**
* @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 );
$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!',
],
]
];
}
}