Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / changes / OldChangesListTest.php
blobf158fc3edf90d8232d1cc1b28e2dee7a997e3bad
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 = array(), $dataName = '' ) {
22 parent::__construct( $name, $data, $dataName );
24 $this->testRecentChangesHelper = new TestRecentChangesHelper();
27 protected function setUp() {
28 parent::setUp();
30 $this->setMwGlobals( array(
31 'wgArticlePath' => '/wiki/$1',
32 'wgLang' => Language::factory( 'qqx' )
33 ) );
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 array(
50 array( '/mw-line-odd/', 1, 'odd line number' ),
51 array( '/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( '/tabindex="0"/', $line, 'assert tab index' );
97 $this->assertRegExp(
98 '/title=Cat&amp;curid=20131103212153&amp;action=history"/',
99 $line,
100 'assert history link'
104 public function testRecentChangesLine_Flags() {
105 $oldChangesList = $this->getOldChangesList();
106 $recentChange = $this->getNewBotEditChange();
108 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
110 $this->assertContains(
111 "<abbr class='newpage' title='(recentchanges-label-newpage)'>(newpageletter)</abbr>",
112 $line,
113 'new page flag'
116 $this->assertContains(
117 "<abbr class='botedit' title='(recentchanges-label-bot)'>(boteditletter)</abbr>",
118 $line,
119 'bot flag'
123 public function testRecentChangesLine_Tags() {
124 $recentChange = $this->getEditChange();
125 $recentChange->mAttribs['ts_tags'] = 'vandalism,newbie';
127 $oldChangesList = $this->getOldChangesList();
128 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
130 $this->assertRegExp( '/<li class="[\w\s-]*mw-tag-vandalism[\w\s-]*">/', $line );
131 $this->assertRegExp( '/<li class="[\w\s-]*mw-tag-newbie[\w\s-]*">/', $line );
134 public function testRecentChangesLine_numberOfWatchingUsers() {
135 $oldChangesList = $this->getOldChangesList();
137 $recentChange = $this->getEditChange();
138 $recentChange->numberofWatchingusers = 100;
140 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
141 $this->assertRegExp( "/(number_of_watching_users_RCview: 100)/", $line );
144 public function testRecentChangesLine_watchlistCssClass() {
145 $oldChangesList = $this->getOldChangesList();
146 $oldChangesList->setWatchlistDivs( true );
148 $recentChange = $this->getEditChange();
149 $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
150 $this->assertRegExp( "/watchlist-0-Cat/", $line );
153 private function getNewBotEditChange() {
154 $user = $this->getTestUser();
156 $recentChange = $this->testRecentChangesHelper->makeNewBotEditRecentChange(
157 $user, 'Abc', '20131103212153', 5, 191, 190, 0, 0
160 return $recentChange;
163 private function getLogChange( $logType, $logAction ) {
164 $user = $this->getTestUser();
166 $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
167 $logType, $logAction, $user, 'Abc', '20131103212153', 0, 0
170 return $recentChange;
173 private function getEditChange() {
174 $user = $this->getTestUser();
175 $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
176 $user, 'Cat', '20131103212153', 5, 191, 190, 0, 0
179 return $recentChange;
182 private function getOldChangesList() {
183 $context = $this->getContext();
184 return new OldChangesList( $context );
187 private function getTestUser() {
188 $user = User::newFromName( 'TestRecentChangesUser' );
190 if ( !$user->getId() ) {
191 $user->addToDatabase();
194 return $user;
197 private function getContext() {
198 $user = $this->getTestUser();
199 $context = $this->testRecentChangesHelper->getTestContext( $user );
200 $context->setLanguage( Language::factory( 'qqx' ) );
202 return $context;