Merge "Unsetting the email address for a user when the email address is invalidated."
[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. The help action
14 * (default) throws a UsageException. Just validate we're getting proper XML
15 *
16 * @expectedException UsageException
17 */
18 public function testApi() {
19 $api = new ApiMain(
20 new FauxRequest( array( 'action' => 'help', 'format' => 'xml' ) )
21 );
22 $api->execute();
23 $api->getPrinter()->setBufferResult( true );
24 $api->printResult( false );
25 $resp = $api->getPrinter()->getBuffer();
26
27 libxml_use_internal_errors( true );
28 $sxe = simplexml_load_string( $resp );
29 $this->assertNotInternalType( "bool", $sxe );
30 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
31 }
32
33 public static function provideAssert() {
34 $anon = new User();
35 $bot = new User();
36 $bot->setName( 'Bot' );
37 $bot->addToDatabase();
38 $bot->addGroup( 'bot' );
39 $user = new User();
40 $user->setName( 'User' );
41 $user->addToDatabase();
42 return array(
43 array( $anon, 'user', 'assertuserfailed' ),
44 array( $user, 'user', false ),
45 array( $user, 'bot', 'assertbotfailed' ),
46 array( $bot, 'user', false ),
47 array( $bot, 'bot', false ),
48 );
49 }
50
51 /**
52 * Tests the assert={user|bot} functionality
53 *
54 * @covers ApiMain::checkAsserts
55 * @dataProvider provideAssert
56 * @param User $user
57 * @param string $assert
58 * @param string|bool $error false if no error expected
59 */
60 public function testAssert( $user, $assert, $error ) {
61 try {
62 $this->doApiRequest( array(
63 'action' => 'query',
64 'assert' => $assert,
65 ), null, null, $user );
66 $this->assertFalse( $error ); // That no error was expected
67 } catch ( UsageException $e ) {
68 $this->assertEquals( $e->getCodeString(), $error );
69 }
70 }
71
72 }