1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
<?php
use MediaWiki\Context\RequestContext;
use MediaWiki\Title\Title;
/**
* @todo add tests to cover article link, timestamp, character difference,
* log entry, user tool links, direction marks, tags, rollback,
* watching users, and date header.
*
* @covers \OldChangesList
* @group Database
* @author Katie Filbert <aude.wiki@gmail.com>
*/
class OldChangesListTest extends MediaWikiLangTestCase {
/**
* @var TestRecentChangesHelper
*/
private $testRecentChangesHelper;
protected function setUp(): void {
parent::setUp();
$this->setUserLang( 'qqx' );
$this->testRecentChangesHelper = new TestRecentChangesHelper();
}
/**
* @dataProvider recentChangesLine_CssForLineNumberProvider
*/
public function testRecentChangesLine_CssForLineNumber( $expected, $linenumber, $message ) {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, false, $linenumber );
$this->assertMatchesRegularExpression( $expected, $line, $message );
}
public static function recentChangesLine_CssForLineNumberProvider() {
return [
[ '/mw-line-odd/', 1, 'odd line number' ],
[ '/mw-line-even/', 2, 'even line number' ]
];
}
public function testRecentChangesLine_NotWatchedCssClass() {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression( '/mw-changeslist-line-not-watched/', $line );
}
public function testRecentChangesLine_WatchedCssClass() {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, true, 1 );
$this->assertMatchesRegularExpression( '/mw-changeslist-line-watched/', $line );
}
public function testRecentChangesLine_LogTitle() {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getLogChange( 'delete', 'delete' );
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression( '/href="\/wiki\/Special:Log\/delete/', $line, 'link has href attribute' );
$this->assertMatchesRegularExpression( '/title="Special:Log\/delete/', $line, 'link has title attribute' );
$this->assertMatchesRegularExpression( "/dellogpage/", $line, 'link text' );
}
public function testRecentChangesLine_DiffHistLinks() {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression(
'/title=Cat&curid=20131103212153&diff=5&oldid=191/',
$line,
'assert diff link'
);
$this->assertMatchesRegularExpression(
'/title=Cat&curid=20131103212153&action=history"/',
$line,
'assert history link'
);
}
public function testRecentChangesLine_Flags() {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getNewBotEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertStringContainsString(
'<abbr class="newpage" title="(recentchanges-label-newpage)">(newpageletter)</abbr>',
$line,
'new page flag'
);
$this->assertStringContainsString(
'<abbr class="botedit" title="(recentchanges-label-bot)">(boteditletter)</abbr>',
$line,
'bot flag'
);
}
public function testRecentChangesLine_Attribs() {
$recentChange = $this->getEditChange();
$recentChange->mAttribs['ts_tags'] = 'vandalism,newbie';
$this->setTemporaryHook( 'OldChangesListRecentChangesLine', static function (
$oldChangesList, &$html, $rc, $classes, $attribs
) {
$html = $html . '/<div>Additional change line </div>/';
} );
$oldChangesList = $this->getOldChangesList();
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertStringContainsString(
'/<div>Additional change line </div>/',
$line
);
$this->assertMatchesRegularExpression(
'/<li data-mw-revid="\d+" data-mw-ts="\d+" class="[\w\s-]*mw-tag-vandalism[\w\s-]*">/',
$line
);
$this->assertMatchesRegularExpression(
'/<li data-mw-revid="\d+" data-mw-ts="\d+" class="[\w\s-]*mw-tag-newbie[\w\s-]*">/',
$line
);
}
public function testRecentChangesLine_numberOfWatchingUsers() {
$oldChangesList = $this->getOldChangesList();
$recentChange = $this->getEditChange();
$recentChange->numberofWatchingusers = 100;
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression( "/(number-of-watching-users-for-recent-changes: 100)/", $line );
}
public function testRecentChangesLine_watchlistCssClass() {
$oldChangesList = $this->getOldChangesList();
$oldChangesList->setWatchlistDivs( true );
$recentChange = $this->getEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression( "/watchlist-0-Cat/", $line );
}
public function testRecentChangesLine_dataAttribute() {
$oldChangesList = $this->getOldChangesList();
$oldChangesList->setWatchlistDivs( true );
$recentChange = $this->getEditChange();
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression( '/data-target-page=\"Cat\"/', $line );
$recentChange = $this->getLogChange( 'delete', 'delete' );
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
$this->assertMatchesRegularExpression( '/data-target-page="Abc"/', $line );
}
public function testRecentChangesLine_prefix() {
$mockContext = $this->getMockBuilder( RequestContext::class )
->onlyMethods( [ 'getTitle' ] )
->getMock();
$mockContext->method( 'getTitle' )
->willReturn( Title::makeTitle( NS_MAIN, 'Expected Context Title' ) );
$oldChangesList = $this->getOldChangesList();
$oldChangesList->setContext( $mockContext );
$recentChange = $this->getEditChange();
$oldChangesList->setChangeLinePrefixer( function ( $rc, $changesList ) {
// Make sure RecentChange and ChangesList objects are the same
$this->assertEquals( 'Expected Context Title', $changesList->getContext()->getTitle() );
$this->assertEquals( 'Cat', $rc->getTitle() );
return 'I am a prefix';
} );
$line = $oldChangesList->recentChangesLine( $recentChange );
$this->assertMatchesRegularExpression( "/I am a prefix/", $line );
}
private function getNewBotEditChange() {
$user = $this->getMutableTestUser()->getUser();
$recentChange = $this->testRecentChangesHelper->makeNewBotEditRecentChange(
$user, 'Abc', '20131103212153', 5, 191, 190, 0, 0
);
return $recentChange;
}
private function getLogChange( $logType, $logAction ) {
$user = $this->getMutableTestUser()->getUser();
$recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
$logType, $logAction, $user, 'Abc', '20131103212153', 0, 0
);
return $recentChange;
}
private function getEditChange() {
$user = $this->getMutableTestUser()->getUser();
$recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
$user, 'Cat', '20131103212153', 5, 191, 190, 0, 0
);
return $recentChange;
}
private function getOldChangesList() {
$context = $this->getContext();
return new OldChangesList( $context );
}
private function getContext() {
$user = $this->getMutableTestUser()->getUser();
$context = $this->testRecentChangesHelper->getTestContext( $user );
$context->setLanguage( 'qqx' );
return $context;
}
}
|