3 use MediaWiki\Linker\LinkRenderer
;
4 use MediaWiki\MediaWikiServices
;
7 * @covers RCCacheEntryFactory
11 * @author Katie Filbert < aude.wiki@gmail.com >
13 class RCCacheEntryFactoryTest
extends MediaWikiLangTestCase
{
16 * @var TestRecentChangesHelper
18 private $testRecentChangesHelper;
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() {
34 $this->setMwGlobals( [
35 'wgArticlePath' => '/wiki/$1'
38 $this->linkRenderer
= MediaWikiServices
::getInstance()->getLinkRenderer();
41 public function testNewFromRecentChange() {
42 $user = $this->getMutableTestUser()->getUser();
43 $recentChange = $this->testRecentChangesHelper
->makeEditRecentChange(
51 0 // number of watching users
53 $cacheEntryFactory = new RCCacheEntryFactory(
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
, 'cur link' );
73 $this->assertQueryLink( 'prev', $diff, $cacheEntry->lastlink
, 'prev link' );
74 $this->assertQueryLink( 'diff', $diff, $cacheEntry->difflink
, 'diff link' );
77 public function testNewForDeleteChange() {
80 'user' => 'TestRecentChangesUser',
81 'timestamp' => '21:21',
82 'numberofWatchingusers' => 0,
83 'unpatrolled' => false
85 $user = $this->getMutableTestUser()->getUser();
86 $recentChange = $this->testRecentChangesHelper
->makeLogRecentChange(
93 0 // number of watching users
95 $cacheEntryFactory = new RCCacheEntryFactory(
100 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
102 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
104 $this->assertEquals( false, $cacheEntry->watched
, 'watched' );
105 $this->assertEquals( '21:21', $cacheEntry->timestamp
, 'timestamp' );
106 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers
, 'watching users' );
107 $this->assertEquals( false, $cacheEntry->unpatrolled
, 'unpatrolled' );
109 $this->assertDeleteLogLink( $cacheEntry );
110 $this->assertUserLinks( $user->getName(), $cacheEntry );
112 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
113 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
114 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
117 public function testNewForRevUserDeleteChange() {
118 $user = $this->getMutableTestUser()->getUser();
119 $recentChange = $this->testRecentChangesHelper
->makeDeletedEditRecentChange(
127 0 // number of watching users
129 $cacheEntryFactory = new RCCacheEntryFactory(
131 $this->getMessages(),
134 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
136 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
138 $this->assertEquals( false, $cacheEntry->watched
, 'watched' );
139 $this->assertEquals( '21:21', $cacheEntry->timestamp
, 'timestamp' );
140 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers
, 'watching users' );
141 $this->assertEquals( false, $cacheEntry->unpatrolled
, 'unpatrolled' );
143 $this->assertRevDel( $cacheEntry );
144 $this->assertTitleLink( 'Zzz', $cacheEntry );
146 $this->assertEquals( 'cur', $cacheEntry->curlink
, 'cur link for delete log or rev' );
147 $this->assertEquals( 'diff', $cacheEntry->difflink
, 'diff link for delete log or rev' );
148 $this->assertEquals( 'prev', $cacheEntry->lastlink
, 'pref link for delete log or rev' );
151 private function assertUserLinks( $user, $cacheEntry ) {
156 'class' => 'new mw-userlink'
160 $cacheEntry->userlink
,
168 'class' => 'mw-usertoollinks'
175 $cacheEntry->usertalklink
,
176 'verify user talk link'
183 'class' => 'mw-usertoollinks'
187 'content' => 'contribs',
190 $cacheEntry->usertalklink
,
191 'verify user tool links'
195 private function assertDeleteLogLink( $cacheEntry ) {
200 'href' => '/wiki/Special:Log/delete',
201 'title' => 'Special:Log/delete'
203 'content' => 'Deletion log'
206 'verify deletion log link'
210 private function assertRevDel( $cacheEntry ) {
215 'class' => 'history-deleted'
217 'content' => '(username removed)'
219 $cacheEntry->userlink
,
220 'verify user link for change with deleted revision and user'
224 private function assertTitleLink( $title, $cacheEntry ) {
229 'href' => '/wiki/' . $title,
239 private function assertQueryLink( $content, $params, $link ) {
243 'content' => $content
246 'assert query link element'
249 foreach ( $params as $key => $value ) {
250 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
254 private function getMessages() {
259 'enhancedrc-history' => 'history',
261 'blocklink' => 'block',
262 'history' => 'Page history',
263 'semicolon-separator' => '; ',
264 'pipe-separator' => ' | '
268 private function getContext() {
269 $user = $this->getMutableTestUser()->getUser();
270 $context = $this->testRecentChangesHelper
->getTestContext( $user );
272 $title = Title
::newFromText( 'RecentChanges', NS_SPECIAL
);
273 $context->setTitle( $title );