4 * @covers RCCacheEntryFactory
9 * @author Katie Filbert < aude.wiki@gmail.com >
11 class RCCacheEntryFactoryTest
extends MediaWikiLangTestCase
{
12 protected function setUp() {
15 $this->setMwGlobals( array(
16 'wgArticlePath' => '/wiki/$1'
21 * @dataProvider editChangeProvider
23 public function testNewFromRecentChange( $expected, $context, $messages,
24 $recentChange, $watched
26 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
27 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
29 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
31 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
32 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
34 $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers
,
37 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
39 $this->assertUserLinks( 'Mary', $cacheEntry );
40 $this->assertTitleLink( 'Xyz', $cacheEntry );
42 $this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink
, 'cur link' );
43 $this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink
, 'prev link' );
44 $this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink
, 'diff link' );
47 public function editChangeProvider() {
53 'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
54 'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
55 'timestamp' => '21:21',
56 'numberofWatchingusers' => 0,
57 'unpatrolled' => false
61 $this->makeEditRecentChange(
69 0 // number of watching users
77 private function makeEditRecentChange( $title, $user, $curid, $thisid, $lastid,
78 $timestamp, $counter, $watchingUsers
81 $attribs = array_merge(
82 $this->getDefaultAttributes( $title, $timestamp ),
84 'rc_user' => $user->getId(),
85 'rc_user_text' => $user->getName(),
86 'rc_this_oldid' => $thisid,
87 'rc_last_oldid' => $lastid,
92 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
96 * @dataProvider deleteChangeProvider
98 public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
99 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
100 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
102 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
104 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
105 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
107 $expected['numberofWatchingusers'],
108 $cacheEntry->numberofWatchingusers
, 'watching users'
110 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
112 $this->assertDeleteLogLink( $cacheEntry );
113 $this->assertUserLinks( 'Mary', $cacheEntry );
115 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
116 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
117 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
120 public function deleteChangeProvider() {
126 'timestamp' => '21:21',
127 'numberofWatchingusers' => 0,
128 'unpatrolled' => false
131 $this->getMessages(),
132 $this->makeLogRecentChange(
134 $this->getTestUser(),
137 0 // number of watching users
145 private function makeLogRecentChange( $title, $user, $timestamp, $counter, $watchingUsers ) {
146 $attribs = array_merge(
147 $this->getDefaultAttributes( $title, $timestamp ),
150 'rc_user' => $user->getId(),
151 'rc_user_text' => $user->getName(),
152 'rc_this_oldid' => 0,
153 'rc_last_oldid' => 0,
154 'rc_old_len' => null,
155 'rc_new_len' => null,
158 'rc_log_type' => 'delete',
159 'rc_log_action' => 'delete'
163 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
167 * @dataProvider revUserDeleteProvider
169 public function testNewForRevUserDeleteChange( $expected, $context, $messages,
170 $recentChange, $watched
172 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
173 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
175 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
177 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
178 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
180 $expected['numberofWatchingusers'],
181 $cacheEntry->numberofWatchingusers
, 'watching users'
183 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
185 $this->assertRevDel( $cacheEntry );
186 $this->assertTitleLink( 'Zzz', $cacheEntry );
188 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
189 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
190 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
193 public function revUserDeleteProvider() {
201 'timestamp' => '21:21',
202 'numberofWatchingusers' => 0,
203 'unpatrolled' => false
206 $this->getMessages(),
207 $this->makeDeletedEditRecentChange(
209 $this->getTestUser(),
215 0 // number of watching users
223 private function makeDeletedEditRecentChange( $title, $user, $timestamp, $curid, $thisid,
224 $lastid, $counter, $watchingUsers
226 $attribs = array_merge(
227 $this->getDefaultAttributes( $title, $timestamp ),
229 'rc_user' => $user->getId(),
230 'rc_user_text' => $user->getName(),
232 'rc_cur_id' => $curid,
233 'rc_this_oldid' => $thisid,
234 'rc_last_oldid' => $lastid
238 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
241 private function assertUserLinks( $user, $cacheEntry ) {
245 'attributes' => array(
246 'class' => 'new mw-userlink'
250 $cacheEntry->userlink
,
257 'attributes' => array(
258 'class' => 'mw-usertoollinks'
265 $cacheEntry->usertalklink
,
266 'verify user talk link'
272 'attributes' => array(
273 'class' => 'mw-usertoollinks'
277 'content' => 'contribs',
280 $cacheEntry->usertalklink
,
281 'verify user tool links'
285 private function assertDeleteLogLink( $cacheEntry ) {
289 'attributes' => array(
290 'href' => '/wiki/Special:Log/delete',
291 'title' => 'Special:Log/delete'
293 'content' => 'Deletion log'
296 'verify deletion log link'
300 private function assertRevDel( $cacheEntry ) {
304 'attributes' => array(
305 'class' => 'history-deleted'
307 'content' => '(username removed)'
309 $cacheEntry->userlink
,
310 'verify user link for change with deleted revision and user'
314 private function assertTitleLink( $title, $cacheEntry ) {
318 'attributes' => array(
319 'href' => '/wiki/' . $title,
329 private function assertQueryLink( $content, $params, $link ) {
333 'content' => $content
336 'assert query link element'
339 foreach ( $params as $key => $value ) {
340 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
344 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
345 $change = new RecentChange();
346 $change->setAttribs( $attribs );
347 $change->counter
= $counter;
348 $change->numberofWatchingusers
= $watchingUsers;
353 private function getDefaultAttributes( $title, $timestamp ) {
357 'rc_user_text' => '127.0.0.1',
358 'rc_ip' => '127.0.0.1',
359 'rc_title' => $title,
361 'rc_timestamp' => $timestamp,
362 'rc_cur_time' => $timestamp,
372 'rc_log_type' => null,
373 'rc_log_action' => '',
375 'rc_source' => 'mw.edit'
379 private function getTestUser() {
380 $user = User
::newFromName( 'Mary' );
382 if ( !$user->getId() ) {
383 $user->addToDatabase();
389 private function getMessages() {
394 'enhancedrc-history' => 'history',
396 'blocklink' => 'block',
397 'history' => 'Page history',
398 'semicolon-separator' => '; ',
399 'pipe-separator' => ' | '
403 private function getContext() {
404 $title = Title
::newFromText( 'RecentChanges', NS_SPECIAL
);
406 $context = new RequestContext();
407 $context->setTitle( $title );
408 $context->setLanguage( Language
::factory( 'en' ) );
410 $user = $this->getTestUser();
411 $context->setUser( $user );