Merge "Revert "Made LCStoreDB try to use a separate DB connection""
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiMainTest.php
index 4ed5aa9..780cf9e 100644 (file)
@@ -30,4 +30,43 @@ class ApiMainTest extends ApiTestCase {
                $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
        }
 
+       public static function provideAssert() {
+               $anon = new User();
+               $bot = new User();
+               $bot->setName( 'Bot' );
+               $bot->addToDatabase();
+               $bot->addGroup( 'bot' );
+               $user = new User();
+               $user->setName( 'User' );
+               $user->addToDatabase();
+               return array(
+                       array( $anon, 'user', 'assertuserfailed' ),
+                       array( $user, 'user', false ),
+                       array( $user, 'bot', 'assertbotfailed' ),
+                       array( $bot, 'user', false ),
+                       array( $bot, 'bot', false ),
+               );
+       }
+
+       /**
+        * Tests the assert={user|bot} functionality
+        *
+        * @covers ApiMain::checkAsserts
+        * @dataProvider provideAssert
+        * @param User $user
+        * @param string $assert
+        * @param string|bool $error False if no error expected
+        */
+       public function testAssert( $user, $assert, $error ) {
+               try {
+                       $this->doApiRequest( array(
+                               'action' => 'query',
+                               'assert' => $assert,
+                       ), null, null, $user );
+                       $this->assertFalse( $error ); // That no error was expected
+               } catch ( UsageException $e ) {
+                       $this->assertEquals( $e->getCodeString(), $error );
+               }
+       }
+
 }