| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Block\Restriction; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
abstract class RestrictionTestCase extends \MediaWikiIntegrationTestCase { |
| 9 |
public function testConstruct() { |
| 10 |
$class = $this->getClass(); |
| 11 |
$restriction = new $class( 1, 2 ); |
| 12 |
|
| 13 |
$this->assertSame( 1, $restriction->getBlockId() ); |
| 14 |
$this->assertSame( 2, $restriction->getValue() ); |
| 15 |
} |
| 16 |
|
| 17 |
public function testSetBlockId() { |
| 18 |
$class = $this->getClass(); |
| 19 |
$restriction = new $class( 1, 2 ); |
| 20 |
|
| 21 |
$restriction->setBlockId( 10 ); |
| 22 |
$this->assertSame( 10, $restriction->getBlockId() ); |
| 23 |
} |
| 24 |
|
| 25 |
public function testEquals() { |
| 26 |
$class = $this->getClass(); |
| 27 |
|
| 28 |
|
| 29 |
$restriction = new $class( 1, 2 ); |
| 30 |
$second = new $class( 1, 2 ); |
| 31 |
$this->assertTrue( $restriction->equals( $second ) ); |
| 32 |
|
| 33 |
|
| 34 |
$second = $this->createMock( $this->getClass() ); |
| 35 |
$this->assertFalse( $restriction->equals( $second ) ); |
| 36 |
|
| 37 |
|
| 38 |
$second = new $class( 2, 2 ); |
| 39 |
$this->assertTrue( $restriction->equals( $second ) ); |
| 40 |
|
| 41 |
|
| 42 |
$second = new $class( 1, 3 ); |
| 43 |
$this->assertFalse( $restriction->equals( $second ) ); |
| 44 |
} |
| 45 |
|
| 46 |
public function testNewFromRow() { |
| 47 |
$class = $this->getClass(); |
| 48 |
|
| 49 |
$restriction = $class::newFromRow( (object)[ |
| 50 |
'ir_ipb_id' => 1, |
| 51 |
'ir_value' => 2, |
| 52 |
] ); |
| 53 |
|
| 54 |
$this->assertSame( 1, $restriction->getBlockId() ); |
| 55 |
$this->assertSame( 2, $restriction->getValue() ); |
| 56 |
} |
| 57 |
|
| 58 |
public function testToRow() { |
| 59 |
$class = $this->getClass(); |
| 60 |
|
| 61 |
$restriction = new $class( 1, 2 ); |
| 62 |
$row = $restriction->toRow(); |
| 63 |
|
| 64 |
$this->assertSame( 1, $row['ir_ipb_id'] ); |
| 65 |
$this->assertSame( 2, $row['ir_value'] ); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
abstract protected function getClass(); |
| 74 |
} |