Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / api / ApiMainTest.php
blobe91edcb7dbed5e24a65ee803a55c49a1eabe3ca0
1 <?php
3 /**
4 * @group API
5 * @group Database
6 * @group medium
8 * @covers ApiMain
9 */
10 class ApiMainTest extends ApiTestCase {
12 /**
13 * Test that the API will accept a FauxRequest and execute.
15 public function testApi() {
16 $api = new ApiMain(
17 new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
19 $api->execute();
20 $data = $api->getResultData();
21 $this->assertInternalType( 'array', $data );
22 $this->assertArrayHasKey( 'query', $data );
25 public static function provideAssert() {
26 $anon = new User();
27 $bot = new User();
28 $bot->setName( 'Bot' );
29 $bot->addToDatabase();
30 $bot->addGroup( 'bot' );
31 $user = new User();
32 $user->setName( 'User' );
33 $user->addToDatabase();
34 return array(
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 ),
43 /**
44 * Tests the assert={user|bot} functionality
46 * @covers ApiMain::checkAsserts
47 * @dataProvider provideAssert
48 * @param User $user
49 * @param string $assert
50 * @param string|bool $error False if no error expected
52 public function testAssert( $user, $assert, $error ) {
53 try {
54 $this->doApiRequest( array(
55 'action' => 'query',
56 'assert' => $assert,
57 ), null, null, $user );
58 $this->assertFalse( $error ); // That no error was expected
59 } catch ( UsageException $e ) {
60 $this->assertEquals( $e->getCodeString(), $error );
64 /**
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;
73 $api = new ApiMain(
74 new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
76 $modules = $api->getModuleManager()->getNamesWithClasses();
77 foreach( $modules as $name => $class ) {
78 $this->assertArrayHasKey(
79 $class,
80 $classes,
81 'Class ' . $class . ' for api module ' . $name . ' not in autoloader (with exact case)'