wiki.techinc.nl/tests/phpunit/includes/block/Restriction/RestrictionTestCase.php
Dayllan Maza a562611e5b Add block restriction classes
Partial blocks logic will be used in multiple places. This
classes will group block restriction functionality to avoid
code duplication

Bug: T202036
Change-Id: I675316dddf272fd0d6172ecad3882160752bf780
2018-10-23 17:41:50 -07:00

74 lines
1.8 KiB
PHP

<?php
namespace MediaWiki\Tests\Block\Restriction;
/**
* @group Blocking
*/
abstract class RestrictionTestCase extends \MediaWikiTestCase {
public function testConstruct() {
$class = $this->getClass();
$restriction = new $class( 1, 2 );
$this->assertSame( $restriction->getBlockId(), 1 );
$this->assertSame( $restriction->getValue(), 2 );
}
public function testSetBlockId() {
$class = $this->getClass();
$restriction = new $class( 1, 2 );
$restriction->setBlockId( 10 );
$this->assertSame( $restriction->getBlockId(), 10 );
}
public function testEquals() {
$class = $this->getClass();
// Test two restrictions with the same data.
$restriction = new $class( 1, 2 );
$second = new $class( 1, 2 );
$this->assertTrue( $restriction->equals( $second ) );
// Test two restrictions that implement different classes.
$second = $this->createMock( $this->getClass() );
$this->assertFalse( $restriction->equals( $second ) );
// Not the same block id.
$second = new $class( 2, 2 );
$this->assertTrue( $restriction->equals( $second ) );
// Not the same value.
$second = new $class( 1, 3 );
$this->assertFalse( $restriction->equals( $second ) );
}
public function testNewFromRow() {
$class = $this->getClass();
$restriction = $class::newFromRow( (object)[
'ir_ipb_id' => 1,
'ir_value' => 2,
] );
$this->assertSame( 1, $restriction->getBlockId() );
$this->assertSame( 2, $restriction->getValue() );
}
public function testToRow() {
$class = $this->getClass();
$restriction = new $class( 1, 2 );
$row = $restriction->toRow();
$this->assertSame( 1, $row['ir_ipb_id'] );
$this->assertSame( 2, $row['ir_value'] );
}
/**
* Get the class name of the class that is being tested.
*
* @return string
*/
abstract protected function getClass();
}