MediaWiki  1.23.15
ApiWatchTest.php
Go to the documentation of this file.
1 <?php
2 
9 class ApiWatchTest extends ApiTestCase {
10  protected function setUp() {
11  parent::setUp();
12  $this->doLogin();
13  }
14 
15  function getTokens() {
16  return $this->getTokenList( self::$users['sysop'] );
17  }
18 
21  public function testWatchEdit() {
22  $tokens = $this->getTokens();
23 
24  $data = $this->doApiRequest( array(
25  'action' => 'edit',
26  'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
27  'text' => 'new text',
28  'token' => $tokens['edittoken'],
29  'watchlist' => 'watch' ) );
30  $this->assertArrayHasKey( 'edit', $data[0] );
31  $this->assertArrayHasKey( 'result', $data[0]['edit'] );
32  $this->assertEquals( 'Success', $data[0]['edit']['result'] );
33 
34  return $data;
35  }
36 
40  public function testWatchClear() {
41  $tokens = $this->getTokens();
42 
43  $data = $this->doApiRequest( array(
44  'action' => 'query',
45  'wllimit' => 'max',
46  'list' => 'watchlist' ) );
47 
48  if ( isset( $data[0]['query']['watchlist'] ) ) {
49  $wl = $data[0]['query']['watchlist'];
50 
51  foreach ( $wl as $page ) {
52  $data = $this->doApiRequest( array(
53  'action' => 'watch',
54  'title' => $page['title'],
55  'unwatch' => true,
56  'token' => $tokens['watchtoken'] ) );
57  }
58  }
59  $data = $this->doApiRequest( array(
60  'action' => 'query',
61  'list' => 'watchlist' ), $data );
62  $this->assertArrayHasKey( 'query', $data[0] );
63  $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
64  foreach ( $data[0]['query']['watchlist'] as $index => $item ) {
65  // Previous tests may insert an invalid title
66  // like ":ApiEditPageTest testNonTextEdit", which
67  // can't be cleared.
68  if ( strpos( $item['title'], ':' ) === 0 ) {
69  unset( $data[0]['query']['watchlist'][$index] );
70  }
71  }
72  $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
73 
74  return $data;
75  }
76 
79  public function testWatchProtect() {
80  $tokens = $this->getTokens();
81 
82  $data = $this->doApiRequest( array(
83  'action' => 'protect',
84  'token' => $tokens['protecttoken'],
85  'title' => 'Help:UTPage',
86  'protections' => 'edit=sysop',
87  'watchlist' => 'unwatch' ) );
88 
89  $this->assertArrayHasKey( 'protect', $data[0] );
90  $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
91  $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
92  $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
93  }
94 
97  public function testGetRollbackToken() {
98  $this->getTokens();
99 
100  if ( !Title::newFromText( 'Help:UTPage' )->exists() ) {
101  $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
102  }
103 
104  $data = $this->doApiRequest( array(
105  'action' => 'query',
106  'prop' => 'revisions',
107  'titles' => 'Help:UTPage',
108  'rvtoken' => 'rollback' ) );
109 
110  $this->assertArrayHasKey( 'query', $data[0] );
111  $this->assertArrayHasKey( 'pages', $data[0]['query'] );
112  $keys = array_keys( $data[0]['query']['pages'] );
113  $key = array_pop( $keys );
114 
115  if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
116  $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
117  }
118 
119  $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
120  $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
121  $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
122  $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
123 
124  return $data;
125  }
126 
133  public function testWatchRollback( $data ) {
134  $keys = array_keys( $data[0]['query']['pages'] );
135  $key = array_pop( $keys );
136  $pageinfo = $data[0]['query']['pages'][$key];
137  $revinfo = $pageinfo['revisions'][0];
138 
139  try {
140  $data = $this->doApiRequest( array(
141  'action' => 'rollback',
142  'title' => 'Help:UTPage',
143  'user' => $revinfo['user'],
144  'token' => $pageinfo['rollbacktoken'],
145  'watchlist' => 'watch' ) );
146 
147  $this->assertArrayHasKey( 'rollback', $data[0] );
148  $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
149  } catch ( UsageException $ue ) {
150  if ( $ue->getCodeString() == 'onlyauthor' ) {
151  $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
152  } else {
153  $this->fail( "Received error '" . $ue->getCodeString() . "'" );
154  }
155  }
156  }
157 }
ApiWatchTest\testWatchProtect
testWatchProtect()
Definition: ApiWatchTest.php:79
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiTestCase\getTokenList
getTokenList( $user, $session=null)
Definition: ApiTestCase.php:166
ApiWatchTest\setUp
setUp()
Definition: ApiWatchTest.php:10
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
ApiWatchTest\testGetRollbackToken
testGetRollbackToken()
Definition: ApiWatchTest.php:97
ApiWatchTest\testWatchEdit
testWatchEdit()
Definition: ApiWatchTest.php:21
UsageException
This exception will be thrown when dieUsage is called to stop module execution.
Definition: ApiMain.php:1439
ApiWatchTest
@group API @group Database @group medium
Definition: ApiWatchTest.php:9
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiTestCase
Definition: ApiTestCase.php:3
ApiWatchTest\getTokens
getTokens()
Definition: ApiWatchTest.php:15
ApiWatchTest\testWatchRollback
testWatchRollback( $data)
@group Broken Broken because there is currently no revision info in the $pageinfo
Definition: ApiWatchTest.php:133
ApiWatchTest\testWatchClear
testWatchClear()
@depends testWatchEdit
Definition: ApiWatchTest.php:40
UsageException\getCodeString
getCodeString()
Definition: ApiMain.php:1462
ApiTestCase\doLogin
doLogin( $user='sysop')
Definition: ApiTestCase.php:141
ApiTestCase\doApiRequest
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:74
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$keys
$keys
Definition: testCompression.php:63