Merge "Never cache pages with the fallback skin"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiWatchTest.php
index 0fa8053..e49c6c0 100644 (file)
@@ -1,37 +1,32 @@
 <?php
 
 /**
+ * @group API
  * @group Database
- * @todo This test suite is severly broken and need a full review 
+ * @group medium
+ * @todo This test suite is severly broken and need a full review
  */
 class ApiWatchTest extends ApiTestCase {
-
-       function setUp() {
+       protected function setUp() {
                parent::setUp();
                $this->doLogin();
        }
-       
+
        function getTokens() {
                return $this->getTokenList( self::$users['sysop'] );
        }
 
        /**
-        * @group Broken
         */
-       function testWatchEdit() {
-               
-               $data = $this->getTokens();
-               
-               $keys = array_keys( $data[0]['query']['pages'] );
-               $key = array_pop( $keys );
-               $pageinfo = $data[0]['query']['pages'][$key];
+       public function testWatchEdit() {
+               $tokens = $this->getTokens();
 
                $data = $this->doApiRequest( array(
                        'action' => 'edit',
-                       'title' => 'UTPage',
+                       'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
                        'text' => 'new text',
-                       'token' => $pageinfo['edittoken'],
-                       'watchlist' => 'watch' ), $data );
+                       'token' => $tokens['edittoken'],
+                       'watchlist' => 'watch' ) );
                $this->assertArrayHasKey( 'edit', $data[0] );
                $this->assertArrayHasKey( 'result', $data[0]['edit'] );
                $this->assertEquals( 'Success', $data[0]['edit']['result'] );
@@ -41,13 +36,14 @@ class ApiWatchTest extends ApiTestCase {
 
        /**
         * @depends testWatchEdit
-        * @group Broken
         */
-       function testWatchClear() {
-       
+       public function testWatchClear() {
+               $tokens = $this->getTokens();
+
                $data = $this->doApiRequest( array(
                        'action' => 'query',
-                       'list' => 'watchlist' ), $data );
+                       'wllimit' => 'max',
+                       'list' => 'watchlist' ) );
 
                if ( isset( $data[0]['query']['watchlist'] ) ) {
                        $wl = $data[0]['query']['watchlist'];
@@ -56,7 +52,8 @@ class ApiWatchTest extends ApiTestCase {
                                $data = $this->doApiRequest( array(
                                        'action' => 'watch',
                                        'title' => $page['title'],
-                                       'unwatch' => true ), $data );
+                                       'unwatch' => true,
+                                       'token' => $tokens['watchtoken'] ) );
                        }
                }
                $data = $this->doApiRequest( array(
@@ -64,28 +61,30 @@ class ApiWatchTest extends ApiTestCase {
                        'list' => 'watchlist' ), $data );
                $this->assertArrayHasKey( 'query', $data[0] );
                $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
+               foreach ( $data[0]['query']['watchlist'] as $index => $item ) {
+                       // Previous tests may insert an invalid title
+                       // like ":ApiEditPageTest testNonTextEdit", which
+                       // can't be cleared.
+                       if ( strpos( $item['title'], ':' ) === 0 ) {
+                               unset( $data[0]['query']['watchlist'][$index] );
+                       }
+               }
                $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
 
                return $data;
        }
 
        /**
-        * @group Broken
-        */      
-       function testWatchProtect() {
-               
-               $data = $this->getTokens();
-               
-               $keys = array_keys( $data[0]['query']['pages'] );
-               $key = array_pop( $keys );
-               $pageinfo = $data[0]['query']['pages'][$key];
+        */
+       public function testWatchProtect() {
+               $tokens = $this->getTokens();
 
                $data = $this->doApiRequest( array(
                        'action' => 'protect',
-                       'token' => $pageinfo['protecttoken'],
-                       'title' => 'UTPage',
+                       'token' => $tokens['protecttoken'],
+                       'title' => 'Help:UTPage',
                        'protections' => 'edit=sysop',
-                       'watchlist' => 'unwatch' ), $data );
+                       'watchlist' => 'unwatch' ) );
 
                $this->assertArrayHasKey( 'protect', $data[0] );
                $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
@@ -93,20 +92,20 @@ class ApiWatchTest extends ApiTestCase {
                $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
        }
 
-       
-       function testGetRollbackToken() {
-               
-               $data = $this->getTokens();
-               
-               if ( !Title::newFromText( 'UTPage' )->exists() ) {
-                       $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
+       /**
+        */
+       public function testGetRollbackToken() {
+               $this->getTokens();
+
+               if ( !Title::newFromText( 'Help:UTPage' )->exists() ) {
+                       $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
                }
 
                $data = $this->doApiRequest( array(
                        'action' => 'query',
                        'prop' => 'revisions',
-                       'titles' => 'UTPage',
-                       'rvtoken' => 'rollback' ), $data );
+                       'titles' => 'Help:UTPage',
+                       'rvtoken' => 'rollback' ) );
 
                $this->assertArrayHasKey( 'query', $data[0] );
                $this->assertArrayHasKey( 'pages', $data[0]['query'] );
@@ -114,7 +113,7 @@ class ApiWatchTest extends ApiTestCase {
                $key = array_pop( $keys );
 
                if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
-                       $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
+                       $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
                }
 
                $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
@@ -126,55 +125,33 @@ class ApiWatchTest extends ApiTestCase {
        }
 
        /**
-        * @depends testGetRollbackToken
         * @group Broken
+        * Broken because there is currently no revision info in the $pageinfo
+        *
+        * @depends testGetRollbackToken
         */
-       function testWatchRollback( $data ) {
+       public function testWatchRollback( $data ) {
                $keys = array_keys( $data[0]['query']['pages'] );
                $key = array_pop( $keys );
-               $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
+               $pageinfo = $data[0]['query']['pages'][$key];
+               $revinfo = $pageinfo['revisions'][0];
 
                try {
                        $data = $this->doApiRequest( array(
                                'action' => 'rollback',
-                               'title' => 'UTPage',
-                               'user' => $pageinfo['user'],
+                               'title' => 'Help:UTPage',
+                               'user' => $revinfo['user'],
                                'token' => $pageinfo['rollbacktoken'],
-                               'watchlist' => 'watch' ), $data );
-               } catch( UsageException $ue ) {
-                       if( $ue->getCodeString() == 'onlyauthor' ) {
-                               $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
+                               'watchlist' => 'watch' ) );
+
+                       $this->assertArrayHasKey( 'rollback', $data[0] );
+                       $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
+               } catch ( UsageException $ue ) {
+                       if ( $ue->getCodeString() == 'onlyauthor' ) {
+                               $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
                        } else {
                                $this->fail( "Received error '" . $ue->getCodeString() . "'" );
                        }
                }
-
-               $this->assertArrayHasKey( 'rollback', $data[0] );
-               $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
-       }
-
-       /**
-        * @group Broken
-        */
-       function testWatchDelete() {
-               
-               $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' => 'delete',
-                       'token' => $pageinfo['deletetoken'],
-                       'title' => 'UTPage' ), $data );
-               $this->assertArrayHasKey( 'delete', $data[0] );
-               $this->assertArrayHasKey( 'title', $data[0]['delete'] );
-
-               $data = $this->doApiRequest( array(
-                       'action' => 'query',
-                       'list' => 'watchlist' ), $data );
-
-               $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
        }
 }