Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / changes / OldChangesListTest.php
blob51cfadcb6f6bff632bbf8d1c0a9481d9e097c24f
1 <?php
3 /**
4 * @covers OldChangesList
6 * @todo add tests to cover article link, timestamp, character difference,
7 * log entry, user tool links, direction marks, tags, rollback,
8 * watching users, and date header.
10 * @group Database
12 * @author Katie Filbert < aude.wiki@gmail.com >
14 class OldChangesListTest extends MediaWikiLangTestCase {
16 /**
17 * @var TestRecentChangesHelper
19 private $testRecentChangesHelper;
21 public function __construct( $name = null, array $data = [], $dataName = '' ) {
22 parent::__construct( $name, $data, $dataName );
24 $this->testRecentChangesHelper = new TestRecentChangesHelper();
27 protected function setUp() {
28 parent::setUp();
30 $this->setMwGlobals( [
31 'wgArticlePath' => '/wiki/$1',
32 ] );
33 $this->setUserLang( 'qqx' );
36 /**
37 * @dataProvider recentChangesLine_CssForLineNumberProvider
39 public function testRecentChangesLine_CssForLineNumber( $expected, $linenumber, $message ) {
40 $oldChangesList = $this->getOldChangesList();
41 $recentChange = $this->getEditChange();
43 $line = $oldChangesList->recentChangesLine( $recentChange, false, $linenumber );
45 $this->assertRegExp( $expected, $line, $message );
48 public function recentChangesLine_CssForLineNumberProvider() {
49 return [
50 [ '/mw-line-odd/', 1, 'odd line number' ],
51 [ '/mw-line-even/', 2, 'even line number' ]
55 public function testRecentChangesLine_NotWatchedCssClass() {
56 $oldChangesList = $this->getOldChangesList();
57 $recentChange = $this->getEditChange();
59 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
61 $this->assertRegExp( '/mw-changeslist-line-not-watched/', $line );
64 public function testRecentChangesLine_WatchedCssClass() {
65 $oldChangesList = $this->getOldChangesList();
66 $recentChange = $this->getEditChange();
68 $line = $oldChangesList->recentChangesLine( $recentChange, true, 1 );
70 $this->assertRegExp( '/mw-changeslist-line-watched/', $line );
73 public function testRecentChangesLine_LogTitle() {
74 $oldChangesList = $this->getOldChangesList();
75 $recentChange = $this->getLogChange( 'delete', 'delete' );
77 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
79 $this->assertRegExp( '/href="\/wiki\/Special:Log\/delete/', $line, 'link has href attribute' );
80 $this->assertRegExp( '/title="Special:Log\/delete/', $line, 'link has title attribute' );
81 $this->assertRegExp( "/dellogpage/", $line, 'link text' );
84 public function testRecentChangesLine_DiffHistLinks() {
85 $oldChangesList = $this->getOldChangesList();
86 $recentChange = $this->getEditChange();
88 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
90 $this->assertRegExp(
91 '/title=Cat&amp;curid=20131103212153&amp;diff=5&amp;oldid=191/',
92 $line,
93 'assert diff link'
96 $this->assertRegExp(
97 '/title=Cat&amp;curid=20131103212153&amp;action=history"/',
98 $line,
99 'assert history link'
103 public function testRecentChangesLine_Flags() {
104 $oldChangesList = $this->getOldChangesList();
105 $recentChange = $this->getNewBotEditChange();
107 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
109 $this->assertContains(
110 '<abbr class="newpage" title="(recentchanges-label-newpage)">(newpageletter)</abbr>',
111 $line,
112 'new page flag'
115 $this->assertContains(
116 '<abbr class="botedit" title="(recentchanges-label-bot)">(boteditletter)</abbr>',
117 $line,
118 'bot flag'
122 public function testRecentChangesLine_Tags() {
123 $recentChange = $this->getEditChange();
124 $recentChange->mAttribs['ts_tags'] = 'vandalism,newbie';
126 $oldChangesList = $this->getOldChangesList();
127 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
129 $this->assertRegExp( '/<li class="[\w\s-]*mw-tag-vandalism[\w\s-]*">/', $line );
130 $this->assertRegExp( '/<li class="[\w\s-]*mw-tag-newbie[\w\s-]*">/', $line );
133 public function testRecentChangesLine_numberOfWatchingUsers() {
134 $oldChangesList = $this->getOldChangesList();
136 $recentChange = $this->getEditChange();
137 $recentChange->numberofWatchingusers = 100;
139 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
140 $this->assertRegExp( "/(number_of_watching_users_RCview: 100)/", $line );
143 public function testRecentChangesLine_watchlistCssClass() {
144 $oldChangesList = $this->getOldChangesList();
145 $oldChangesList->setWatchlistDivs( true );
147 $recentChange = $this->getEditChange();
148 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
149 $this->assertRegExp( "/watchlist-0-Cat/", $line );
152 private function getNewBotEditChange() {
153 $user = $this->getMutableTestUser()->getUser();
155 $recentChange = $this->testRecentChangesHelper->makeNewBotEditRecentChange(
156 $user, 'Abc', '20131103212153', 5, 191, 190, 0, 0
159 return $recentChange;
162 private function getLogChange( $logType, $logAction ) {
163 $user = $this->getMutableTestUser()->getUser();
165 $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
166 $logType, $logAction, $user, 'Abc', '20131103212153', 0, 0
169 return $recentChange;
172 private function getEditChange() {
173 $user = $this->getMutableTestUser()->getUser();
174 $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
175 $user, 'Cat', '20131103212153', 5, 191, 190, 0, 0
178 return $recentChange;
181 private function getOldChangesList() {
182 $context = $this->getContext();
183 return new OldChangesList( $context );
186 private function getContext() {
187 $user = $this->getMutableTestUser()->getUser();
188 $context = $this->testRecentChangesHelper->getTestContext( $user );
189 $context->setLanguage( 'qqx' );
191 return $context;