This found wrong class names for api modules Change-Id: If1125cd5fa4ed836fe15fc79480d78ebd899be4e
82 lines
2 KiB
PHP
82 lines
2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group API
|
|
* @group Database
|
|
* @group medium
|
|
*
|
|
* @covers ApiMain
|
|
*/
|
|
class ApiMainTest extends ApiTestCase {
|
|
|
|
/**
|
|
* Test that the API will accept a FauxRequest and execute.
|
|
*/
|
|
public function testApi() {
|
|
$api = new ApiMain(
|
|
new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
|
|
);
|
|
$api->execute();
|
|
$data = $api->getResultData();
|
|
$this->assertInternalType( 'array', $data );
|
|
$this->assertArrayHasKey( 'query', $data );
|
|
}
|
|
|
|
public static function provideAssert() {
|
|
$anon = new User();
|
|
$bot = new User();
|
|
$bot->setName( 'Bot' );
|
|
$bot->addToDatabase();
|
|
$bot->addGroup( 'bot' );
|
|
$user = new User();
|
|
$user->setName( 'User' );
|
|
$user->addToDatabase();
|
|
return array(
|
|
array( $anon, 'user', 'assertuserfailed' ),
|
|
array( $user, 'user', false ),
|
|
array( $user, 'bot', 'assertbotfailed' ),
|
|
array( $bot, 'user', false ),
|
|
array( $bot, 'bot', false ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Tests the assert={user|bot} functionality
|
|
*
|
|
* @covers ApiMain::checkAsserts
|
|
* @dataProvider provideAssert
|
|
* @param User $user
|
|
* @param string $assert
|
|
* @param string|bool $error False if no error expected
|
|
*/
|
|
public function testAssert( $user, $assert, $error ) {
|
|
try {
|
|
$this->doApiRequest( array(
|
|
'action' => 'query',
|
|
'assert' => $assert,
|
|
), null, null, $user );
|
|
$this->assertFalse( $error ); // That no error was expected
|
|
} catch ( UsageException $e ) {
|
|
$this->assertEquals( $e->getCodeString(), $error );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test if all classes in the main module manager exists
|
|
*/
|
|
public function testClassNamesInModuleManager() {
|
|
global $wgAutoloadLocalClasses;
|
|
|
|
$api = new ApiMain(
|
|
new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
|
|
);
|
|
$modules = $api->getModuleManager()->getNamesWithClasses();
|
|
foreach( $modules as $name => $class ) {
|
|
$this->assertArrayHasKey(
|
|
$class,
|
|
$wgAutoloadLocalClasses,
|
|
'Class ' . $class . ' for api module ' . $name . ' not in autoloader (with exact case)'
|
|
);
|
|
}
|
|
}
|
|
}
|