[MCR] Introduce RevisionSlotsUpdate.
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionSlotsTest.php
index b9f833c..95bba47 100644 (file)
@@ -2,10 +2,12 @@
 
 namespace MediaWiki\Tests\Storage;
 
+use InvalidArgumentException;
 use MediaWiki\Storage\RevisionAccessException;
 use MediaWiki\Storage\RevisionSlots;
 use MediaWiki\Storage\SlotRecord;
 use MediaWikiTestCase;
+use TextContent;
 use WikitextContent;
 
 class RevisionSlotsTest extends MediaWikiTestCase {
@@ -18,6 +20,28 @@ class RevisionSlotsTest extends MediaWikiTestCase {
                return new RevisionSlots( $slots );
        }
 
+       public function provideConstructorFailue() {
+               yield 'not an array or callable' => [
+                       'foo'
+               ];
+               yield 'array of the wrong thing' => [
+                       [ 1, 2, 3 ]
+               ];
+       }
+
+       /**
+        * @dataProvider provideConstructorFailue
+        * @param $slots
+        *
+        * @covers \MediaWiki\Storage\RevisionSlots::__construct
+        * @covers \MediaWiki\Storage\RevisionSlots::setSlotsInternal
+        */
+       public function testConstructorFailue( $slots ) {
+               $this->setExpectedException( InvalidArgumentException::class );
+
+               new RevisionSlots( $slots );
+       }
+
        /**
         * @covers \MediaWiki\Storage\RevisionSlots::getSlot
         */
@@ -94,6 +118,40 @@ class RevisionSlotsTest extends MediaWikiTestCase {
                $this->assertEquals( [ 'main' => $mainSlot, 'aux' => $auxSlot ], $slots->getSlots() );
        }
 
+       /**
+        * @covers \MediaWiki\Storage\RevisionSlots::getInheritedSlots
+        */
+       public function testGetInheritedSlots() {
+               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $auxSlot = SlotRecord::newInherited(
+                       SlotRecord::newSaved(
+                               7, 7, 'foo',
+                               SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) )
+                       )
+               );
+               $slotsArray = [ $mainSlot, $auxSlot ];
+               $slots = $this->newRevisionSlots( $slotsArray );
+
+               $this->assertEquals( [ 'aux' => $auxSlot ], $slots->getInheritedSlots() );
+       }
+
+       /**
+        * @covers \MediaWiki\Storage\RevisionSlots::getTouchedSlots
+        */
+       public function testGetTouchedSlots() {
+               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $auxSlot = SlotRecord::newInherited(
+                       SlotRecord::newSaved(
+                               7, 7, 'foo',
+                               SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) )
+                       )
+               );
+               $slotsArray = [ $mainSlot, $auxSlot ];
+               $slots = $this->newRevisionSlots( $slotsArray );
+
+               $this->assertEquals( [ 'main' => $mainSlot ], $slots->getTouchedSlots() );
+       }
+
        public function provideComputeSize() {
                yield [ 1, [ 'A' ] ];
                yield [ 2, [ 'AA' ] ];
@@ -136,4 +194,34 @@ class RevisionSlotsTest extends MediaWikiTestCase {
                $this->assertSame( $expected, $slots->computeSha1() );
        }
 
+       public function provideHasSameContent() {
+               $fooX = SlotRecord::newUnsaved( 'x', new TextContent( 'Foo' ) );
+               $barZ = SlotRecord::newUnsaved( 'z', new TextContent( 'Bar' ) );
+               $fooY = SlotRecord::newUnsaved( 'y', new TextContent( 'Foo' ) );
+               $barZS = SlotRecord::newSaved( 7, 7, 'xyz', $barZ );
+               $barZ2 = SlotRecord::newUnsaved( 'z', new TextContent( 'Baz' ) );
+
+               $a = $this->newRevisionSlots( [ 'x' => $fooX, 'z' => $barZ ] );
+               $a2 = $this->newRevisionSlots( [ 'x' => $fooX, 'z' => $barZ ] );
+               $a3 = $this->newRevisionSlots( [ 'x' => $fooX, 'z' => $barZS ] );
+               $b = $this->newRevisionSlots( [ 'y' => $fooY, 'z' => $barZ ] );
+               $c = $this->newRevisionSlots( [ 'x' => $fooX, 'z' => $barZ2 ] );
+
+               yield 'same instance' => [ $a, $a, true ];
+               yield 'same slots' => [ $a, $a2, true ];
+               yield 'same content' => [ $a, $a3, true ];
+
+               yield 'different roles' => [ $a, $b, false ];
+               yield 'different content' => [ $a, $c, false ];
+       }
+
+       /**
+        * @dataProvider provideHasSameContent
+        * @covers \MediaWiki\Storage\RevisionSlots::hasSameContent
+        */
+       public function testHasSameContent( RevisionSlots $a, RevisionSlots $b, $same ) {
+               $this->assertSame( $same, $a->hasSameContent( $b ) );
+               $this->assertSame( $same, $b->hasSameContent( $a ) );
+       }
+
 }