mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-12 09:32:55 +00:00
Merge "Add basic tests for QuestyCaptcha"
This commit is contained in:
commit
da1f50aff4
|
@ -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";
|
||||
|
|
|
@ -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 {
|
||||
|
|
49
tests/QuestyCaptchaTest.php
Normal file
49
tests/QuestyCaptchaTest.php
Normal 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!',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue