4 * @covers RCCacheEntryFactory
8 * @author Katie Filbert < aude.wiki@gmail.com >
10 class RCCacheEntryFactoryTest
extends MediaWikiLangTestCase
{
13 * @var TestRecentChangesHelper
15 private $testRecentChangesHelper;
17 public function __construct( $name = null, array $data = array(), $dataName = '' ) {
18 parent
::__construct( $name, $data, $dataName );
20 $this->testRecentChangesHelper
= new TestRecentChangesHelper();
23 protected function setUp() {
26 $this->setMwGlobals( array(
27 'wgArticlePath' => '/wiki/$1'
32 * @dataProvider editChangeProvider
34 public function testNewFromRecentChange( $expected, $context, $messages,
35 $recentChange, $watched
37 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
38 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
40 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
42 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
43 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
45 $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers
,
48 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
50 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
51 $this->assertTitleLink( 'Xyz', $cacheEntry );
53 $this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink
, 'cur link' );
54 $this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink
, 'prev link' );
55 $this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink
, 'diff link' );
58 public function editChangeProvider() {
63 'user' => 'TestRecentChangesUser',
64 'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
65 'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
66 'timestamp' => '21:21',
67 'numberofWatchingusers' => 0,
68 'unpatrolled' => false
72 $this->testRecentChangesHelper
->makeEditRecentChange(
80 0 // number of watching users
88 * @dataProvider deleteChangeProvider
90 public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
91 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
92 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
94 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
96 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
97 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
99 $expected['numberofWatchingusers'],
100 $cacheEntry->numberofWatchingusers
, 'watching users'
102 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
104 $this->assertDeleteLogLink( $cacheEntry );
105 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
107 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
108 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
109 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
112 public function deleteChangeProvider() {
117 'user' => 'TestRecentChangesUser',
118 'timestamp' => '21:21',
119 'numberofWatchingusers' => 0,
120 'unpatrolled' => false
123 $this->getMessages(),
124 $this->testRecentChangesHelper
->makeLogRecentChange(
127 $this->getTestUser(),
131 0 // number of watching users
139 * @dataProvider revUserDeleteProvider
141 public function testNewForRevUserDeleteChange( $expected, $context, $messages,
142 $recentChange, $watched
144 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
145 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
147 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
149 $this->assertEquals( $watched, $cacheEntry->watched
, 'watched' );
150 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp
, 'timestamp' );
152 $expected['numberofWatchingusers'],
153 $cacheEntry->numberofWatchingusers
, 'watching users'
155 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled
, 'unpatrolled' );
157 $this->assertRevDel( $cacheEntry );
158 $this->assertTitleLink( 'Zzz', $cacheEntry );
160 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
161 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
162 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
165 public function revUserDeleteProvider() {
170 'user' => 'TestRecentChangesUser',
173 'timestamp' => '21:21',
174 'numberofWatchingusers' => 0,
175 'unpatrolled' => false
178 $this->getMessages(),
179 $this->testRecentChangesHelper
->makeDeletedEditRecentChange(
180 $this->getTestUser(),
187 0 // number of watching users
194 private function assertUserLinks( $user, $cacheEntry ) {
198 'attributes' => array(
199 'class' => 'new mw-userlink'
203 $cacheEntry->userlink
,
210 'attributes' => array(
211 'class' => 'mw-usertoollinks'
218 $cacheEntry->usertalklink
,
219 'verify user talk link'
225 'attributes' => array(
226 'class' => 'mw-usertoollinks'
230 'content' => 'contribs',
233 $cacheEntry->usertalklink
,
234 'verify user tool links'
238 private function assertDeleteLogLink( $cacheEntry ) {
242 'attributes' => array(
243 'href' => '/wiki/Special:Log/delete',
244 'title' => 'Special:Log/delete'
246 'content' => 'Deletion log'
249 'verify deletion log link'
253 private function assertRevDel( $cacheEntry ) {
257 'attributes' => array(
258 'class' => 'history-deleted'
260 'content' => '(username removed)'
262 $cacheEntry->userlink
,
263 'verify user link for change with deleted revision and user'
267 private function assertTitleLink( $title, $cacheEntry ) {
271 'attributes' => array(
272 'href' => '/wiki/' . $title,
282 private function assertQueryLink( $content, $params, $link ) {
286 'content' => $content
289 'assert query link element'
292 foreach ( $params as $key => $value ) {
293 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
297 private function getMessages() {
302 'enhancedrc-history' => 'history',
304 'blocklink' => 'block',
305 'history' => 'Page history',
306 'semicolon-separator' => '; ',
307 'pipe-separator' => ' | '
311 private function getTestUser() {
312 $user = User
::newFromName( 'TestRecentChangesUser' );
314 if ( !$user->getId() ) {
315 $user->addToDatabase();
321 private function getContext() {
322 $user = $this->getTestUser();
323 $context = $this->testRecentChangesHelper
->getTestContext( $user );
325 $title = Title
::newFromText( 'RecentChanges', NS_SPECIAL
);
326 $context->setTitle( $title );