Make undo fail if more than just the main slot is affected.
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionSlotsTest.php
index 95bba47..52647c2 100644 (file)
@@ -136,9 +136,9 @@ class RevisionSlotsTest extends MediaWikiTestCase {
        }
 
        /**
-        * @covers \MediaWiki\Storage\RevisionSlots::getTouchedSlots
+        * @covers \MediaWiki\Storage\RevisionSlots::getOriginalSlots
         */
-       public function testGetTouchedSlots() {
+       public function testGetOriginalSlots() {
                $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newInherited(
                        SlotRecord::newSaved(
@@ -149,7 +149,7 @@ class RevisionSlotsTest extends MediaWikiTestCase {
                $slotsArray = [ $mainSlot, $auxSlot ];
                $slots = $this->newRevisionSlots( $slotsArray );
 
-               $this->assertEquals( [ 'main' => $mainSlot ], $slots->getTouchedSlots() );
+               $this->assertEquals( [ 'main' => $mainSlot ], $slots->getOriginalSlots() );
        }
 
        public function provideComputeSize() {
@@ -224,4 +224,34 @@ class RevisionSlotsTest extends MediaWikiTestCase {
                $this->assertSame( $same, $b->hasSameContent( $a ) );
        }
 
+       public function provideGetRolesWithDifferentContent() {
+               $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, [] ];
+               yield 'same slots' => [ $a, $a2, [] ];
+               yield 'same content' => [ $a, $a3, [] ];
+
+               yield 'different roles' => [ $a, $b, [ 'x', 'y' ] ];
+               yield 'different content' => [ $a, $c, [ 'z' ] ];
+       }
+
+       /**
+        * @dataProvider provideGetRolesWithDifferentContent
+        * @covers \MediaWiki\Storage\RevisionSlots::getRolesWithDifferentContent
+        */
+       public function testGetRolesWithDifferentContent( RevisionSlots $a, RevisionSlots $b, $roles ) {
+               $this->assertArrayEquals( $roles, $a->getRolesWithDifferentContent( $b ) );
+               $this->assertArrayEquals( $roles, $b->getRolesWithDifferentContent( $a ) );
+       }
+
 }