MediaWiki REL1_31
MutableRevisionSlotsTest.php
Go to the documentation of this file.
1<?php
2
4
9
14
15 public function testSetMultipleSlots() {
16 $slots = new MutableRevisionSlots();
17
18 $this->assertSame( [], $slots->getSlots() );
19
20 $slotA = SlotRecord::newUnsaved( 'some', new WikitextContent( 'A' ) );
21 $slots->setSlot( $slotA );
22 $this->assertTrue( $slots->hasSlot( 'some' ) );
23 $this->assertSame( $slotA, $slots->getSlot( 'some' ) );
24 $this->assertSame( [ 'some' => $slotA ], $slots->getSlots() );
25
26 $slotB = SlotRecord::newUnsaved( 'other', new WikitextContent( 'B' ) );
27 $slots->setSlot( $slotB );
28 $this->assertTrue( $slots->hasSlot( 'other' ) );
29 $this->assertSame( $slotB, $slots->getSlot( 'other' ) );
30 $this->assertSame( [ 'some' => $slotA, 'other' => $slotB ], $slots->getSlots() );
31 }
32
34 $slots = new MutableRevisionSlots();
35
36 $this->assertSame( [], $slots->getSlots() );
37
38 $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
39 $slots->setSlot( $slotA );
40 $this->assertSame( $slotA, $slots->getSlot( 'main' ) );
41 $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
42
43 $slotB = SlotRecord::newUnsaved( 'main', new WikitextContent( 'B' ) );
44 $slots->setSlot( $slotB );
45 $this->assertSame( $slotB, $slots->getSlot( 'main' ) );
46 $this->assertSame( [ 'main' => $slotB ], $slots->getSlots() );
47 }
48
50 $slots = new MutableRevisionSlots();
51
52 $this->assertSame( [], $slots->getSlots() );
53
54 $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
55 $slots->setSlot( $slotA );
56 $this->assertSame( $slotA, $slots->getSlot( 'main' ) );
57 $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
58
59 $newContent = new WikitextContent( 'B' );
60 $slots->setContent( 'main', $newContent );
61 $this->assertSame( $newContent, $slots->getContent( 'main' ) );
62 }
63
64 public function testRemoveExistingSlot() {
65 $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
66 $slots = new MutableRevisionSlots( [ $slotA ] );
67
68 $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
69
70 $slots->removeSlot( 'main' );
71 $this->assertSame( [], $slots->getSlots() );
72 $this->setExpectedException( RevisionAccessException::class );
73 $slots->getSlot( 'main' );
74 }
75
76}
Mutable version of RevisionSlots, for constructing a new revision.
Exception representing a failure to look up a revision.
Value object representing a content slot associated with a page revision.
Content object for wiki text pages.