MediaWiki  REL1_24
ApiMainTest.php
Go to the documentation of this file.
00001 <?php
00002 
00010 class ApiMainTest extends ApiTestCase {
00011 
00018     public function testApi() {
00019         $api = new ApiMain(
00020             new FauxRequest( array( 'action' => 'help', 'format' => 'xml' ) )
00021         );
00022         $api->execute();
00023         $api->getPrinter()->setBufferResult( true );
00024         $api->printResult( false );
00025         $resp = $api->getPrinter()->getBuffer();
00026 
00027         libxml_use_internal_errors( true );
00028         $sxe = simplexml_load_string( $resp );
00029         $this->assertNotInternalType( "bool", $sxe );
00030         $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
00031     }
00032 
00033     public static function provideAssert() {
00034         $anon = new User();
00035         $bot = new User();
00036         $bot->setName( 'Bot' );
00037         $bot->addToDatabase();
00038         $bot->addGroup( 'bot' );
00039         $user = new User();
00040         $user->setName( 'User' );
00041         $user->addToDatabase();
00042         return array(
00043             array( $anon, 'user', 'assertuserfailed' ),
00044             array( $user, 'user', false ),
00045             array( $user, 'bot', 'assertbotfailed' ),
00046             array( $bot, 'user', false ),
00047             array( $bot, 'bot', false ),
00048         );
00049     }
00050 
00060     public function testAssert( $user, $assert, $error ) {
00061         try {
00062             $this->doApiRequest( array(
00063                 'action' => 'query',
00064                 'assert' => $assert,
00065             ), null, null, $user );
00066             $this->assertFalse( $error ); // That no error was expected
00067         } catch ( UsageException $e ) {
00068             $this->assertEquals( $e->getCodeString(), $error );
00069         }
00070     }
00071 
00072 }