Remove unused param in RCCacheEntryFactoryTest
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / RCCacheEntryFactoryTest.php
1 <?php
2
3 /**
4 * @covers RCCacheEntryFactory
5 *
6 * @group Database
7 *
8 * @licence GNU GPL v2+
9 * @author Katie Filbert < aude.wiki@gmail.com >
10 */
11 class RCCacheEntryFactoryTest extends MediaWikiLangTestCase {
12
13 /**
14 * @var TestRecentChangesHelper
15 */
16 private $testRecentChangesHelper;
17
18 public function __construct( $name = null, array $data = array(), $dataName = '' ) {
19 parent::__construct( $name, $data, $dataName );
20
21 $this->testRecentChangesHelper = new TestRecentChangesHelper();
22 }
23
24 protected function setUp() {
25 parent::setUp();
26
27 $this->setMwGlobals( array(
28 'wgArticlePath' => '/wiki/$1'
29 ) );
30 }
31
32 /**
33 * @dataProvider editChangeProvider
34 */
35 public function testNewFromRecentChange( $expected, $context, $messages,
36 $recentChange, $watched
37 ) {
38 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
39 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
40
41 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
42
43 $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
44 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
45 $this->assertEquals(
46 $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers,
47 'watching users'
48 );
49 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
50
51 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
52 $this->assertTitleLink( 'Xyz', $cacheEntry );
53
54 $this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink, 'cur link' );
55 $this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink, 'prev link' );
56 $this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink, 'diff link' );
57 }
58
59 public function editChangeProvider() {
60 $user = $this->testRecentChangesHelper->getTestUser();
61
62 return array(
63 array(
64 array(
65 'title' => 'Xyz',
66 'user' => 'TestRecentChangesUser',
67 'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
68 'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
69 'timestamp' => '21:21',
70 'numberofWatchingusers' => 0,
71 'unpatrolled' => false
72 ),
73 $this->getContext(),
74 $this->getMessages(),
75 $this->testRecentChangesHelper->makeEditRecentChange(
76 $user,
77 'Xyz',
78 5, // curid
79 191, // thisid
80 190, // lastid
81 '20131103212153',
82 0, // counter
83 0 // number of watching users
84 ),
85 false
86 )
87 );
88 }
89
90 /**
91 * @dataProvider deleteChangeProvider
92 */
93 public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
94 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
95 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
96
97 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
98
99 $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
100 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
101 $this->assertEquals(
102 $expected['numberofWatchingusers'],
103 $cacheEntry->numberofWatchingusers, 'watching users'
104 );
105 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
106
107 $this->assertDeleteLogLink( $cacheEntry );
108 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
109
110 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
111 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
112 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
113 }
114
115 public function deleteChangeProvider() {
116 $user = $this->testRecentChangesHelper->getTestUser();
117
118 return array(
119 array(
120 array(
121 'title' => 'Abc',
122 'user' => 'TestRecentChangesUser',
123 'timestamp' => '21:21',
124 'numberofWatchingusers' => 0,
125 'unpatrolled' => false
126 ),
127 $this->getContext(),
128 $this->getMessages(),
129 $this->testRecentChangesHelper->makeLogRecentChange(
130 $user,
131 'Abc',
132 '20131103212153',
133 0, // counter
134 0 // number of watching users
135 ),
136 false
137 )
138 );
139 }
140
141 /**
142 * @dataProvider revUserDeleteProvider
143 */
144 public function testNewForRevUserDeleteChange( $expected, $context, $messages,
145 $recentChange, $watched
146 ) {
147 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
148 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
149
150 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
151
152 $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
153 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
154 $this->assertEquals(
155 $expected['numberofWatchingusers'],
156 $cacheEntry->numberofWatchingusers, 'watching users'
157 );
158 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
159
160 $this->assertRevDel( $cacheEntry );
161 $this->assertTitleLink( 'Zzz', $cacheEntry );
162
163 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
164 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
165 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
166 }
167
168 public function revUserDeleteProvider() {
169 $user = $this->testRecentChangesHelper->getTestUser();
170
171 return array(
172 array(
173 array(
174 'title' => 'Zzz',
175 'user' => 'TestRecentChangesUser',
176 'diff' => '',
177 'cur' => '',
178 'timestamp' => '21:21',
179 'numberofWatchingusers' => 0,
180 'unpatrolled' => false
181 ),
182 $this->getContext(),
183 $this->getMessages(),
184 $this->testRecentChangesHelper->makeDeletedEditRecentChange(
185 $user,
186 'Zzz',
187 '20131103212153',
188 191, // thisid
189 190, // lastid
190 '20131103212153',
191 0, // counter
192 0 // number of watching users
193 ),
194 false
195 )
196 );
197 }
198
199 private function assertUserLinks( $user, $cacheEntry ) {
200 $this->assertTag(
201 array(
202 'tag' => 'a',
203 'attributes' => array(
204 'class' => 'new mw-userlink'
205 ),
206 'content' => $user
207 ),
208 $cacheEntry->userlink,
209 'verify user link'
210 );
211
212 $this->assertTag(
213 array(
214 'tag' => 'span',
215 'attributes' => array(
216 'class' => 'mw-usertoollinks'
217 ),
218 'child' => array(
219 'tag' => 'a',
220 'content' => 'Talk',
221 )
222 ),
223 $cacheEntry->usertalklink,
224 'verify user talk link'
225 );
226
227 $this->assertTag(
228 array(
229 'tag' => 'span',
230 'attributes' => array(
231 'class' => 'mw-usertoollinks'
232 ),
233 'child' => array(
234 'tag' => 'a',
235 'content' => 'contribs',
236 )
237 ),
238 $cacheEntry->usertalklink,
239 'verify user tool links'
240 );
241 }
242
243 private function assertDeleteLogLink( $cacheEntry ) {
244 $this->assertTag(
245 array(
246 'tag' => 'a',
247 'attributes' => array(
248 'href' => '/wiki/Special:Log/delete',
249 'title' => 'Special:Log/delete'
250 ),
251 'content' => 'Deletion log'
252 ),
253 $cacheEntry->link,
254 'verify deletion log link'
255 );
256 }
257
258 private function assertRevDel( $cacheEntry ) {
259 $this->assertTag(
260 array(
261 'tag' => 'span',
262 'attributes' => array(
263 'class' => 'history-deleted'
264 ),
265 'content' => '(username removed)'
266 ),
267 $cacheEntry->userlink,
268 'verify user link for change with deleted revision and user'
269 );
270 }
271
272 private function assertTitleLink( $title, $cacheEntry ) {
273 $this->assertTag(
274 array(
275 'tag' => 'a',
276 'attributes' => array(
277 'href' => '/wiki/' . $title,
278 'title' => $title
279 ),
280 'content' => $title
281 ),
282 $cacheEntry->link,
283 'verify title link'
284 );
285 }
286
287 private function assertQueryLink( $content, $params, $link ) {
288 $this->assertTag(
289 array(
290 'tag' => 'a',
291 'content' => $content
292 ),
293 $link,
294 'assert query link element'
295 );
296
297 foreach ( $params as $key => $value ) {
298 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
299 }
300 }
301
302 private function getMessages() {
303 return array(
304 'cur' => 'cur',
305 'diff' => 'diff',
306 'hist' => 'hist',
307 'enhancedrc-history' => 'history',
308 'last' => 'prev',
309 'blocklink' => 'block',
310 'history' => 'Page history',
311 'semicolon-separator' => '; ',
312 'pipe-separator' => ' | '
313 );
314 }
315
316 private function getContext() {
317 $context = $this->testRecentChangesHelper->getTestContext();
318
319 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
320 $context->setTitle( $title );
321
322 return $context;
323 }
324 }