3 namespace MediaWiki\Tests\Storage
;
5 use MediaWiki\Storage\SlotRecord
;
8 use Wikimedia\Assert\ParameterTypeException
;
12 * @covers \MediaWiki\Storage\SlotRecord
14 class SlotRecordTest
extends MediaWikiTestCase
{
16 public function provideAContent() {
17 yield
[ new WikitextContent( 'A' ) ];
19 function ( SlotRecord
$slotRecord ) {
20 if ( $slotRecord->getAddress() === 'tt:456' ) {
21 return new WikitextContent( 'A' );
23 throw new RuntimeException( 'Got Wrong SlotRecord for callback' );
29 * @dataProvider provideAContent
31 public function testValidConstruction( $content ) {
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'
43 $record = new SlotRecord( $row, $content );
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() );
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 ];
66 * @dataProvider provideInvalidConstruction
68 public function testInvalidConstruction( $row, $content ) {
69 $this->setExpectedException( ParameterTypeException
::class );
70 new SlotRecord( $row, $content );
73 public function testHasAddress_false() {
74 $record = new SlotRecord( (object)[], new WikitextContent( 'A' ) );
75 $this->assertFalse( $record->hasAddress() );
78 public function testHasRevision_false() {
79 $record = new SlotRecord( (object)[], new WikitextContent( 'A' ) );
80 $this->assertFalse( $record->hasRevision() );
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() );