Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / changes / RCCacheEntryFactoryTest.php
blob552dacb7b9f6edbc9e55519bd87baf800174ded7
1 <?php
3 /**
4 * @covers RCCacheEntryFactory
6 * @group Database
8 * @author Katie Filbert < aude.wiki@gmail.com >
9 */
10 class RCCacheEntryFactoryTest extends MediaWikiLangTestCase {
12 /**
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() {
24 parent::setUp();
26 $this->setMwGlobals( array(
27 'wgArticlePath' => '/wiki/$1'
28 ) );
31 /**
32 * @dataProvider editChangeProvider
34 public function testNewFromRecentChange( $expected, $context, $messages,
35 $recentChange, $watched
36 ) {
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' );
44 $this->assertEquals(
45 $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers,
46 'watching users'
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() {
59 return array(
60 array(
61 array(
62 'title' => 'Xyz',
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
70 $this->getContext(),
71 $this->getMessages(),
72 $this->testRecentChangesHelper->makeEditRecentChange(
73 $this->getTestUser(),
74 'Xyz',
75 5, // curid
76 191, // thisid
77 190, // lastid
78 '20131103212153',
79 0, // counter
80 0 // number of watching users
82 false
87 /**
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' );
98 $this->assertEquals(
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() {
113 return array(
114 array(
115 array(
116 'title' => 'Abc',
117 'user' => 'TestRecentChangesUser',
118 'timestamp' => '21:21',
119 'numberofWatchingusers' => 0,
120 'unpatrolled' => false
122 $this->getContext(),
123 $this->getMessages(),
124 $this->testRecentChangesHelper->makeLogRecentChange(
125 'delete',
126 'delete',
127 $this->getTestUser(),
128 'Abc',
129 '20131103212153',
130 0, // counter
131 0 // number of watching users
133 false
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' );
151 $this->assertEquals(
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() {
166 return array(
167 array(
168 array(
169 'title' => 'Zzz',
170 'user' => 'TestRecentChangesUser',
171 'diff' => '',
172 'cur' => '',
173 'timestamp' => '21:21',
174 'numberofWatchingusers' => 0,
175 'unpatrolled' => false
177 $this->getContext(),
178 $this->getMessages(),
179 $this->testRecentChangesHelper->makeDeletedEditRecentChange(
180 $this->getTestUser(),
181 'Zzz',
182 '20131103212153',
183 191, // thisid
184 190, // lastid
185 '20131103212153',
186 0, // counter
187 0 // number of watching users
189 false
194 private function assertUserLinks( $user, $cacheEntry ) {
195 $this->assertTag(
196 array(
197 'tag' => 'a',
198 'attributes' => array(
199 'class' => 'new mw-userlink'
201 'content' => $user
203 $cacheEntry->userlink,
204 'verify user link'
207 $this->assertTag(
208 array(
209 'tag' => 'span',
210 'attributes' => array(
211 'class' => 'mw-usertoollinks'
213 'child' => array(
214 'tag' => 'a',
215 'content' => 'talk',
218 $cacheEntry->usertalklink,
219 'verify user talk link'
222 $this->assertTag(
223 array(
224 'tag' => 'span',
225 'attributes' => array(
226 'class' => 'mw-usertoollinks'
228 'child' => array(
229 'tag' => 'a',
230 'content' => 'contribs',
233 $cacheEntry->usertalklink,
234 'verify user tool links'
238 private function assertDeleteLogLink( $cacheEntry ) {
239 $this->assertTag(
240 array(
241 'tag' => 'a',
242 'attributes' => array(
243 'href' => '/wiki/Special:Log/delete',
244 'title' => 'Special:Log/delete'
246 'content' => 'Deletion log'
248 $cacheEntry->link,
249 'verify deletion log link'
253 private function assertRevDel( $cacheEntry ) {
254 $this->assertTag(
255 array(
256 'tag' => 'span',
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 ) {
268 $this->assertTag(
269 array(
270 'tag' => 'a',
271 'attributes' => array(
272 'href' => '/wiki/' . $title,
273 'title' => $title
275 'content' => $title
277 $cacheEntry->link,
278 'verify title link'
282 private function assertQueryLink( $content, $params, $link ) {
283 $this->assertTag(
284 array(
285 'tag' => 'a',
286 'content' => $content
288 $link,
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() {
298 return array(
299 'cur' => 'cur',
300 'diff' => 'diff',
301 'hist' => 'hist',
302 'enhancedrc-history' => 'history',
303 'last' => 'prev',
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();
318 return $user;
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 );
328 return $context;