10 class ApiMainTest
extends ApiTestCase
{
13 * Test that the API will accept a FauxRequest and execute.
15 public function testApi() {
17 new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
20 $data = $api->getResultData();
21 $this->assertInternalType( 'array', $data );
22 $this->assertArrayHasKey( 'query', $data );
25 public static function provideAssert() {
28 $bot->setName( 'Bot' );
29 $bot->addToDatabase();
30 $bot->addGroup( 'bot' );
32 $user->setName( 'User' );
33 $user->addToDatabase();
35 array( $anon, 'user', 'assertuserfailed' ),
36 array( $user, 'user', false ),
37 array( $user, 'bot', 'assertbotfailed' ),
38 array( $bot, 'user', false ),
39 array( $bot, 'bot', false ),
44 * Tests the assert={user|bot} functionality
46 * @covers ApiMain::checkAsserts
47 * @dataProvider provideAssert
49 * @param string $assert
50 * @param string|bool $error False if no error expected
52 public function testAssert( $user, $assert, $error ) {
54 $this->doApiRequest( array(
57 ), null, null, $user );
58 $this->assertFalse( $error ); // That no error was expected
59 } catch ( UsageException
$e ) {
60 $this->assertEquals( $e->getCodeString(), $error );
65 * Test if all classes in the main module manager exists
67 public function testClassNamesInModuleManager() {
68 global $wgAutoloadLocalClasses, $wgAutoloadClasses;
70 // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
71 $classes = $wgAutoloadLocalClasses +
$wgAutoloadClasses;
74 new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
76 $modules = $api->getModuleManager()->getNamesWithClasses();
77 foreach( $modules as $name => $class ) {
78 $this->assertArrayHasKey(
81 'Class ' . $class . ' for api module ' . $name . ' not in autoloader (with exact case)'