1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<?php
/**
* @group API
* @group Database
* @group medium
* @todo This test suite is severly broken and need a full review
*/
class ApiWatchTest extends ApiTestCase {
protected function setUp() {
parent::setUp();
$this->doLogin();
}
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;
}
/**
*/
function testWatchEdit() {
$pageinfo = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'edit',
'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
'text' => 'new text',
'token' => $pageinfo['edittoken'],
'watchlist' => 'watch' ) );
$this->assertArrayHasKey( 'edit', $data[0] );
$this->assertArrayHasKey( 'result', $data[0]['edit'] );
$this->assertEquals( 'Success', $data[0]['edit']['result'] );
return $data;
}
/**
* @depends testWatchEdit
*/
function testWatchClear() {
$pageinfo = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'query',
'list' => 'watchlist' ) );
if ( isset( $data[0]['query']['watchlist'] ) ) {
$wl = $data[0]['query']['watchlist'];
foreach ( $wl as $page ) {
$data = $this->doApiRequest( array(
'action' => 'watch',
'title' => $page['title'],
'unwatch' => true,
'token' => $pageinfo['watchtoken'] ) );
}
}
$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;
}
/**
*/
function testWatchProtect() {
$pageinfo = $this->getTokens();
$data = $this->doApiRequest( array(
'action' => 'protect',
'token' => $pageinfo['protecttoken'],
'title' => 'Help:UTPage',
'protections' => 'edit=sysop',
'watchlist' => 'unwatch' ) );
$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] );
}
/**
*/
function testGetRollbackToken() {
$pageinfo = $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' => 'Help:UTPage',
'rvtoken' => 'rollback' ) );
$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'] ) ) {
$this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
}
$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;
}
/**
* @group Broken
* Broken because there is currently no revision info in the $pageinfo
*
* @depends testGetRollbackToken
*/
function testWatchRollback( $data ) {
$keys = array_keys( $data[0]['query']['pages'] );
$key = array_pop( $keys );
$pageinfo = $data[0]['query']['pages'][$key];
$revinfo = $pageinfo['revisions'][0];
try {
$data = $this->doApiRequest( array(
'action' => 'rollback',
'title' => 'Help:UTPage',
'user' => $revinfo['user'],
'token' => $pageinfo['rollbacktoken'],
'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() . "'" );
}
}
}
/**
*/
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'] );
$data = $this->doApiRequest( array(
'action' => 'query',
'list' => 'watchlist' ) );
$this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
}
}
|