Followup r100905, disabling testGetRollbackToken because it reports as failed on...
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiWatchTest.php
index 0742a0a..b780374 100644 (file)
@@ -1,99 +1,34 @@
 <?php
 
-require_once dirname( __FILE__ ) . '/ApiSetup.php';
-
 /**
  * @group Database
- * @group Destructive
+ * @todo This test suite is severly broken and need a full review 
  */
-class ApiWatchTest extends ApiTestSetup {
+class ApiWatchTest extends ApiTestCase {
 
        function setUp() {
                parent::setUp();
+               $this->doLogin();
        }
-
-       function testLogin() {
-               $data = $this->doApiRequest( array(
-                       'action' => 'login',
-                       'lgname' => self::$sysopUser->userName,
-                       'lgpassword' => self::$sysopUser->password ) );
-
-               $this->assertArrayHasKey( "login", $data[0] );
-               $this->assertArrayHasKey( "result", $data[0]['login'] );
-               $this->assertEquals( "NeedToken", $data[0]['login']['result'] );
-               $token = $data[0]['login']['token'];
-
-               $data = $this->doApiRequest( array(
-                       'action' => 'login',
-                       "lgtoken" => $token,
-                       "lgname" => self::$sysopUser->userName,
-                       "lgpassword" => self::$sysopUser->password ), $data );
-
-               $this->assertArrayHasKey( "login", $data[0] );
-               $this->assertArrayHasKey( "result", $data[0]['login'] );
-               $this->assertEquals( "Success", $data[0]['login']['result'] );
-               $this->assertArrayHasKey( 'lgtoken', $data[0]['login'] );
-
-               return $data;
-       }
-
-       function testGettingToken() {
-               foreach ( array( self::$user, self::$sysopUser ) as $user ) {
-                       $this->getUserTokens( $user );
-               }
-       }
-
-       function getUserTokens( $user ) {
-               $GLOBALS['wgUser'] = $user->user;
-               $data = $this->doApiRequest( array(
-                       'action' => 'query',
-                       'titles' => 'Main Page',
-                       'intoken' => 'edit|delete|protect|move|block|unblock',
-                       'prop' => 'info' ) );
-
-               $this->assertArrayHasKey( 'query', $data[0] );
-               $this->assertArrayHasKey( 'pages', $data[0]['query'] );
-               $keys = array_keys( $data[0]['query']['pages'] );
-               $key = array_pop( $keys );
-
-               $rights = $user->user->getRights();
-
-               $this->assertArrayHasKey( $key, $data[0]['query']['pages'] );
-               $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] );
-               $this->assertArrayHasKey( 'movetoken', $data[0]['query']['pages'][$key] );
-
-               if ( isset( $rights['delete'] ) ) {
-                       $this->assertArrayHasKey( 'deletetoken', $data[0]['query']['pages'][$key] );
-               }
-
-               if ( isset( $rights['block'] ) ) {
-                       $this->assertArrayHasKey( 'blocktoken', $data[0]['query']['pages'][$key] );
-                       $this->assertArrayHasKey( 'unblocktoken', $data[0]['query']['pages'][$key] );
-               }
-
-               if ( isset( $rights['protect'] ) ) {
-                       $this->assertArrayHasKey( 'protecttoken', $data[0]['query']['pages'][$key] );
-               }
-
-               return $data;
-       }
-
-       function testGetToken() {
-               return $this->getUserTokens( self::$sysopUser );
+       
+       function getTokens() {
+               return $this->getTokenList( self::$users['sysop'] );
        }
 
        /**
-        * @depends testGetToken
+        * @group Broken
         */
-       function testWatchEdit( $data ) {
-               $this->markTestIncomplete( "Broken" );
+       function testWatchEdit() {
+               
+               $data = $this->getTokens();
+               
                $keys = array_keys( $data[0]['query']['pages'] );
                $key = array_pop( $keys );
                $pageinfo = $data[0]['query']['pages'][$key];
 
                $data = $this->doApiRequest( array(
                        'action' => 'edit',
-                       'title' => 'Main Page',
+                       'title' => 'UTPage',
                        'text' => 'new text',
                        'token' => $pageinfo['edittoken'],
                        'watchlist' => 'watch' ), $data );
@@ -106,8 +41,10 @@ class ApiWatchTest extends ApiTestSetup {
 
        /**
         * @depends testWatchEdit
+        * @group Broken
         */
-       function testWatchClear( $data ) {
+       function testWatchClear() {
+       
                $data = $this->doApiRequest( array(
                        'action' => 'query',
                        'list' => 'watchlist' ), $data );
@@ -133,10 +70,12 @@ class ApiWatchTest extends ApiTestSetup {
        }
 
        /**
-        * @depends testGetToken
-        */
-       function testWatchProtect( $data ) {
-               $this->markTestIncomplete( "Broken" );
+        * @group Broken
+        */      
+       function testWatchProtect() {
+               
+               $data = $this->getTokens();
+               
                $keys = array_keys( $data[0]['query']['pages'] );
                $key = array_pop( $keys );
                $pageinfo = $data[0]['query']['pages'][$key];
@@ -144,7 +83,7 @@ class ApiWatchTest extends ApiTestSetup {
                $data = $this->doApiRequest( array(
                        'action' => 'protect',
                        'token' => $pageinfo['protecttoken'],
-                       'title' => 'Main Page',
+                       'title' => 'UTPage',
                        'protections' => 'edit=sysop',
                        'watchlist' => 'unwatch' ), $data );
 
@@ -155,17 +94,20 @@ class ApiWatchTest extends ApiTestSetup {
        }
 
        /**
-        * @depends testGetToken
+        * @group Broken
         */
-       function testGetRollbackToken( $data ) {
-               if ( !Title::newFromText( 'Main Page' )->exists() ) {
-                       $this->markTestIncomplete( "The article [[Main Page]] does not exist" );
+       function testGetRollbackToken() {
+               
+               $data = $this->getTokens();
+               
+               if ( !Title::newFromText( 'UTPage' )->exists() ) {
+                       $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
                }
 
                $data = $this->doApiRequest( array(
                        'action' => 'query',
                        'prop' => 'revisions',
-                       'titles' => 'Main Page',
+                       'titles' => 'UTPage',
                        'rvtoken' => 'rollback' ), $data );
 
                $this->assertArrayHasKey( 'query', $data[0] );
@@ -174,7 +116,7 @@ class ApiWatchTest extends ApiTestSetup {
                $key = array_pop( $keys );
 
                if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
-                       $this->markTestIncomplete( "Target page (Main Page) doesn't exist" );
+                       $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
                }
 
                $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
@@ -187,6 +129,7 @@ class ApiWatchTest extends ApiTestSetup {
 
        /**
         * @depends testGetRollbackToken
+        * @group Broken
         */
        function testWatchRollback( $data ) {
                $keys = array_keys( $data[0]['query']['pages'] );
@@ -196,15 +139,15 @@ class ApiWatchTest extends ApiTestSetup {
                try {
                        $data = $this->doApiRequest( array(
                                'action' => 'rollback',
-                               'title' => 'Main Page',
+                               'title' => 'UTPage',
                                'user' => $pageinfo['user'],
                                'token' => $pageinfo['rollbacktoken'],
                                'watchlist' => 'watch' ), $data );
                } catch( UsageException $ue ) {
                        if( $ue->getCodeString() == 'onlyauthor' ) {
-                               $this->markTestIncomplete( "Only one author to 'Main Page', cannot test rollback" );
+                               $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
                        } else {
-                               $this->fail( "Received error " . $ue->getCodeString() );
+                               $this->fail( "Received error '" . $ue->getCodeString() . "'" );
                        }
                }
 
@@ -213,10 +156,12 @@ class ApiWatchTest extends ApiTestSetup {
        }
 
        /**
-        * @depends testGetToken
+        * @group Broken
         */
-       function testWatchDelete( $data ) {
-               $this->markTestIncomplete( "Broken" );
+       function testWatchDelete() {
+               
+               $data = $this->getTokens();
+               
                $keys = array_keys( $data[0]['query']['pages'] );
                $key = array_pop( $keys );
                $pageinfo = $data[0]['query']['pages'][$key];
@@ -224,7 +169,7 @@ class ApiWatchTest extends ApiTestSetup {
                $data = $this->doApiRequest( array(
                        'action' => 'delete',
                        'token' => $pageinfo['deletetoken'],
-                       'title' => 'Main Page' ), $data );
+                       'title' => 'UTPage' ), $data );
                $this->assertArrayHasKey( 'delete', $data[0] );
                $this->assertArrayHasKey( 'title', $data[0]['delete'] );