- UserEditTrackerTest: determine whether to create the page based on WikiPage::exists() instead of a method parameter. The current implementation only works because the page is not deleted between test runs, and the creation query is ignored. However, if the first call to `editTrackerDoEdit` doesn't have $create=true, tests would fail. For instance, testGetEditTimestamp would fail when run on its own because the revision cannot be inserted if the page doesn't exist. Just use WikiPage::exists instead of forcing callers to handle this correctly. - DatabaseBlockTest: use addDBDataOnce instead of a DIY implementation. This also makes the tests more deterministic, because the records needed by the test class are created immediately. Also avoid redundant User::addToDatabase and ::saveSettings, these are already done by TestUser. - PageRestrictionTest: avoid Title::newFromID which is not guaranteed to succeed if all pages have been deleted by that point. The second part of the test was effectively doing the same thing as the first part, so just remove it. - WikiPageDbTest: avoid expensive page deletions in tearDown. These are all unnecessary because the DB is cleaned up after each test (and 'page' is explicitly included in $tablesUsed). In fact, deleting test pages as done there can be even worse than not doing anything, because it creates log entries etc. Add page_restrictions to tablesUsed as that's not truncated automatically. - DBSiteStoreTest: testReset would fail when run on its own because it depends on test sites being inserted in testGetSites. Make the test add the sites it needs, so that they can safely be cleared between test runs. Change-Id: I1065fb3e8507b4b1a3bf185181f2f3059a97fd04
77 lines
2.2 KiB
PHP
77 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Block\Restriction;
|
|
|
|
use MediaWiki\Block\Restriction\PageRestriction;
|
|
use MediaWiki\Title\Title;
|
|
|
|
/**
|
|
* @group Database
|
|
* @group Blocking
|
|
* @covers \MediaWiki\Block\Restriction\AbstractRestriction
|
|
* @covers \MediaWiki\Block\Restriction\PageRestriction
|
|
*/
|
|
class PageRestrictionTest extends RestrictionTestCase {
|
|
|
|
public function testMatches() {
|
|
$class = $this->getClass();
|
|
$page = $this->getExistingTestPage( 'Saturn' );
|
|
$restriction = new $class( 1, $page->getId() );
|
|
$this->assertTrue( $restriction->matches( $page->getTitle() ) );
|
|
|
|
$page = $this->getExistingTestPage( 'Mars' );
|
|
$this->assertFalse( $restriction->matches( $page->getTitle() ) );
|
|
|
|
// Deleted page.
|
|
$restriction = new $class( 2, 99999 );
|
|
$page = $this->getExistingTestPage( 'Saturn' );
|
|
$this->assertFalse( $restriction->matches( $page->getTitle() ) );
|
|
}
|
|
|
|
public function testGetType() {
|
|
$class = $this->getClass();
|
|
$restriction = new $class( 1, 2 );
|
|
$this->assertEquals( 'page', $restriction->getType() );
|
|
}
|
|
|
|
public function testGetTitle() {
|
|
$class = $this->getClass();
|
|
$restriction = new $class( 1, 2 );
|
|
$title = Title::makeTitle( NS_MAIN, 'Pluto' );
|
|
$title->mArticleID = 2;
|
|
$restriction->setTitle( $title );
|
|
$this->assertSame( $title, $restriction->getTitle() );
|
|
}
|
|
|
|
public function testNewFromRow() {
|
|
$class = $this->getClass();
|
|
$restriction = $class::newFromRow( (object)[
|
|
'ir_ipb_id' => 1,
|
|
'ir_value' => 2,
|
|
'page_namespace' => 0,
|
|
'page_title' => 'Saturn',
|
|
] );
|
|
|
|
$this->assertSame( 1, $restriction->getBlockId() );
|
|
$this->assertSame( 2, $restriction->getValue() );
|
|
$this->assertSame( 'Saturn', $restriction->getTitle()->getText() );
|
|
}
|
|
|
|
public function testNewFromTitle() {
|
|
$class = $this->getClass();
|
|
$title = Title::makeTitle( NS_MAIN, 'Pluto' );
|
|
$restriction = $class::newFromTitle( 'Mars' );
|
|
$restriction2 = $class::newFromTitle( $title );
|
|
|
|
$this->assertSame( 0, $restriction->getBlockId() );
|
|
$this->assertSame( 'Mars', $restriction->getTitle()->getText() );
|
|
$this->assertSame( $title->getArticleID(), $restriction2->getValue() );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function getClass() {
|
|
return PageRestriction::class;
|
|
}
|
|
}
|