MediaWiki
REL1_20
|
00001 <?php 00002 00008 class ApiWatchTest extends ApiTestCase { 00009 00010 function setUp() { 00011 parent::setUp(); 00012 $this->doLogin(); 00013 } 00014 00015 function getTokens() { 00016 $data = $this->getTokenList( self::$users['sysop'] ); 00017 00018 $keys = array_keys( $data[0]['query']['pages'] ); 00019 $key = array_pop( $keys ); 00020 $pageinfo = $data[0]['query']['pages'][$key]; 00021 00022 return $pageinfo; 00023 } 00024 00027 function testWatchEdit() { 00028 $pageinfo = $this->getTokens(); 00029 00030 $data = $this->doApiRequest( array( 00031 'action' => 'edit', 00032 'title' => 'UTPage', 00033 'text' => 'new text', 00034 'token' => $pageinfo['edittoken'], 00035 'watchlist' => 'watch' ) ); 00036 $this->assertArrayHasKey( 'edit', $data[0] ); 00037 $this->assertArrayHasKey( 'result', $data[0]['edit'] ); 00038 $this->assertEquals( 'Success', $data[0]['edit']['result'] ); 00039 00040 return $data; 00041 } 00042 00046 function testWatchClear() { 00047 00048 $pageinfo = $this->getTokens(); 00049 00050 $data = $this->doApiRequest( array( 00051 'action' => 'query', 00052 'list' => 'watchlist' ) ); 00053 00054 if ( isset( $data[0]['query']['watchlist'] ) ) { 00055 $wl = $data[0]['query']['watchlist']; 00056 00057 foreach ( $wl as $page ) { 00058 $data = $this->doApiRequest( array( 00059 'action' => 'watch', 00060 'title' => $page['title'], 00061 'unwatch' => true, 00062 'token' => $pageinfo['watchtoken'] ) ); 00063 } 00064 } 00065 $data = $this->doApiRequest( array( 00066 'action' => 'query', 00067 'list' => 'watchlist' ), $data ); 00068 $this->assertArrayHasKey( 'query', $data[0] ); 00069 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] ); 00070 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) ); 00071 00072 return $data; 00073 } 00074 00077 function testWatchProtect() { 00078 00079 $pageinfo = $this->getTokens(); 00080 00081 $data = $this->doApiRequest( array( 00082 'action' => 'protect', 00083 'token' => $pageinfo['protecttoken'], 00084 'title' => 'UTPage', 00085 'protections' => 'edit=sysop', 00086 'watchlist' => 'unwatch' ) ); 00087 00088 $this->assertArrayHasKey( 'protect', $data[0] ); 00089 $this->assertArrayHasKey( 'protections', $data[0]['protect'] ); 00090 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) ); 00091 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] ); 00092 } 00093 00096 function testGetRollbackToken() { 00097 00098 $pageinfo = $this->getTokens(); 00099 00100 if ( !Title::newFromText( 'UTPage' )->exists() ) { 00101 $this->markTestSkipped( "The article [[UTPage]] does not exist" ); //TODO: just create it? 00102 } 00103 00104 $data = $this->doApiRequest( array( 00105 'action' => 'query', 00106 'prop' => 'revisions', 00107 'titles' => 'UTPage', 00108 'rvtoken' => 'rollback' ) ); 00109 00110 $this->assertArrayHasKey( 'query', $data[0] ); 00111 $this->assertArrayHasKey( 'pages', $data[0]['query'] ); 00112 $keys = array_keys( $data[0]['query']['pages'] ); 00113 $key = array_pop( $keys ); 00114 00115 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) { 00116 $this->markTestSkipped( "Target page (UTPage) doesn't exist" ); 00117 } 00118 00119 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] ); 00120 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] ); 00121 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] ); 00122 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] ); 00123 00124 return $data; 00125 } 00126 00133 function testWatchRollback( $data ) { 00134 $keys = array_keys( $data[0]['query']['pages'] ); 00135 $key = array_pop( $keys ); 00136 $pageinfo = $data[0]['query']['pages'][$key]; 00137 $revinfo = $pageinfo['revisions'][0]; 00138 00139 try { 00140 $data = $this->doApiRequest( array( 00141 'action' => 'rollback', 00142 'title' => 'UTPage', 00143 'user' => $revinfo['user'], 00144 'token' => $pageinfo['rollbacktoken'], 00145 'watchlist' => 'watch' ) ); 00146 00147 $this->assertArrayHasKey( 'rollback', $data[0] ); 00148 $this->assertArrayHasKey( 'title', $data[0]['rollback'] ); 00149 } catch( UsageException $ue ) { 00150 if( $ue->getCodeString() == 'onlyauthor' ) { 00151 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" ); 00152 } else { 00153 $this->fail( "Received error '" . $ue->getCodeString() . "'" ); 00154 } 00155 } 00156 } 00157 00160 function testWatchDelete() { 00161 $pageinfo = $this->getTokens(); 00162 00163 $data = $this->doApiRequest( array( 00164 'action' => 'delete', 00165 'token' => $pageinfo['deletetoken'], 00166 'title' => 'UTPage' ) ); 00167 $this->assertArrayHasKey( 'delete', $data[0] ); 00168 $this->assertArrayHasKey( 'title', $data[0]['delete'] ); 00169 00170 $data = $this->doApiRequest( array( 00171 'action' => 'query', 00172 'list' => 'watchlist' ) ); 00173 00174 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' ); 00175 } 00176 }