MediaWiki  1.33.0
MutableRevisionSlotsTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use 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 
69  $slots->setSlot( $slotA );
70  $this->assertSame( $slotA, $slots->getSlot( SlotRecord::MAIN ) );
71  $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
72 
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();
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 
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() {
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 }
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:33
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testSetContentOfExistingSlotOverwritesContent
testSetContentOfExistingSlotOverwritesContent()
Definition: MutableRevisionSlotsTest.php:105
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\newRevisionSlots
newRevisionSlots( $slots=[])
Definition: MutableRevisionSlotsTest.php:22
Revision\MutableRevisionSlots
Mutable version of RevisionSlots, for constructing a new revision.
Definition: MutableRevisionSlots.php:33
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:36
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testInheritSlotOverwritesSlot
testInheritSlotOverwritesSlot()
Definition: MutableRevisionSlotsTest.php:88
Revision\SlotRecord\newUnsaved
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:129
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testNewFromParentRevisionSlots
testNewFromParentRevisionSlots()
Definition: MutableRevisionSlotsTest.php:132
MediaWiki\Tests\Revision\RevisionSlotsTest
Definition: RevisionSlotsTest.php:13
Revision\SlotRecord\MAIN
const MAIN
Definition: SlotRecord.php:41
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\newSavedSlot
newSavedSlot( $role, Content $content)
Definition: MutableRevisionSlotsTest.php:84
Content
Base interface for content objects.
Definition: Content.php:34
Revision\MutableRevisionSlots\newFromParentRevisionSlots
static newFromParentRevisionSlots(array $slots)
Constructs a MutableRevisionSlots that inherits from the given list of slots.
Definition: MutableRevisionSlots.php:43
MediaWiki\Tests\Revision\MutableRevisionSlotsTest
\MediaWiki\Revision\MutableRevisionSlots
Definition: MutableRevisionSlotsTest.php:16
Revision\SlotRecord\newSaved
static newSaved( $revisionId, $contentId, $contentAddress, SlotRecord $protoSlot)
Constructs a complete SlotRecord for a newly saved revision, based on the incomplete proto-slot.
Definition: SlotRecord.php:164
Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:35
$content
$content
Definition: pageupdater.txt:72
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testSetExistingSlotOverwritesSlot
testSetExistingSlotOverwritesSlot()
Definition: MutableRevisionSlotsTest.php:63
MediaWiki\Tests\Revision\MutableRevisionSlotsTest\testConstructorFailue
testConstructorFailue( $slots)
provideConstructorFailue
Definition: MutableRevisionSlotsTest.php:39
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39