MediaWiki  1.33.0
RestrictionTestCase.php
Go to the documentation of this file.
1 <?php
2 
4 
8 abstract class RestrictionTestCase extends \MediaWikiTestCase {
9  public function testConstruct() {
10  $class = $this->getClass();
11  $restriction = new $class( 1, 2 );
12 
13  $this->assertSame( $restriction->getBlockId(), 1 );
14  $this->assertSame( $restriction->getValue(), 2 );
15  }
16 
17  public function testSetBlockId() {
18  $class = $this->getClass();
19  $restriction = new $class( 1, 2 );
20 
21  $restriction->setBlockId( 10 );
22  $this->assertSame( $restriction->getBlockId(), 10 );
23  }
24 
25  public function testEquals() {
26  $class = $this->getClass();
27 
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 ) );
32 
33  // Test two restrictions that implement different classes.
34  $second = $this->createMock( $this->getClass() );
35  $this->assertFalse( $restriction->equals( $second ) );
36 
37  // Not the same block id.
38  $second = new $class( 2, 2 );
39  $this->assertTrue( $restriction->equals( $second ) );
40 
41  // Not the same value.
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 
73  abstract protected function getClass();
74 }
MediaWiki\Tests\Block\Restriction\RestrictionTestCase\getClass
getClass()
Get the class name of the class that is being tested.
MediaWiki\Tests\Block\Restriction\RestrictionTestCase\testToRow
testToRow()
Definition: RestrictionTestCase.php:58
MediaWiki\Tests\Block\Restriction\RestrictionTestCase
Blocking.
Definition: RestrictionTestCase.php:8
MediaWiki\Tests\Block\Restriction\RestrictionTestCase\testSetBlockId
testSetBlockId()
Definition: RestrictionTestCase.php:17
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Tests\Block\Restriction
Definition: NamespaceRestrictionTest.php:3
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Tests\Block\Restriction\RestrictionTestCase\testNewFromRow
testNewFromRow()
Definition: RestrictionTestCase.php:46
MediaWiki\Tests\Block\Restriction\RestrictionTestCase\testConstruct
testConstruct()
Definition: RestrictionTestCase.php:9
MediaWiki\Tests\Block\Restriction\RestrictionTestCase\testEquals
testEquals()
Definition: RestrictionTestCase.php:25