4 * @covers EnhancedChangesList
8 * @author Katie Filbert < aude.wiki@gmail.com >
10 class EnhancedChangesListTest
extends MediaWikiLangTestCase
{
13 * @var TestRecentChangesHelper
15 private $testRecentChangesHelper;
17 public function __construct( $name = null, array $data = [], $dataName = '' ) {
18 parent
::__construct( $name, $data, $dataName );
20 $this->testRecentChangesHelper
= new TestRecentChangesHelper();
23 public function testBeginRecentChangesList_styleModules() {
24 $enhancedChangesList = $this->newEnhancedChangesList();
25 $enhancedChangesList->beginRecentChangesList();
27 $styleModules = $enhancedChangesList->getOutput()->getModuleStyles();
29 $this->assertContains(
30 'mediawiki.special.changeslist',
32 'has mediawiki.special.changeslist'
35 $this->assertContains(
36 'mediawiki.special.changeslist.enhanced',
38 'has mediawiki.special.changeslist.enhanced'
42 public function testBeginRecentChangesList_jsModules() {
43 $enhancedChangesList = $this->newEnhancedChangesList();
44 $enhancedChangesList->beginRecentChangesList();
46 $modules = $enhancedChangesList->getOutput()->getModules();
48 $this->assertContains( 'jquery.makeCollapsible', $modules, 'has jquery.makeCollapsible' );
49 $this->assertContains( 'mediawiki.icon', $modules, 'has mediawiki.icon' );
52 public function testBeginRecentChangesList_html() {
53 $enhancedChangesList = $this->newEnhancedChangesList();
54 $html = $enhancedChangesList->beginRecentChangesList();
56 $this->assertEquals( '<div class="mw-changeslist">', $html );
62 public function testRecentChangesLine() {
63 $enhancedChangesList = $this->newEnhancedChangesList();
64 $enhancedChangesList->beginRecentChangesList();
66 $recentChange = $this->getEditChange( '20131103092153' );
67 $html = $enhancedChangesList->recentChangesLine( $recentChange, false );
69 $this->assertInternalType( 'string', $html );
71 $recentChange2 = $this->getEditChange( '20131103092253' );
72 $html = $enhancedChangesList->recentChangesLine( $recentChange2, false );
74 $this->assertEquals( '', $html );
77 public function testRecentChangesPrefix() {
78 $mockContext = $this->getMockBuilder( RequestContext
::class )
79 ->setMethods( [ 'getTitle' ] )
81 $mockContext->method( 'getTitle' )
82 ->will( $this->returnValue( Title
::newFromText( 'Expected Context Title' ) ) );
84 // One group of two lines
85 $enhancedChangesList = $this->newEnhancedChangesList();
86 $enhancedChangesList->setContext( $mockContext );
87 $enhancedChangesList->setChangeLinePrefixer( function ( $rc, $changesList ) {
88 // Make sure RecentChange and ChangesList objects are the same
89 $this->assertEquals( 'Expected Context Title', $changesList->getContext()->getTitle() );
90 $this->assertTrue( $rc->getTitle() == 'Cat' ||
$rc->getTitle() == 'Dog' );
91 return 'Hello world prefix';
93 $enhancedChangesList->beginRecentChangesList();
95 $recentChange = $this->getEditChange( '20131103092153' );
96 $enhancedChangesList->recentChangesLine( $recentChange );
97 $recentChange = $this->getEditChange( '20131103092154' );
98 $enhancedChangesList->recentChangesLine( $recentChange );
100 $html = $enhancedChangesList->endRecentChangesList();
102 $this->assertRegExp( '/Hello world prefix/', $html );
104 // Two separate lines
105 $enhancedChangesList->beginRecentChangesList();
107 $recentChange = $this->getEditChange( '20131103092153' );
108 $enhancedChangesList->recentChangesLine( $recentChange );
109 $recentChange = $this->getEditChange( '20131103092154', 'Dog' );
110 $enhancedChangesList->recentChangesLine( $recentChange );
112 $html = $enhancedChangesList->endRecentChangesList();
114 preg_match_all( '/Hello world prefix/', $html, $matches );
115 $this->assertCount( 2, $matches[0] );
118 public function testCategorizationLineFormatting() {
119 $html = $this->createCategorizationLine(
120 $this->getCategorizationChange( '20150629191735', 0, 0 )
122 $this->assertNotContains( '(diff | hist)', strip_tags( $html ) );
125 public function testCategorizationLineFormattingWithRevision() {
126 $html = $this->createCategorizationLine(
127 $this->getCategorizationChange( '20150629191735', 1025, 1024 )
129 $this->assertContains( '(diff | hist)', strip_tags( $html ) );
133 * @todo more tests for actual formatting, this is more of a smoke test
135 public function testEndRecentChangesList() {
136 $enhancedChangesList = $this->newEnhancedChangesList();
137 $enhancedChangesList->beginRecentChangesList();
139 $recentChange = $this->getEditChange( '20131103092153' );
140 $enhancedChangesList->recentChangesLine( $recentChange, false );
142 $html = $enhancedChangesList->endRecentChangesList();
144 '/data-mw-revid="5" data-mw-ts="20131103092153" class="[^"]*mw-enhanced-rc[^"]*"/',
148 $recentChange2 = $this->getEditChange( '20131103092253' );
149 $enhancedChangesList->recentChangesLine( $recentChange2, false );
151 $html = $enhancedChangesList->endRecentChangesList();
153 preg_match_all( '/td class="mw-enhanced-rc-nested"/', $html, $matches );
154 $this->assertCount( 2, $matches[0] );
156 preg_match_all( '/data-target-page="Cat"/', $html, $matches );
157 $this->assertCount( 2, $matches[0] );
159 $recentChange3 = $this->getLogChange();
160 $enhancedChangesList->recentChangesLine( $recentChange3, false );
162 $html = $enhancedChangesList->endRecentChangesList();
163 $this->assertContains( 'data-mw-logaction="foo/bar"', $html );
164 $this->assertContains( 'data-mw-logid="25"', $html );
165 $this->assertContains( 'data-target-page="Title"', $html );
169 * @return EnhancedChangesList
171 private function newEnhancedChangesList() {
172 $user = User
::newFromId( 0 );
173 $context = $this->testRecentChangesHelper
->getTestContext( $user );
175 return new EnhancedChangesList( $context );
179 * @return RecentChange
181 private function getEditChange( $timestamp, $pageTitle = 'Cat' ) {
182 $user = $this->getMutableTestUser()->getUser();
183 $recentChange = $this->testRecentChangesHelper
->makeEditRecentChange(
184 $user, $pageTitle, 0, 5, 191, $timestamp, 0, 0
187 return $recentChange;
190 private function getLogChange() {
191 $user = $this->getMutableTestUser()->getUser();
192 $recentChange = $this->testRecentChangesHelper
->makeLogRecentChange( 'foo', 'bar', $user,
193 'Title', '20131103092153', 0, 0
196 return $recentChange;
200 * @return RecentChange
202 private function getCategorizationChange( $timestamp, $thisId, $lastId ) {
203 $wikiPage = new WikiPage( Title
::newFromText( 'Testpage' ) );
204 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'page created' );
206 $wikiPage = new WikiPage( Title
::newFromText( 'Category:Foo' ) );
207 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'category page created' );
209 $user = $this->getMutableTestUser()->getUser();
210 $recentChange = $this->testRecentChangesHelper
->makeCategorizationRecentChange(
211 $user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp
214 return $recentChange;
217 private function createCategorizationLine( $recentChange ) {
218 $enhancedChangesList = $this->newEnhancedChangesList();
219 $cacheEntry = $this->testRecentChangesHelper
->getCacheEntry( $recentChange );
221 $reflection = new \
ReflectionClass( get_class( $enhancedChangesList ) );
222 $method = $reflection->getMethod( 'recentChangesBlockLine' );
223 $method->setAccessible( true );
225 return $method->invokeArgs( $enhancedChangesList, [ $cacheEntry ] );