Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / changes / RCCacheEntryFactoryTest.php
blob4ff1eb8e768f98ca7e133d46307c683c6b06381d
1 <?php
3 use MediaWiki\Linker\LinkRenderer;
4 use MediaWiki\MediaWikiServices;
6 /**
7 * @covers RCCacheEntryFactory
9 * @group Database
11 * @author Katie Filbert < aude.wiki@gmail.com >
13 class RCCacheEntryFactoryTest extends MediaWikiLangTestCase {
15 /**
16 * @var TestRecentChangesHelper
18 private $testRecentChangesHelper;
20 /**
21 * @var LinkRenderer;
23 private $linkRenderer;
25 public function __construct( $name = null, array $data = [], $dataName = '' ) {
26 parent::__construct( $name, $data, $dataName );
28 $this->testRecentChangesHelper = new TestRecentChangesHelper();
31 protected function setUp() {
32 parent::setUp();
34 $this->setMwGlobals( [
35 'wgArticlePath' => '/wiki/$1'
36 ] );
38 $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
41 public function testNewFromRecentChange() {
42 $user = $this->getMutableTestUser()->getUser();
43 $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
44 $user,
45 'Xyz',
46 5, // curid
47 191, // thisid
48 190, // lastid
49 '20131103212153',
50 0, // counter
51 0 // number of watching users
53 $cacheEntryFactory = new RCCacheEntryFactory(
54 $this->getContext(),
55 $this->getMessages(),
56 $this->linkRenderer
58 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
60 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
62 $this->assertEquals( false, $cacheEntry->watched, 'watched' );
63 $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
64 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
65 $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
67 $this->assertUserLinks( $user->getName(), $cacheEntry );
68 $this->assertTitleLink( 'Xyz', $cacheEntry );
70 $diff = [ 'curid' => 5, 'diff' => 191, 'oldid' => 190 ];
71 $cur = [ 'curid' => 5, 'diff' => 0, 'oldid' => 191 ];
72 $this->assertQueryLink( 'cur', $cur, $cacheEntry->curlink );
73 $this->assertQueryLink( 'prev', $diff, $cacheEntry->lastlink );
74 $this->assertQueryLink( 'diff', $diff, $cacheEntry->difflink );
77 public function testNewForDeleteChange() {
78 $user = $this->getMutableTestUser()->getUser();
79 $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
80 'delete',
81 'delete',
82 $user,
83 'Abc',
84 '20131103212153',
85 0, // counter
86 0 // number of watching users
88 $cacheEntryFactory = new RCCacheEntryFactory(
89 $this->getContext(),
90 $this->getMessages(),
91 $this->linkRenderer
93 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
95 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
97 $this->assertEquals( false, $cacheEntry->watched, 'watched' );
98 $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
99 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
100 $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
102 $this->assertDeleteLogLink( $cacheEntry );
103 $this->assertUserLinks( $user->getName(), $cacheEntry );
105 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
106 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
107 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
110 public function testNewForRevUserDeleteChange() {
111 $user = $this->getMutableTestUser()->getUser();
112 $recentChange = $this->testRecentChangesHelper->makeDeletedEditRecentChange(
113 $user,
114 'Zzz',
115 '20131103212153',
116 191, // thisid
117 190, // lastid
118 '20131103212153',
119 0, // counter
120 0 // number of watching users
122 $cacheEntryFactory = new RCCacheEntryFactory(
123 $this->getContext(),
124 $this->getMessages(),
125 $this->linkRenderer
127 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
129 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
131 $this->assertEquals( false, $cacheEntry->watched, 'watched' );
132 $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
133 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
134 $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
136 $this->assertRevDel( $cacheEntry );
137 $this->assertTitleLink( 'Zzz', $cacheEntry );
139 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
140 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
141 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
144 private function assertUserLinks( $user, $cacheEntry ) {
145 $this->assertTag(
147 'tag' => 'a',
148 'attributes' => [
149 'class' => 'new mw-userlink'
151 'content' => $user
153 $cacheEntry->userlink,
154 'verify user link'
157 $this->assertTag(
159 'tag' => 'span',
160 'attributes' => [
161 'class' => 'mw-usertoollinks'
163 'child' => [
164 'tag' => 'a',
165 'content' => 'talk',
168 $cacheEntry->usertalklink,
169 'verify user talk link'
172 $this->assertTag(
174 'tag' => 'span',
175 'attributes' => [
176 'class' => 'mw-usertoollinks'
178 'child' => [
179 'tag' => 'a',
180 'content' => 'contribs',
183 $cacheEntry->usertalklink,
184 'verify user tool links'
188 private function assertDeleteLogLink( $cacheEntry ) {
189 $this->assertTag(
191 'tag' => 'a',
192 'attributes' => [
193 'href' => '/wiki/Special:Log/delete',
194 'title' => 'Special:Log/delete'
196 'content' => 'Deletion log'
198 $cacheEntry->link,
199 'verify deletion log link'
203 private function assertRevDel( $cacheEntry ) {
204 $this->assertTag(
206 'tag' => 'span',
207 'attributes' => [
208 'class' => 'history-deleted'
210 'content' => '(username removed)'
212 $cacheEntry->userlink,
213 'verify user link for change with deleted revision and user'
217 private function assertTitleLink( $title, $cacheEntry ) {
218 $this->assertTag(
220 'tag' => 'a',
221 'attributes' => [
222 'href' => '/wiki/' . $title,
223 'title' => $title
225 'content' => $title
227 $cacheEntry->link,
228 'verify title link'
232 private function assertQueryLink( $content, $params, $link ) {
233 $this->assertTag(
235 'tag' => 'a',
236 'content' => $content
238 $link,
239 'assert query link element'
242 foreach ( $params as $key => $value ) {
243 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
247 private function getMessages() {
248 return [
249 'cur' => 'cur',
250 'diff' => 'diff',
251 'hist' => 'hist',
252 'enhancedrc-history' => 'history',
253 'last' => 'prev',
254 'blocklink' => 'block',
255 'history' => 'Page history',
256 'semicolon-separator' => '; ',
257 'pipe-separator' => ' | '
261 private function getContext() {
262 $user = $this->getMutableTestUser()->getUser();
263 $context = $this->testRecentChangesHelper->getTestContext( $user );
265 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
266 $context->setTitle( $title );
268 return $context;