MediaWiki
REL1_32
MutableRevisionSlotsTest.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Tests\Revision
;
4
5
use
Content
;
6
use InvalidArgumentException;
7
use
MediaWiki\Revision\MutableRevisionSlots
;
8
use
MediaWiki\Revision\RevisionAccessException
;
9
use
MediaWiki\Revision\RevisionSlots
;
10
use
MediaWiki\Revision\SlotRecord
;
11
use
WikitextContent
;
12
16
class
MutableRevisionSlotsTest
extends
RevisionSlotsTest
{
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
63
public
function
testSetExistingSlotOverwritesSlot
() {
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
88
public
function
testInheritSlotOverwritesSlot
() {
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
105
public
function
testSetContentOfExistingSlotOverwritesContent
() {
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
132
public
function
testNewFromParentRevisionSlots
() {
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
}
MediaWiki\Revision\MutableRevisionSlots
Mutable version of RevisionSlots, for constructing a new revision.
Definition
MutableRevisionSlots.php:33
MediaWiki\Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition
RevisionAccessException.php:33
MediaWiki\Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition
RevisionSlots.php:35
MediaWiki\Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition
SlotRecord.php:39
MediaWiki\Tests\Revision\MutableRevisionSlotsTest
\MediaWiki\Revision\MutableRevisionSlots
Definition
MutableRevisionSlotsTest.php:16
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testInheritSlotOverwritesSlot
testInheritSlotOverwritesSlot()
Definition
MutableRevisionSlotsTest.php:88
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testNewFromParentRevisionSlots
testNewFromParentRevisionSlots()
Definition
MutableRevisionSlotsTest.php:132
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testConstructorFailue
testConstructorFailue( $slots)
provideConstructorFailue
Definition
MutableRevisionSlotsTest.php:39
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testSetContentOfExistingSlotOverwritesContent
testSetContentOfExistingSlotOverwritesContent()
Definition
MutableRevisionSlotsTest.php:105
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testSetExistingSlotOverwritesSlot
testSetExistingSlotOverwritesSlot()
Definition
MutableRevisionSlotsTest.php:63
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\newRevisionSlots
newRevisionSlots( $slots=[])
Definition
MutableRevisionSlotsTest.php:22
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\newSavedSlot
newSavedSlot( $role, Content $content)
Definition
MutableRevisionSlotsTest.php:84
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testRemoveExistingSlot
testRemoveExistingSlot()
Definition
MutableRevisionSlotsTest.php:120
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testSetMultipleSlots
testSetMultipleSlots()
Definition
MutableRevisionSlotsTest.php:45
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\provideConstructorFailue
provideConstructorFailue()
Definition
MutableRevisionSlotsTest.php:26
MediaWiki\Tests\Revision\RevisionSlotsTest
Definition
RevisionSlotsTest.php:13
WikitextContent
Content object for wiki text pages.
Definition
WikitextContent.php:35
Content
Base interface for content objects.
Definition
Content.php:34
MediaWiki\Tests\Revision
Definition
McrReadNewRevisionStoreDbTest.php:2
$content
$content
Definition
pageupdater.txt:72
tests
phpunit
includes
Revision
MutableRevisionSlotsTest.php
Generated on Mon Nov 25 2024 15:58:51 for MediaWiki by
1.10.0