4 * @covers RCCacheEntryFactory
9 * @author Katie Filbert < aude.wiki@gmail.com >
11 class RCCacheEntryFactoryTest
extends MediaWikiLangTestCase
{
14 * @var TestRecentChangesHelper
16 private $testRecentChangesHelper;
18 public function __construct( $name = null, array $data = array(), $dataName = '' ) {
19 parent
::__construct( $name, $data, $dataName );
21 $this->testRecentChangesHelper
= new TestRecentChangesHelper();
24 protected function setUp() {
27 $this->setMwGlobals( array(
28 'wgArticlePath' => '/wiki/$1'
33 * @dataProvider editChangeProvider
35 public function testNewFromRecentChange( $expected, $context, $messages,
36 $recentChange, $watched
38 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
39 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
41 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
43 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
44 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
46 $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers
,
49 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
51 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
52 $this->assertTitleLink( 'Xyz', $cacheEntry );
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' );
59 public function editChangeProvider() {
64 'user' => 'TestRecentChangesUser',
65 'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
66 'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
67 'timestamp' => '21:21',
68 'numberofWatchingusers' => 0,
69 'unpatrolled' => false
73 $this->testRecentChangesHelper
->makeEditRecentChange(
81 0 // number of watching users
89 * @dataProvider deleteChangeProvider
91 public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
92 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
93 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
95 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
97 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
98 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
100 $expected['numberofWatchingusers'],
101 $cacheEntry->numberofWatchingusers
, 'watching users'
103 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
105 $this->assertDeleteLogLink( $cacheEntry );
106 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
108 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
109 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
110 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
113 public function deleteChangeProvider() {
118 'user' => 'TestRecentChangesUser',
119 'timestamp' => '21:21',
120 'numberofWatchingusers' => 0,
121 'unpatrolled' => false
124 $this->getMessages(),
125 $this->testRecentChangesHelper
->makeLogRecentChange(
128 $this->getTestUser(),
132 0 // number of watching users
140 * @dataProvider revUserDeleteProvider
142 public function testNewForRevUserDeleteChange( $expected, $context, $messages,
143 $recentChange, $watched
145 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
146 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
148 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
150 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
151 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
153 $expected['numberofWatchingusers'],
154 $cacheEntry->numberofWatchingusers
, 'watching users'
156 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
158 $this->assertRevDel( $cacheEntry );
159 $this->assertTitleLink( 'Zzz', $cacheEntry );
161 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
162 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
163 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
166 public function revUserDeleteProvider() {
171 'user' => 'TestRecentChangesUser',
174 'timestamp' => '21:21',
175 'numberofWatchingusers' => 0,
176 'unpatrolled' => false
179 $this->getMessages(),
180 $this->testRecentChangesHelper
->makeDeletedEditRecentChange(
181 $this->getTestUser(),
188 0 // number of watching users
195 private function assertUserLinks( $user, $cacheEntry ) {
199 'attributes' => array(
200 'class' => 'new mw-userlink'
204 $cacheEntry->userlink
,
211 'attributes' => array(
212 'class' => 'mw-usertoollinks'
219 $cacheEntry->usertalklink
,
220 'verify user talk link'
226 'attributes' => array(
227 'class' => 'mw-usertoollinks'
231 'content' => 'contribs',
234 $cacheEntry->usertalklink
,
235 'verify user tool links'
239 private function assertDeleteLogLink( $cacheEntry ) {
243 'attributes' => array(
244 'href' => '/wiki/Special:Log/delete',
245 'title' => 'Special:Log/delete'
247 'content' => 'Deletion log'
250 'verify deletion log link'
254 private function assertRevDel( $cacheEntry ) {
258 'attributes' => array(
259 'class' => 'history-deleted'
261 'content' => '(username removed)'
263 $cacheEntry->userlink
,
264 'verify user link for change with deleted revision and user'
268 private function assertTitleLink( $title, $cacheEntry ) {
272 'attributes' => array(
273 'href' => '/wiki/' . $title,
283 private function assertQueryLink( $content, $params, $link ) {
287 'content' => $content
290 'assert query link element'
293 foreach ( $params as $key => $value ) {
294 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
298 private function getMessages() {
303 'enhancedrc-history' => 'history',
305 'blocklink' => 'block',
306 'history' => 'Page history',
307 'semicolon-separator' => '; ',
308 'pipe-separator' => ' | '
312 private function getTestUser() {
313 $user = User
::newFromName( 'TestRecentChangesUser' );
315 if ( !$user->getId() ) {
316 $user->addToDatabase();
322 private function getContext() {
323 $user = $this->getTestUser();
324 $context = $this->testRecentChangesHelper
->getTestContext( $user );
326 $title = Title
::newFromText( 'RecentChanges', NS_SPECIAL
);
327 $context->setTitle( $title );