| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Block\Restriction; |
| 4 |
|
| 5 |
use MediaWiki\Block\Restriction\PageRestriction; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class PageRestrictionTest extends RestrictionTestCase { |
| 15 |
|
| 16 |
public function testMatches() { |
| 17 |
$class = $this->getClass(); |
| 18 |
$page = $this->getExistingTestPage( 'Saturn' ); |
| 19 |
$restriction = new $class( 1, $page->getId() ); |
| 20 |
$this->assertTrue( $restriction->matches( $page->getTitle() ) ); |
| 21 |
|
| 22 |
$page = $this->getExistingTestPage( 'Mars' ); |
| 23 |
$this->assertFalse( $restriction->matches( $page->getTitle() ) ); |
| 24 |
|
| 25 |
|
| 26 |
$restriction = new $class( 2, 99999 ); |
| 27 |
$page = $this->getExistingTestPage( 'Saturn' ); |
| 28 |
$this->assertFalse( $restriction->matches( $page->getTitle() ) ); |
| 29 |
} |
| 30 |
|
| 31 |
public function testGetType() { |
| 32 |
$class = $this->getClass(); |
| 33 |
$restriction = new $class( 1, 2 ); |
| 34 |
$this->assertEquals( 'page', $restriction->getType() ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testGetTitle() { |
| 38 |
$class = $this->getClass(); |
| 39 |
$restriction = new $class( 1, 2 ); |
| 40 |
$title = Title::makeTitle( NS_MAIN, 'Pluto' ); |
| 41 |
$title->mArticleID = 2; |
| 42 |
$restriction->setTitle( $title ); |
| 43 |
$this->assertSame( $title, $restriction->getTitle() ); |
| 44 |
} |
| 45 |
|
| 46 |
public function testNewFromRow() { |
| 47 |
$class = $this->getClass(); |
| 48 |
$restriction = $class::newFromRow( (object)[ |
| 49 |
'ir_ipb_id' => 1, |
| 50 |
'ir_value' => 2, |
| 51 |
'page_namespace' => 0, |
| 52 |
'page_title' => 'Saturn', |
| 53 |
] ); |
| 54 |
|
| 55 |
$this->assertSame( 1, $restriction->getBlockId() ); |
| 56 |
$this->assertSame( 2, $restriction->getValue() ); |
| 57 |
$this->assertSame( 'Saturn', $restriction->getTitle()->getText() ); |
| 58 |
} |
| 59 |
|
| 60 |
public function testNewFromTitle() { |
| 61 |
$class = $this->getClass(); |
| 62 |
$title = Title::makeTitle( NS_MAIN, 'Pluto' ); |
| 63 |
$restriction = $class::newFromTitle( 'Mars' ); |
| 64 |
$restriction2 = $class::newFromTitle( $title ); |
| 65 |
|
| 66 |
$this->assertSame( 0, $restriction->getBlockId() ); |
| 67 |
$this->assertSame( 'Mars', $restriction->getTitle()->getText() ); |
| 68 |
$this->assertSame( $title->getArticleID(), $restriction2->getValue() ); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
protected function getClass() { |
| 75 |
return PageRestriction::class; |
| 76 |
} |
| 77 |
} |