2014-07-25 13:08:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers OldChangesList
|
|
|
|
|
*
|
2014-07-25 16:40:47 +00:00
|
|
|
* @todo add tests to cover article link, timestamp, character difference,
|
|
|
|
|
* log entry, user tool links, direction marks, tags, rollback,
|
|
|
|
|
* watching users, and date header.
|
|
|
|
|
*
|
2014-07-25 13:08:12 +00:00
|
|
|
* @group Database
|
|
|
|
|
*
|
|
|
|
|
* @author Katie Filbert < aude.wiki@gmail.com >
|
|
|
|
|
*/
|
|
|
|
|
class OldChangesListTest extends MediaWikiLangTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var TestRecentChangesHelper
|
|
|
|
|
*/
|
|
|
|
|
private $testRecentChangesHelper;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2014-07-25 13:08:12 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2014-09-01 10:22:50 +00:00
|
|
|
'wgArticlePath' => '/wiki/$1',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2016-03-09 16:47:58 +00:00
|
|
|
$this->setUserLang( 'qqx' );
|
2021-03-08 03:23:08 +00:00
|
|
|
$this->testRecentChangesHelper = new TestRecentChangesHelper();
|
2014-07-25 13:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider recentChangesLine_CssForLineNumberProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testRecentChangesLine_CssForLineNumber( $expected, $linenumber, $message ) {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, $linenumber );
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp( $expected, $line, $message );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function recentChangesLine_CssForLineNumberProvider() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ '/mw-line-odd/', 1, 'odd line number' ],
|
|
|
|
|
[ '/mw-line-even/', 2, 'even line number' ]
|
|
|
|
|
];
|
2014-07-25 13:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecentChangesLine_NotWatchedCssClass() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp( '/mw-changeslist-line-not-watched/', $line );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecentChangesLine_WatchedCssClass() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, true, 1 );
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp( '/mw-changeslist-line-watched/', $line );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecentChangesLine_LogTitle() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
2014-07-25 16:39:07 +00:00
|
|
|
$recentChange = $this->getLogChange( 'delete', 'delete' );
|
2014-07-25 13:08:12 +00:00
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp( '/href="\/wiki\/Special:Log\/delete/', $line, 'link has href attribute' );
|
|
|
|
|
$this->assertRegExp( '/title="Special:Log\/delete/', $line, 'link has title attribute' );
|
2014-09-01 10:22:50 +00:00
|
|
|
$this->assertRegExp( "/dellogpage/", $line, 'link text' );
|
2014-07-25 13:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecentChangesLine_DiffHistLinks() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/title=Cat&curid=20131103212153&diff=5&oldid=191/',
|
|
|
|
|
$line,
|
|
|
|
|
'assert diff link'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/title=Cat&curid=20131103212153&action=history"/',
|
|
|
|
|
$line,
|
|
|
|
|
'assert history link'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 16:40:15 +00:00
|
|
|
public function testRecentChangesLine_Flags() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$recentChange = $this->getNewBotEditChange();
|
|
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString(
|
2016-03-08 17:12:38 +00:00
|
|
|
'<abbr class="newpage" title="(recentchanges-label-newpage)">(newpageletter)</abbr>',
|
2014-07-25 16:40:15 +00:00
|
|
|
$line,
|
|
|
|
|
'new page flag'
|
|
|
|
|
);
|
|
|
|
|
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString(
|
2016-03-08 17:12:38 +00:00
|
|
|
'<abbr class="botedit" title="(recentchanges-label-bot)">(boteditletter)</abbr>',
|
2014-07-25 16:40:15 +00:00
|
|
|
$line,
|
|
|
|
|
'bot flag'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 05:31:32 +00:00
|
|
|
public function testRecentChangesLine_Attribs() {
|
2014-09-06 16:40:52 +00:00
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
$recentChange->mAttribs['ts_tags'] = 'vandalism,newbie';
|
|
|
|
|
|
2021-02-07 13:10:36 +00:00
|
|
|
$this->setTemporaryHook( 'OldChangesListRecentChangesLine', static function (
|
2020-05-13 22:04:37 +00:00
|
|
|
$oldChangesList, &$html, $rc, $classes, $attribs
|
|
|
|
|
) {
|
|
|
|
|
$html = $html . '/<div>Additional change line </div>/';
|
|
|
|
|
} );
|
|
|
|
|
|
2014-09-06 16:40:52 +00:00
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
|
2020-05-13 22:04:37 +00:00
|
|
|
$this->assertStringContainsString(
|
|
|
|
|
'/<div>Additional change line </div>/',
|
|
|
|
|
$line
|
|
|
|
|
);
|
2017-08-11 14:22:42 +00:00
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/<li data-mw-revid="\d+" data-mw-ts="\d+" class="[\w\s-]*mw-tag-vandalism[\w\s-]*">/',
|
|
|
|
|
$line
|
|
|
|
|
);
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/<li data-mw-revid="\d+" data-mw-ts="\d+" class="[\w\s-]*mw-tag-newbie[\w\s-]*">/',
|
|
|
|
|
$line
|
|
|
|
|
);
|
2014-09-06 16:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-01 10:23:15 +00:00
|
|
|
public function testRecentChangesLine_numberOfWatchingUsers() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
$recentChange->numberofWatchingusers = 100;
|
|
|
|
|
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
2019-04-30 20:41:50 +00:00
|
|
|
$this->assertRegExp( "/(number-of-watching-users-for-recent-changes: 100)/", $line );
|
2014-09-01 10:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecentChangesLine_watchlistCssClass() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$oldChangesList->setWatchlistDivs( true );
|
|
|
|
|
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
$this->assertRegExp( "/watchlist-0-Cat/", $line );
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-11 00:59:58 +00:00
|
|
|
public function testRecentChangesLine_dataAttribute() {
|
|
|
|
|
$oldChangesList = $this->getOldChangesList();
|
|
|
|
|
$oldChangesList->setWatchlistDivs( true );
|
|
|
|
|
|
|
|
|
|
$recentChange = $this->getEditChange();
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
$this->assertRegExp( '/data-target-page=\"Cat\"/', $line );
|
|
|
|
|
|
|
|
|
|
$recentChange = $this->getLogChange( 'delete', 'delete' );
|
|
|
|
|
$line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
|
|
|
|
|
$this->assertRegExp( '/data-target-page="Abc"/', $line );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecentChangesLine_prefix() {
|
|
|
|
|
$mockContext = $this->getMockBuilder( RequestContext::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'getTitle' ] )
|
2016-06-11 00:59:58 +00:00
|
|
|
->getMock();
|
|
|
|
|
$mockContext->method( 'getTitle' )
|
2021-04-22 08:28:11 +00:00
|
|
|
->willReturn( Title::newFromText( 'Expected Context Title' ) );
|
2016-06-11 00:59:58 +00:00
|
|
|
|
|
|
|
|
$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->assertRegExp( "/I am a prefix/", $line );
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 13:08:12 +00:00
|
|
|
private function getNewBotEditChange() {
|
2016-05-18 09:19:20 +00:00
|
|
|
$user = $this->getMutableTestUser()->getUser();
|
2014-07-25 13:08:12 +00:00
|
|
|
|
|
|
|
|
$recentChange = $this->testRecentChangesHelper->makeNewBotEditRecentChange(
|
2014-07-25 16:40:15 +00:00
|
|
|
$user, 'Abc', '20131103212153', 5, 191, 190, 0, 0
|
2014-07-25 13:08:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $recentChange;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 16:39:07 +00:00
|
|
|
private function getLogChange( $logType, $logAction ) {
|
2016-05-18 09:19:20 +00:00
|
|
|
$user = $this->getMutableTestUser()->getUser();
|
2014-07-25 13:08:12 +00:00
|
|
|
|
|
|
|
|
$recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
|
2014-07-25 16:39:07 +00:00
|
|
|
$logType, $logAction, $user, 'Abc', '20131103212153', 0, 0
|
2014-07-25 13:08:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $recentChange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getEditChange() {
|
2016-05-18 09:19:20 +00:00
|
|
|
$user = $this->getMutableTestUser()->getUser();
|
2014-07-25 13:08:12 +00:00
|
|
|
$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() {
|
2016-05-18 09:19:20 +00:00
|
|
|
$user = $this->getMutableTestUser()->getUser();
|
2014-07-25 13:08:12 +00:00
|
|
|
$context = $this->testRecentChangesHelper->getTestContext( $user );
|
2016-03-09 16:47:58 +00:00
|
|
|
$context->setLanguage( 'qqx' );
|
2014-07-25 13:08:12 +00:00
|
|
|
|
|
|
|
|
return $context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|