Cache redirects from Special:Redirect
[lhc/web/wiklou.git] / tests / phpunit / includes / block / Restriction / PageRestrictionTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Block\Restriction;
4
5 use MediaWiki\Block\Restriction\PageRestriction;
6
7 /**
8 * @group Database
9 * @group Blocking
10 * @covers \MediaWiki\Block\Restriction\AbstractRestriction
11 * @covers \MediaWiki\Block\Restriction\PageRestriction
12 */
13 class PageRestrictionTest extends RestrictionTestCase {
14
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() ) );
20
21 $page = $this->getExistingTestPage( 'Mars' );
22 $this->assertFalse( $restriction->matches( $page->getTitle() ) );
23 }
24
25 public function testGetType() {
26 $class = $this->getClass();
27 $restriction = new $class( 1, 2 );
28 $this->assertEquals( 'page', $restriction->getType() );
29 }
30
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() );
38
39 $restriction = new $class( 1, 1 );
40 $title = \Title::newFromId( 1 );
41 $this->assertEquals( $title->getArticleId(), $restriction->getTitle()->getArticleId() );
42 }
43
44 public function testNewFromRow() {
45 $class = $this->getClass();
46 $restriction = $class::newFromRow( (object)[
47 'ir_ipb_id' => 1,
48 'ir_value' => 2,
49 'page_namespace' => 0,
50 'page_title' => 'Saturn',
51 ] );
52
53 $this->assertSame( 1, $restriction->getBlockId() );
54 $this->assertSame( 2, $restriction->getValue() );
55 $this->assertSame( 'Saturn', $restriction->getTitle()->getText() );
56 }
57
58 /**
59 * {@inheritdoc}
60 */
61 protected function getClass() {
62 return PageRestriction::class;
63 }
64 }