Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / changes / EnhancedChangesListTest.php
blob308e6de11e8f5c55e5118da630dcd940b897b5d0
1 <?php
3 /**
4 * @covers EnhancedChangesList
6 * @group Database
8 * @author Katie Filbert < aude.wiki@gmail.com >
9 */
10 class EnhancedChangesListTest extends MediaWikiLangTestCase {
12 /**
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',
31 $styleModules,
32 'has mediawiki.special.changeslist'
35 $this->assertContains(
36 'mediawiki.special.changeslist.enhanced',
37 $styleModules,
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 );
59 /**
60 * @todo more tests
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 testCategorizationLineFormatting() {
78 $html = $this->createCategorizationLine(
79 $this->getCategorizationChange( '20150629191735', 0, 0 )
81 $this->assertNotContains( '(diff | hist)', strip_tags( $html ) );
84 public function testCategorizationLineFormattingWithRevision() {
85 $html = $this->createCategorizationLine(
86 $this->getCategorizationChange( '20150629191735', 1025, 1024 )
88 $this->assertContains( '(diff | hist)', strip_tags( $html ) );
91 /**
92 * @todo more tests for actual formatting, this is more of a smoke test
94 public function testEndRecentChangesList() {
95 $enhancedChangesList = $this->newEnhancedChangesList();
96 $enhancedChangesList->beginRecentChangesList();
98 $recentChange = $this->getEditChange( '20131103092153' );
99 $enhancedChangesList->recentChangesLine( $recentChange, false );
101 $recentChange2 = $this->getEditChange( '20131103092253' );
102 $enhancedChangesList->recentChangesLine( $recentChange2, false );
104 $html = $enhancedChangesList->endRecentChangesList();
106 preg_match_all( '/td class="mw-enhanced-rc-nested"/', $html, $matches );
107 $this->assertCount( 2, $matches[0] );
111 * @return EnhancedChangesList
113 private function newEnhancedChangesList() {
114 $user = User::newFromId( 0 );
115 $context = $this->testRecentChangesHelper->getTestContext( $user );
117 return new EnhancedChangesList( $context );
121 * @return RecentChange
123 private function getEditChange( $timestamp ) {
124 $user = $this->getMutableTestUser()->getUser();
125 $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
126 $user, 'Cat', $timestamp, 5, 191, 190, 0, 0
129 return $recentChange;
133 * @return RecentChange
135 private function getCategorizationChange( $timestamp, $thisId, $lastId ) {
136 $wikiPage = new WikiPage( Title::newFromText( 'Testpage' ) );
137 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'page created' );
139 $wikiPage = new WikiPage( Title::newFromText( 'Category:Foo' ) );
140 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'category page created' );
142 $user = $this->getMutableTestUser()->getUser();
143 $recentChange = $this->testRecentChangesHelper->makeCategorizationRecentChange(
144 $user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp
147 return $recentChange;
150 private function createCategorizationLine( $recentChange ) {
151 $enhancedChangesList = $this->newEnhancedChangesList();
152 $cacheEntry = $this->testRecentChangesHelper->getCacheEntry( $recentChange );
154 $reflection = new \ReflectionClass( get_class( $enhancedChangesList ) );
155 $method = $reflection->getMethod( 'recentChangesBlockLine' );
156 $method->setAccessible( true );
158 return $method->invokeArgs( $enhancedChangesList, [ $cacheEntry ] );