MCR: replace slot_inherited with slot_origin
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / SlotRecordTest.php
index ef31315..8f26494 100644 (file)
@@ -25,7 +25,7 @@ class SlotRecordTest extends MediaWikiTestCase {
                        'model_name' => CONTENT_MODEL_WIKITEXT,
                        'format_name' => CONTENT_FORMAT_WIKITEXT,
                        'slot_revision_id' => '2',
-                       'slot_inherited' => '1',
+                       'slot_origin' => '1',
                        'role_name' => 'myRole',
                ];
                return (object)$data;
@@ -43,6 +43,7 @@ class SlotRecordTest extends MediaWikiTestCase {
                $this->assertSame( 'someHash', $record->getSha1() );
                $this->assertSame( CONTENT_MODEL_WIKITEXT, $record->getModel() );
                $this->assertSame( 2, $record->getRevision() );
+               $this->assertSame( 1, $record->getOrigin() );
                $this->assertSame( 'tt:456', $record->getAddress() );
                $this->assertSame( 33, $record->getContentId() );
                $this->assertSame( CONTENT_FORMAT_WIKITEXT, $record->getFormat() );
@@ -56,7 +57,8 @@ class SlotRecordTest extends MediaWikiTestCase {
                        'format_name' => function () {
                                return CONTENT_FORMAT_WIKITEXT;
                        },
-                       'slot_inherited' => '0'
+                       'slot_revision_id' => '2',
+                       'slot_origin' => '2',
                ] );
 
                $content = function () {
@@ -73,6 +75,7 @@ class SlotRecordTest extends MediaWikiTestCase {
                $this->assertNotNull( $record->getSha1() );
                $this->assertSame( CONTENT_MODEL_WIKITEXT, $record->getModel() );
                $this->assertSame( 2, $record->getRevision() );
+               $this->assertSame( 2, $record->getRevision() );
                $this->assertSame( 'tt:456', $record->getAddress() );
                $this->assertSame( 33, $record->getContentId() );
                $this->assertSame( CONTENT_FORMAT_WIKITEXT, $record->getFormat() );
@@ -122,13 +125,35 @@ class SlotRecordTest extends MediaWikiTestCase {
                $record->getAddress();
        }
 
-       public function testGetRevision_fails() {
+       public function provideIncomplete() {
+               $unsaved = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               yield 'unsaved' => [ $unsaved ];
+
+               $parent = new SlotRecord( $this->makeRow(), new WikitextContent( 'A' ) );
+               $inherited = SlotRecord::newInherited( $parent );
+               yield 'inherited' => [ $inherited ];
+       }
+
+       /**
+        * @dataProvider provideIncomplete
+        */
+       public function testGetRevision_fails( SlotRecord $record ) {
                $record = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
                $this->setExpectedException( IncompleteRevisionException::class );
 
                $record->getRevision();
        }
 
+       /**
+        * @dataProvider provideIncomplete
+        */
+       public function testGetOrigin_fails( SlotRecord $record ) {
+               $record = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $this->setExpectedException( IncompleteRevisionException::class );
+
+               $record->getOrigin();
+       }
+
        public function provideHashStability() {
                yield [ '', 'phoiac9h4m842xq45sp7s6u21eteeq1' ];
                yield [ 'Lorem ipsum', 'hcr5u40uxr81d3nx89nvwzclfz6r9c5' ];
@@ -155,7 +180,7 @@ class SlotRecordTest extends MediaWikiTestCase {
        }
 
        public function testNewInherited() {
-               $row = $this->makeRow( [ 'slot_revision_id' => 7, 'slot_inherited' => 0 ] );
+               $row = $this->makeRow( [ 'slot_revision_id' => 7, 'slot_origin' => 7 ] );
                $parent = new SlotRecord( $row, new WikitextContent( 'A' ) );
 
                // This would happen while doing an edit, before saving revision meta-data.
@@ -205,6 +230,7 @@ class SlotRecordTest extends MediaWikiTestCase {
                $this->assertSame( 20, $saved->getContentId() );
                $this->assertSame( 'A', $saved->getContent()->getNativeData() );
                $this->assertSame( 10, $saved->getRevision() );
+               $this->assertSame( 10, $saved->getOrigin() );
 
                // make sure we didn't mess with the internal state of $unsaved
                $this->assertFalse( $unsaved->hasAddress() );
@@ -215,7 +241,7 @@ class SlotRecordTest extends MediaWikiTestCase {
                $freshRow = $this->makeRow( [
                        'content_id' => 10,
                        'content_address' => 'address:1',
-                       'slot_inherited' => 0,
+                       'slot_origin' => 1,
                        'slot_revision_id' => 1,
                ] );
 
@@ -227,7 +253,8 @@ class SlotRecordTest extends MediaWikiTestCase {
                $inheritedRow = $this->makeRow( [
                        'content_id' => null,
                        'content_address' => null,
-                       'slot_inherited' => 1
+                       'slot_origin' => 0,
+                       'slot_revision_id' => 1,
                ] );
 
                $inheritedSlot = new SlotRecord( $inheritedRow, new WikitextContent( 'A' ) );