Merge "Update MessagesEn.php::$preloadedMessages"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiMainTest.php
1 <?php
2
3 /**
4 * @group API
5 * @group Database
6 * @group medium
7 *
8 * @covers ApiMain
9 */
10 class ApiMainTest extends ApiTestCase {
11
12 /**
13 * Test that the API will accept a FauxRequest and execute.
14 */
15 public function testApi() {
16 $api = new ApiMain(
17 new FauxRequest( array( 'action' => 'query', 'meta' => 'siteinfo' ) )
18 );
19 $api->execute();
20 $data = $api->getResultData();
21 $this->assertInternalType( 'array', $data );
22 $this->assertArrayHasKey( 'query', $data );
23 }
24
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 ),
40 );
41 }
42
43 /**
44 * Tests the assert={user|bot} functionality
45 *
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
51 */
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 );
61 }
62 }
63
64 }