3 namespace MediaWiki\Tests\Block\Restriction
;
5 use MediaWiki\Block\Restriction\PageRestriction
;
10 * @covers \MediaWiki\Block\Restriction\AbstractRestriction
11 * @covers \MediaWiki\Block\Restriction\PageRestriction
13 class PageRestrictionTest
extends RestrictionTestCase
{
15 public function testMatches() {
16 $class = $this->getClass();
17 $page = $this->getExistingTestPage( 'Saturn' );
18 $restriction = new $class( 1, $page->getId() );
19 $this->assertTrue( $restriction->matches( $page->getTitle() ) );
21 $page = $this->getExistingTestPage( 'Mars' );
22 $this->assertFalse( $restriction->matches( $page->getTitle() ) );
25 public function testGetType() {
26 $class = $this->getClass();
27 $restriction = new $class( 1, 2 );
28 $this->assertEquals( 'page', $restriction->getType() );
31 public function testGetTitle() {
32 $class = $this->getClass();
33 $restriction = new $class( 1, 2 );
34 $title = \Title
::newFromText( 'Pluto' );
35 $title->mArticleID
= 2;
36 $restriction->setTitle( $title );
37 $this->assertSame( $title, $restriction->getTitle() );
39 $restriction = new $class( 1, 1 );
40 $title = \Title
::newFromId( 1 );
41 $this->assertEquals( $title->getArticleId(), $restriction->getTitle()->getArticleId() );
44 public function testNewFromRow() {
45 $class = $this->getClass();
46 $restriction = $class::newFromRow( (object)[
49 'page_namespace' => 0,
50 'page_title' => 'Saturn',
53 $this->assertSame( 1, $restriction->getBlockId() );
54 $this->assertSame( 2, $restriction->getValue() );
55 $this->assertSame( 'Saturn', $restriction->getTitle()->getText() );
61 protected function getClass() {
62 return PageRestriction
::class;