2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-02 13:33:43 +00:00
|
|
|
* @group API
|
2010-12-14 16:26:35 +00:00
|
|
|
* @group Database
|
2013-01-18 19:02:28 +00:00
|
|
|
* @group medium
|
2012-04-02 13:33:43 +00:00
|
|
|
* @todo This test suite is severly broken and need a full review
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
2011-07-01 16:34:02 +00:00
|
|
|
class ApiWatchTest extends ApiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2010-12-14 16:26:35 +00:00
|
|
|
parent::setUp();
|
2011-01-02 05:52:00 +00:00
|
|
|
$this->doLogin();
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2012-04-02 13:33:43 +00:00
|
|
|
|
2011-01-02 05:52:00 +00:00
|
|
|
function getTokens() {
|
2012-06-22 20:51:51 +00:00
|
|
|
$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;
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-30 18:58:07 +00:00
|
|
|
/**
|
|
|
|
|
*/
|
2011-01-02 05:52:00 +00:00
|
|
|
function testWatchEdit() {
|
2012-06-22 20:51:51 +00:00
|
|
|
$pageinfo = $this->getTokens();
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'edit',
|
2012-09-19 18:07:56 +00:00
|
|
|
'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
|
2010-12-14 16:26:35 +00:00
|
|
|
'text' => 'new text',
|
|
|
|
|
'token' => $pageinfo['edittoken'],
|
2012-06-22 20:51:51 +00:00
|
|
|
'watchlist' => 'watch' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertArrayHasKey( 'edit', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'result', $data[0]['edit'] );
|
|
|
|
|
$this->assertEquals( 'Success', $data[0]['edit']['result'] );
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testWatchEdit
|
|
|
|
|
*/
|
2011-01-02 05:52:00 +00:00
|
|
|
function testWatchClear() {
|
2012-04-02 13:33:43 +00:00
|
|
|
|
2012-06-22 20:51:51 +00:00
|
|
|
$pageinfo = $this->getTokens();
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'query',
|
2012-06-22 20:51:51 +00:00
|
|
|
'list' => 'watchlist' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
if ( isset( $data[0]['query']['watchlist'] ) ) {
|
|
|
|
|
$wl = $data[0]['query']['watchlist'];
|
|
|
|
|
|
|
|
|
|
foreach ( $wl as $page ) {
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'watch',
|
|
|
|
|
'title' => $page['title'],
|
2012-06-22 20:51:51 +00:00
|
|
|
'unwatch' => true,
|
|
|
|
|
'token' => $pageinfo['watchtoken'] ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'list' => 'watchlist' ), $data );
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
|
|
|
|
|
$this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-30 18:58:07 +00:00
|
|
|
/**
|
2012-04-02 13:33:43 +00:00
|
|
|
*/
|
2011-01-02 05:52:00 +00:00
|
|
|
function testWatchProtect() {
|
2012-04-02 13:33:43 +00:00
|
|
|
|
2012-06-22 20:51:51 +00:00
|
|
|
$pageinfo = $this->getTokens();
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'protect',
|
|
|
|
|
'token' => $pageinfo['protecttoken'],
|
2012-09-19 18:07:56 +00:00
|
|
|
'title' => 'Help:UTPage',
|
2010-12-14 16:26:35 +00:00
|
|
|
'protections' => 'edit=sysop',
|
2012-06-22 20:51:51 +00:00
|
|
|
'watchlist' => 'unwatch' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'protect', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'protections', $data[0]['protect'] );
|
|
|
|
|
$this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
|
|
|
|
|
$this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-27 21:01:28 +00:00
|
|
|
/**
|
|
|
|
|
*/
|
2011-01-02 05:52:00 +00:00
|
|
|
function testGetRollbackToken() {
|
2013-04-26 07:48:46 +00:00
|
|
|
$this->getTokens();
|
2012-04-02 13:33:43 +00:00
|
|
|
|
2012-09-19 18:07:56 +00:00
|
|
|
if ( !Title::newFromText( 'Help:UTPage' )->exists() ) {
|
|
|
|
|
$this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
'prop' => 'revisions',
|
2012-09-19 18:07:56 +00:00
|
|
|
'titles' => 'Help:UTPage',
|
2012-06-22 20:51:51 +00:00
|
|
|
'rvtoken' => 'rollback' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'query', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'pages', $data[0]['query'] );
|
|
|
|
|
$keys = array_keys( $data[0]['query']['pages'] );
|
|
|
|
|
$key = array_pop( $keys );
|
|
|
|
|
|
|
|
|
|
if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
|
2012-09-19 18:07:56 +00:00
|
|
|
$this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
|
|
|
|
|
$this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
|
|
|
|
|
$this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
|
|
|
|
|
$this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-30 18:58:07 +00:00
|
|
|
* @group Broken
|
2012-06-22 20:51:51 +00:00
|
|
|
* Broken because there is currently no revision info in the $pageinfo
|
|
|
|
|
*
|
|
|
|
|
* @depends testGetRollbackToken
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
|
|
|
|
function testWatchRollback( $data ) {
|
|
|
|
|
$keys = array_keys( $data[0]['query']['pages'] );
|
|
|
|
|
$key = array_pop( $keys );
|
2012-06-22 20:51:51 +00:00
|
|
|
$pageinfo = $data[0]['query']['pages'][$key];
|
|
|
|
|
$revinfo = $pageinfo['revisions'][0];
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'rollback',
|
2012-09-19 18:07:56 +00:00
|
|
|
'title' => 'Help:UTPage',
|
2012-06-22 20:51:51 +00:00
|
|
|
'user' => $revinfo['user'],
|
2010-12-14 16:26:35 +00:00
|
|
|
'token' => $pageinfo['rollbacktoken'],
|
2012-06-22 20:51:51 +00:00
|
|
|
'watchlist' => 'watch' ) );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'rollback', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'title', $data[0]['rollback'] );
|
2013-02-14 13:10:38 +00:00
|
|
|
} catch ( UsageException $ue ) {
|
|
|
|
|
if ( $ue->getCodeString() == 'onlyauthor' ) {
|
2012-09-19 18:07:56 +00:00
|
|
|
$this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
|
2010-12-14 16:26:35 +00:00
|
|
|
} else {
|
2011-05-30 18:58:07 +00:00
|
|
|
$this->fail( "Received error '" . $ue->getCodeString() . "'" );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-30 18:58:07 +00:00
|
|
|
/**
|
|
|
|
|
*/
|
2011-01-02 05:52:00 +00:00
|
|
|
function testWatchDelete() {
|
2012-06-22 20:51:51 +00:00
|
|
|
$pageinfo = $this->getTokens();
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$data = $this->doApiRequest( array(
|
|
|
|
|
'action' => 'delete',
|
|
|
|
|
'token' => $pageinfo['deletetoken'],
|
2012-09-19 18:07:56 +00:00
|
|
|
'title' => 'Help:UTPage' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertArrayHasKey( 'delete', $data[0] );
|
|
|
|
|
$this->assertArrayHasKey( 'title', $data[0]['delete'] );
|
|
|
|
|
|
2013-04-26 07:48:46 +00:00
|
|
|
$this->doApiRequest( array(
|
2010-12-14 16:26:35 +00:00
|
|
|
'action' => 'query',
|
2012-06-22 20:51:51 +00:00
|
|
|
'list' => 'watchlist' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
|
|
|
|
$this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
|
|
|
|
|
}
|
|
|
|
|
}
|