Merge "Never cache pages with the fallback skin"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiWatchTest.php
index a9bc43a..e49c6c0 100644 (file)
@@ -13,25 +13,19 @@ class ApiWatchTest extends ApiTestCase {
        }
 
        function getTokens() {
-               $data = $this->getTokenList( self::$users['sysop'] );
-
-               $keys = array_keys( $data[0]['query']['pages'] );
-               $key = array_pop( $keys );
-               $pageinfo = $data[0]['query']['pages'][$key];
-
-               return $pageinfo;
+               return $this->getTokenList( self::$users['sysop'] );
        }
 
        /**
         */
-       function testWatchEdit() {
-               $pageinfo = $this->getTokens();
+       public function testWatchEdit() {
+               $tokens = $this->getTokens();
 
                $data = $this->doApiRequest( array(
                        'action' => 'edit',
                        'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
                        'text' => 'new text',
-                       'token' => $pageinfo['edittoken'],
+                       'token' => $tokens['edittoken'],
                        'watchlist' => 'watch' ) );
                $this->assertArrayHasKey( 'edit', $data[0] );
                $this->assertArrayHasKey( 'result', $data[0]['edit'] );
@@ -43,12 +37,12 @@ class ApiWatchTest extends ApiTestCase {
        /**
         * @depends testWatchEdit
         */
-       function testWatchClear() {
-
-               $pageinfo = $this->getTokens();
+       public function testWatchClear() {
+               $tokens = $this->getTokens();
 
                $data = $this->doApiRequest( array(
                        'action' => 'query',
+                       'wllimit' => 'max',
                        'list' => 'watchlist' ) );
 
                if ( isset( $data[0]['query']['watchlist'] ) ) {
@@ -59,7 +53,7 @@ class ApiWatchTest extends ApiTestCase {
                                        'action' => 'watch',
                                        'title' => $page['title'],
                                        'unwatch' => true,
-                                       'token' => $pageinfo['watchtoken'] ) );
+                                       'token' => $tokens['watchtoken'] ) );
                        }
                }
                $data = $this->doApiRequest( array(
@@ -67,6 +61,14 @@ 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;
@@ -74,13 +76,12 @@ class ApiWatchTest extends ApiTestCase {
 
        /**
         */
-       function testWatchProtect() {
-
-               $pageinfo = $this->getTokens();
+       public function testWatchProtect() {
+               $tokens = $this->getTokens();
 
                $data = $this->doApiRequest( array(
                        'action' => 'protect',
-                       'token' => $pageinfo['protecttoken'],
+                       'token' => $tokens['protecttoken'],
                        'title' => 'Help:UTPage',
                        'protections' => 'edit=sysop',
                        'watchlist' => 'unwatch' ) );
@@ -93,7 +94,7 @@ class ApiWatchTest extends ApiTestCase {
 
        /**
         */
-       function testGetRollbackToken() {
+       public function testGetRollbackToken() {
                $this->getTokens();
 
                if ( !Title::newFromText( 'Help:UTPage' )->exists() ) {
@@ -129,7 +130,7 @@ class ApiWatchTest extends ApiTestCase {
         *
         * @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];
@@ -153,23 +154,4 @@ class ApiWatchTest extends ApiTestCase {
                        }
                }
        }
-
-       /**
-        */
-       function testWatchDelete() {
-               $pageinfo = $this->getTokens();
-
-               $data = $this->doApiRequest( array(
-                       'action' => 'delete',
-                       'token' => $pageinfo['deletetoken'],
-                       'title' => 'Help:UTPage' ) );
-               $this->assertArrayHasKey( 'delete', $data[0] );
-               $this->assertArrayHasKey( 'title', $data[0]['delete'] );
-
-               $this->doApiRequest( array(
-                       'action' => 'query',
-                       'list' => 'watchlist' ) );
-
-               $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
-       }
 }