MediaWiki REL1_33
MutableRevisionSlotsTest.php
Go to the documentation of this file.
1<?php
2
4
5use Content;
6use InvalidArgumentException;
12
17
22 protected function newRevisionSlots( $slots = [] ) {
23 return new MutableRevisionSlots( $slots );
24 }
25
26 public function provideConstructorFailue() {
27 yield 'array or the wrong thing' => [
28 [ 1, 2, 3 ]
29 ];
30 }
31
39 public function testConstructorFailue( $slots ) {
40 $this->setExpectedException( InvalidArgumentException::class );
41
42 new MutableRevisionSlots( $slots );
43 }
44
45 public function testSetMultipleSlots() {
46 $slots = new MutableRevisionSlots();
47
48 $this->assertSame( [], $slots->getSlots() );
49
50 $slotA = SlotRecord::newUnsaved( 'some', new WikitextContent( 'A' ) );
51 $slots->setSlot( $slotA );
52 $this->assertTrue( $slots->hasSlot( 'some' ) );
53 $this->assertSame( $slotA, $slots->getSlot( 'some' ) );
54 $this->assertSame( [ 'some' => $slotA ], $slots->getSlots() );
55
56 $slotB = SlotRecord::newUnsaved( 'other', new WikitextContent( 'B' ) );
57 $slots->setSlot( $slotB );
58 $this->assertTrue( $slots->hasSlot( 'other' ) );
59 $this->assertSame( $slotB, $slots->getSlot( 'other' ) );
60 $this->assertSame( [ 'some' => $slotA, 'other' => $slotB ], $slots->getSlots() );
61 }
62
64 $slots = new MutableRevisionSlots();
65
66 $this->assertSame( [], $slots->getSlots() );
67
68 $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
69 $slots->setSlot( $slotA );
70 $this->assertSame( $slotA, $slots->getSlot( SlotRecord::MAIN ) );
71 $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
72
73 $slotB = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'B' ) );
74 $slots->setSlot( $slotB );
75 $this->assertSame( $slotB, $slots->getSlot( SlotRecord::MAIN ) );
76 $this->assertSame( [ 'main' => $slotB ], $slots->getSlots() );
77 }
78
84 private function newSavedSlot( $role, Content $content ) {
85 return SlotRecord::newSaved( 7, 7, 'xyz', SlotRecord::newUnsaved( $role, $content ) );
86 }
87
89 $slots = new MutableRevisionSlots();
90 $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
91 $slots->setSlot( $slotA );
92 $slotB = $this->newSavedSlot( SlotRecord::MAIN, new WikitextContent( 'B' ) );
93 $slotC = $this->newSavedSlot( 'foo', new WikitextContent( 'C' ) );
94 $slots->inheritSlot( $slotB );
95 $slots->inheritSlot( $slotC );
96 $this->assertSame( [ 'main', 'foo' ], $slots->getSlotRoles() );
97 $this->assertNotSame( $slotB, $slots->getSlot( SlotRecord::MAIN ) );
98 $this->assertNotSame( $slotC, $slots->getSlot( 'foo' ) );
99 $this->assertTrue( $slots->getSlot( SlotRecord::MAIN )->isInherited() );
100 $this->assertTrue( $slots->getSlot( 'foo' )->isInherited() );
101 $this->assertSame( $slotB->getContent(), $slots->getSlot( SlotRecord::MAIN )->getContent() );
102 $this->assertSame( $slotC->getContent(), $slots->getSlot( 'foo' )->getContent() );
103 }
104
106 $slots = new MutableRevisionSlots();
107
108 $this->assertSame( [], $slots->getSlots() );
109
110 $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
111 $slots->setSlot( $slotA );
112 $this->assertSame( $slotA, $slots->getSlot( SlotRecord::MAIN ) );
113 $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
114
115 $newContent = new WikitextContent( 'B' );
116 $slots->setContent( SlotRecord::MAIN, $newContent );
117 $this->assertSame( $newContent, $slots->getContent( SlotRecord::MAIN ) );
118 }
119
120 public function testRemoveExistingSlot() {
121 $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
122 $slots = new MutableRevisionSlots( [ $slotA ] );
123
124 $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
125
126 $slots->removeSlot( SlotRecord::MAIN );
127 $this->assertSame( [], $slots->getSlots() );
128 $this->setExpectedException( RevisionAccessException::class );
129 $slots->getSlot( SlotRecord::MAIN );
130 }
131
134 $parentSlots = [
135 'some' => $this->newSavedSlot( 'some', new WikitextContent( 'X' ) ),
136 'other' => $this->newSavedSlot( 'other', new WikitextContent( 'Y' ) ),
137 ];
138 $slots = MutableRevisionSlots::newFromParentRevisionSlots( $parentSlots );
139 $this->assertSame( [ 'some', 'other' ], $slots->getSlotRoles() );
140 $this->assertNotSame( $parentSlots['some'], $slots->getSlot( 'some' ) );
141 $this->assertNotSame( $parentSlots['other'], $slots->getSlot( 'other' ) );
142 $this->assertTrue( $slots->getSlot( 'some' )->isInherited() );
143 $this->assertTrue( $slots->getSlot( 'other' )->isInherited() );
144 $this->assertSame( $parentSlots['some']->getContent(), $slots->getContent( 'some' ) );
145 $this->assertSame( $parentSlots['other']->getContent(), $slots->getContent( 'other' ) );
146 }
147
148}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Mutable version of RevisionSlots, for constructing a new revision.
Exception representing a failure to look up a revision.
Value object representing the set of slots belonging to a revision.
Value object representing a content slot associated with a page revision.
Content object for wiki text pages.
Base interface for content objects.
Definition Content.php:34
$content