10 class ApiMainTest
extends ApiTestCase
{
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
16 * @expectedException UsageException
18 public function testApi() {
20 new FauxRequest( array( 'action' => 'help', 'format' => 'xml' ) )
23 $api->getPrinter()->setBufferResult( true );
24 $api->printResult( false );
25 $resp = $api->getPrinter()->getBuffer();
27 libxml_use_internal_errors( true );
28 $sxe = simplexml_load_string( $resp );
29 $this->assertNotInternalType( "bool", $sxe );
30 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
33 public static function provideAssert() {
36 $bot->setName( 'Bot' );
37 $bot->addToDatabase();
38 $bot->addGroup( 'bot' );
40 $user->setName( 'User' );
41 $user->addToDatabase();
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 ),
52 * Tests the assert={user|bot} functionality
54 * @covers ApiMain::checkAsserts
55 * @dataProvider provideAssert
57 * @param string $assert
58 * @param string|bool $error False if no error expected
60 public function testAssert( $user, $assert, $error ) {
62 $this->doApiRequest( array(
65 ), null, null, $user );
66 $this->assertFalse( $error ); // That no error was expected
67 } catch ( UsageException
$e ) {
68 $this->assertEquals( $e->getCodeString(), $error );