Merge "Add basic tests for QuestyCaptcha"

This commit is contained in:
jenkins-bot 2015-01-23 21:03:51 +00:00 committed by Gerrit Code Review
commit da1f50aff4
3 changed files with 76 additions and 0 deletions

View file

@ -200,6 +200,7 @@ $wgHooks['APIGetAllowedParams'][] = 'ConfirmEditHooks::APIGetAllowedParams';
$wgHooks['APIGetParamDescription'][] = 'ConfirmEditHooks::APIGetParamDescription';
$wgHooks['AddNewAccountApiForm'][] = 'ConfirmEditHooks::addNewAccountApiForm';
$wgHooks['AddNewAccountApiResult'][] = 'ConfirmEditHooks::addNewAccountApiResult';
$wgHooks['UnitTestsList'][] = 'ConfirmEditHooks::onUnitTestsList';
$wgAutoloadClasses['ConfirmEditHooks'] = "$wgConfirmEditIP/ConfirmEditHooks.php";
$wgAutoloadClasses['SimpleCaptcha'] = "$wgConfirmEditIP/Captcha.php";

View file

@ -80,6 +80,32 @@ class ConfirmEditHooks {
public static function APIGetParamDescription( &$module, &$desc ) {
return self::getInstance()->APIGetParamDescription( $module, $desc );
}
/**
* Hook to add PHPUnit test cases.
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
*
* @param array &$files
* @return boolean
*/
public static function onUnitTestsList( array &$files ) {
// @codeCoverageIgnoreStart
$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/' );
/**
* @var SplFileInfo $fileInfo
*/
$ourFiles = array();
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
$ourFiles[] = $fileInfo->getPathname();
}
}
$files = array_merge( $files, $ourFiles );
return true;
// @codeCoverageIgnoreEnd
}
}
class CaptchaSpecialPage extends UnlistedSpecialPage {

View file

@ -0,0 +1,49 @@
<?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'] = array();
}
$this->setMwGlobals( 'wgCaptchaQuestions', $config );
$this->mergeMwGlobalArrayValue(
'wgAutoloadClasses',
array( 'QuestyCaptcha' => __DIR__ . '/../QuestyCaptcha.class.php' )
);
$qc = new QuestyCaptcha();
$this->assertEquals( $expected, $qc->getCaptcha() );
}
public static function provideGetCaptcha() {
return array(
array(
array(
array(
'question' => 'FooBar',
'answer' => 'Answer!',
),
),
array(
'question' => 'FooBar',
'answer' => 'Answer!',
),
),
array(
array(
'FooBar' => 'Answer!',
),
array(
'question' => 'FooBar',
'answer' => 'Answer!',
),
)
);
}
}