Merge "mw.rcfilters.ui.SaveFiltersPopupButtonWidget: Remove pointless option"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / SlotRecordTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Storage;
4
5 use MediaWiki\Storage\SlotRecord;
6 use MediaWikiTestCase;
7 use RuntimeException;
8 use Wikimedia\Assert\ParameterTypeException;
9 use WikitextContent;
10
11 /**
12 * @covers \MediaWiki\Storage\SlotRecord
13 */
14 class SlotRecordTest extends MediaWikiTestCase {
15
16 public function provideAContent() {
17 yield [ new WikitextContent( 'A' ) ];
18 yield [
19 function ( SlotRecord $slotRecord ) {
20 if ( $slotRecord->getAddress() === 'tt:456' ) {
21 return new WikitextContent( 'A' );
22 }
23 throw new RuntimeException( 'Got Wrong SlotRecord for callback' );
24 },
25 ];
26 }
27
28 /**
29 * @dataProvider provideAContent
30 */
31 public function testValidConstruction( $content ) {
32 $row = (object)[
33 'cont_size' => '1',
34 'cont_sha1' => 'someHash',
35 'cont_address' => 'tt:456',
36 'model_name' => 'aModelname',
37 'slot_revision' => '2',
38 'format_name' => 'someFormatName',
39 'role_name' => 'myRole',
40 'slot_inherited' => '99'
41 ];
42
43 $record = new SlotRecord( $row, $content );
44
45 $this->assertSame( 'A', $record->getContent()->getNativeData() );
46 $this->assertSame( 1, $record->getSize() );
47 $this->assertSame( 'someHash', $record->getSha1() );
48 $this->assertSame( 'aModelname', $record->getModel() );
49 $this->assertSame( 2, $record->getRevision() );
50 $this->assertSame( 'tt:456', $record->getAddress() );
51 $this->assertSame( 'someFormatName', $record->getFormat() );
52 $this->assertSame( 'myRole', $record->getRole() );
53 $this->assertTrue( $record->hasAddress() );
54 $this->assertTrue( $record->hasRevision() );
55 $this->assertTrue( $record->isInherited() );
56 }
57
58 public function provideInvalidConstruction() {
59 yield 'both null' => [ null, null ];
60 yield 'null row' => [ null, new WikitextContent( 'A' ) ];
61 yield 'array row' => [ null, new WikitextContent( 'A' ) ];
62 yield 'null content' => [ (object)[], null ];
63 }
64
65 /**
66 * @dataProvider provideInvalidConstruction
67 */
68 public function testInvalidConstruction( $row, $content ) {
69 $this->setExpectedException( ParameterTypeException::class );
70 new SlotRecord( $row, $content );
71 }
72
73 public function testHasAddress_false() {
74 $record = new SlotRecord( (object)[], new WikitextContent( 'A' ) );
75 $this->assertFalse( $record->hasAddress() );
76 }
77
78 public function testHasRevision_false() {
79 $record = new SlotRecord( (object)[], new WikitextContent( 'A' ) );
80 $this->assertFalse( $record->hasRevision() );
81 }
82
83 public function testInInherited_false() {
84 // TODO unskip me once fixed.
85 $this->markTestSkipped( 'Should probably return false, needs fixing?' );
86 $record = new SlotRecord( (object)[], new WikitextContent( 'A' ) );
87 $this->assertFalse( $record->isInherited() );
88 }
89
90 }