3 namespace MediaWiki\Tests\Block\Restriction
;
8 abstract class RestrictionTestCase
extends \MediaWikiTestCase
{
9 public function testConstruct() {
10 $class = $this->getClass();
11 $restriction = new $class( 1, 2 );
13 $this->assertSame( $restriction->getBlockId(), 1 );
14 $this->assertSame( $restriction->getValue(), 2 );
17 public function testSetBlockId() {
18 $class = $this->getClass();
19 $restriction = new $class( 1, 2 );
21 $restriction->setBlockId( 10 );
22 $this->assertSame( $restriction->getBlockId(), 10 );
25 public function testEquals() {
26 $class = $this->getClass();
28 // Test two restrictions with the same data.
29 $restriction = new $class( 1, 2 );
30 $second = new $class( 1, 2 );
31 $this->assertTrue( $restriction->equals( $second ) );
33 // Test two restrictions that implement different classes.
34 $second = $this->createMock( $this->getClass() );
35 $this->assertFalse( $restriction->equals( $second ) );
37 // Not the same block id.
38 $second = new $class( 2, 2 );
39 $this->assertTrue( $restriction->equals( $second ) );
41 // Not the same value.
42 $second = new $class( 1, 3 );
43 $this->assertFalse( $restriction->equals( $second ) );
46 public function testNewFromRow() {
47 $class = $this->getClass();
49 $restriction = $class::newFromRow( (object)[
54 $this->assertSame( 1, $restriction->getBlockId() );
55 $this->assertSame( 2, $restriction->getValue() );
58 public function testToRow() {
59 $class = $this->getClass();
61 $restriction = new $class( 1, 2 );
62 $row = $restriction->toRow();
64 $this->assertSame( 1, $row['ir_ipb_id'] );
65 $this->assertSame( 2, $row['ir_value'] );
69 * Get the class name of the class that is being tested.
73 abstract protected function getClass();