use MediaWiki\Block\BlockRestriction;
use MediaWiki\Block\Restriction\PageRestriction;
+use MediaWiki\Block\Restriction\NamespaceRestriction;
/**
* @group Database
}
/**
- * @covers Block::preventsEdit
+ * @covers Block::appliesToTitle
*/
- public function testPreventsEditReturnsTrueOnSitewideBlock() {
+ public function testAppliesToTitleReturnsTrueOnSitewideBlock() {
$user = $this->getTestUser()->getUser();
$block = new Block( [
'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
$title = $this->getExistingTestPage( 'Foo' )->getTitle();
- $this->assertTrue( $block->preventsEdit( $title ) );
+ $this->assertTrue( $block->appliesToTitle( $title ) );
+
+ // appliesToTitle() ignores allowUsertalk
+ $title = $user->getTalkPage();
+ $this->assertTrue( $block->appliesToTitle( $title ) );
$block->delete();
}
/**
- * @covers Block::preventsEdit
+ * @covers Block::appliesToTitle
*/
- public function testPreventsEditOnPartialBlock() {
+ public function testAppliesToTitleOnPartialBlock() {
$user = $this->getTestUser()->getUser();
$block = new Block( [
'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
$pageFoo = $this->getExistingTestPage( 'Foo' );
$pageBar = $this->getExistingTestPage( 'Bar' );
+ $pageJohn = $this->getExistingTestPage( 'User:John' );
$pageRestriction = new PageRestriction( $block->getId(), $pageFoo->getId() );
- BlockRestriction::insert( [ $pageRestriction ] );
+ $namespaceRestriction = new NamespaceRestriction( $block->getId(), NS_USER );
+ BlockRestriction::insert( [ $pageRestriction, $namespaceRestriction ] );
- $this->assertTrue( $block->preventsEdit( $pageFoo->getTitle() ) );
- $this->assertFalse( $block->preventsEdit( $pageBar->getTitle() ) );
+ $this->assertTrue( $block->appliesToTitle( $pageFoo->getTitle() ) );
+ $this->assertFalse( $block->appliesToTitle( $pageBar->getTitle() ) );
+ $this->assertTrue( $block->appliesToTitle( $pageJohn->getTitle() ) );
$block->delete();
}
/**
- * @covers Block::preventsEdit
- * @dataProvider preventsEditOnUserTalkProvider
+ * @covers Block::appliesToNamespace
+ * @covers Block::appliesToPage
*/
- public function testPreventsEditOnUserTalkPage(
- $allowUsertalk, $sitewide, $result, $blockAllowsUTEdit = true
- ) {
- $this->setMwGlobals( [
- 'wgBlockAllowsUTEdit' => $blockAllowsUTEdit,
+ public function testAppliesToReturnsTrueOnSitewideBlock() {
+ $user = $this->getTestUser()->getUser();
+ $block = new Block( [
+ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
+ 'allowUsertalk' => true,
+ 'sitewide' => true
] );
+ $block->setTarget( $user );
+ $block->setBlocker( $this->getTestSysop()->getUser() );
+ $block->insert();
+
+ $title = $this->getExistingTestPage()->getTitle();
+
+ $this->assertTrue( $block->appliesToPage( $title->getArticleID() ) );
+ $this->assertTrue( $block->appliesToNamespace( NS_MAIN ) );
+ $this->assertTrue( $block->appliesToNamespace( NS_USER_TALK ) );
+
+ $block->delete();
+ }
+
+ /**
+ * @covers Block::appliesToPage
+ */
+ public function testAppliesToPageOnPartialPageBlock() {
$user = $this->getTestUser()->getUser();
$block = new Block( [
'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
- 'allowUsertalk' => $allowUsertalk,
- 'sitewide' => $sitewide
+ 'allowUsertalk' => true,
+ 'sitewide' => false
] );
$block->setTarget( $user );
$block->setBlocker( $this->getTestSysop()->getUser() );
$block->insert();
- $this->assertEquals( $result, $block->preventsEdit( $user->getTalkPage() ) );
+ $title = $this->getExistingTestPage()->getTitle();
+
+ $pageRestriction = new PageRestriction(
+ $block->getId(),
+ $title->getArticleID()
+ );
+ BlockRestriction::insert( [ $pageRestriction ] );
+
+ $this->assertTrue( $block->appliesToPage( $title->getArticleID() ) );
+
$block->delete();
}
- public function preventsEditOnUserTalkProvider() {
- return [
- [
- 'allowUsertalk' => false,
- 'sitewide' => true,
- 'result' => true,
- ],
- [
- 'allowUsertalk' => true,
- 'sitewide' => true,
- 'result' => false,
- ],
- [
- 'allowUsertalk' => true,
- 'sitewide' => false,
- 'result' => false,
- ],
- [
- 'allowUsertalk' => false,
- 'sitewide' => false,
- 'result' => true,
- ],
- [
- 'allowUsertalk' => true,
- 'sitewide' => true,
- 'result' => true,
- 'blockAllowsUTEdit' => false
- ],
- [
- 'allowUsertalk' => true,
- 'sitewide' => false,
- 'result' => true,
- 'blockAllowsUTEdit' => false
- ],
- ];
+ /**
+ * @covers Block::appliesToNamespace
+ */
+ public function testAppliesToNamespaceOnPartialNamespaceBlock() {
+ $user = $this->getTestUser()->getUser();
+ $block = new Block( [
+ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
+ 'allowUsertalk' => true,
+ 'sitewide' => false
+ ] );
+
+ $block->setTarget( $user );
+ $block->setBlocker( $this->getTestSysop()->getUser() );
+ $block->insert();
+
+ $namespaceRestriction = new NamespaceRestriction( $block->getId(), NS_MAIN );
+ BlockRestriction::insert( [ $namespaceRestriction ] );
+
+ $this->assertTrue( $block->appliesToNamespace( NS_MAIN ) );
+ $this->assertFalse( $block->appliesToNamespace( NS_USER ) );
+
+ $block->delete();
}
+
+ /**
+ * @covers Block::prevents
+ */
+ public function testBlockAllowsPurge() {
+ $block = new Block();
+ $this->assertFalse( $block->prevents( 'purge' ) );
+ }
+
}