wiki.techinc.nl/tests/phpunit/includes/specials/SpecialRecentchangesTest.php
Thiemo Kreuz e4b51a4aae Fix mismatching type hints in ChangesListSpecialPageTest
Some of these parameters are marked as optional and nullable,
but can never be null (the test would fail then), and are
never missing.

While I'm here I also add more strict type hints for
parameters and return types. Note this is only done in tests
and impossible to cause trouble in production.

Change-Id: I1c66325c97d5ea86d9822e789a36542faad1272b
2021-05-01 15:39:54 +00:00

111 lines
3.4 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
* Test class for SpecialRecentchanges class
*
* @group Database
*
* @covers SpecialRecentChanges
*/
class SpecialRecentchangesTest extends AbstractChangesListSpecialPageTestCase {
/**
* @return SpecialRecentChanges
*/
protected function getPage() {
$services = MediaWikiServices::getInstance();
return TestingAccessWrapper::newFromObject(
new SpecialRecentChanges(
$services->getWatchedItemStore(),
$services->getMessageCache(),
$services->getDBLoadBalancer(),
$services->getUserOptionsLookup()
)
);
}
// Below providers should only be for features specific to
// RecentChanges. Otherwise, it should go in ChangesListSpecialPageTest
public function provideParseParameters() {
return [
[ 'limit=123', [ 'limit' => '123' ] ],
[ '234', [ 'limit' => '234' ] ],
[ 'days=3', [ 'days' => '3' ] ],
[ 'days=0.25', [ 'days' => '0.25' ] ],
[ 'namespace=5', [ 'namespace' => '5' ] ],
[ 'namespace=5|3', [ 'namespace' => '5|3' ] ],
[ 'tagfilter=foo', [ 'tagfilter' => 'foo' ] ],
[ 'tagfilter=foo;bar', [ 'tagfilter' => 'foo;bar' ] ],
];
}
public function validateOptionsProvider() {
return [
[
// hidebots=1 is default for Special:RecentChanges
[ 'hideanons' => 1, 'hideliu' => 1 ],
true,
[ 'hideliu' => 1 ],
false,
],
];
}
public function testAddWatchlistJoins() {
// Edit a test page so that it shows up in RC.
$testTitle = Title::newFromText( 'Test page' );
$testPage = WikiPage::factory( $testTitle );
$testPage->doEditContent( ContentHandler::makeContent( 'Test content', $testTitle ), '' );
// Set up RC.
$context = new RequestContext;
$context->setTitle( Title::newFromText( __METHOD__ ) );
$context->setUser( $this->getTestUser()->getUser() );
$context->setRequest( new FauxRequest );
// Confirm that the test page is in RC.
$rc1 = $this->getPage();
$rc1->setContext( $context );
$rc1->execute( null );
$this->assertStringContainsString( 'Test page', $rc1->getOutput()->getHTML() );
$this->assertStringContainsString( 'mw-changeslist-line-not-watched', $rc1->getOutput()->getHTML() );
// Watch the page, and check that it's now watched in RC.
$watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
$watchedItemStore->addWatch( $context->getUser(), $testTitle );
$rc2 = $this->getPage();
$rc2->setContext( $context );
$rc2->execute( null );
$this->assertStringContainsString( 'Test page', $rc2->getOutput()->getHTML() );
$this->assertStringContainsString( 'mw-changeslist-line-watched', $rc2->getOutput()->getHTML() );
// Force a past expiry date on the watchlist item.
$db = wfGetDB( DB_PRIMARY );
$queryConds = [ 'wl_namespace' => $testTitle->getNamespace(), 'wl_title' => $testTitle->getDBkey() ];
$watchedItemId = $db->selectField( 'watchlist', 'wl_id', $queryConds, __METHOD__ );
$db->update(
'watchlist_expiry',
[ 'we_expiry' => $db->timestamp( '20200101000000' ) ],
[ 'we_item' => $watchedItemId ],
__METHOD__
);
// Check that the page is still in RC, but that it's no longer watched.
$rc3 = $this->getPage();
$rc3->setContext( $context );
$rc3->execute( null );
$this->assertStringContainsString( 'Test page', $rc3->getOutput()->getHTML() );
$this->assertStringContainsString( 'mw-changeslist-line-not-watched', $rc3->getOutput()->getHTML() );
}
}