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 }
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
MediaWiki\Tests\Storage\MutableRevisionSlotsTest
\MediaWiki\Storage\MutableRevisionSlots
Definition: MutableRevisionSlotsTest.php:13
MediaWiki\Tests\Storage\MutableRevisionSlotsTest\testSetContentOfExistingSlotOverwritesContent
testSetContentOfExistingSlotOverwritesContent()
Definition: MutableRevisionSlotsTest.php:49
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:37
MediaWiki\Tests\Storage
Definition: BlobStoreFactoryTest.php:3
MediaWiki\Tests\Storage\MutableRevisionSlotsTest\testRemoveExistingSlot
testRemoveExistingSlot()
Definition: MutableRevisionSlotsTest.php:64
MediaWiki\Tests\Storage\MutableRevisionSlotsTest\testSetExistingSlotOverwritesSlot
testSetExistingSlotOverwritesSlot()
Definition: MutableRevisionSlotsTest.php:33
MediaWiki\Storage\SlotRecord\newUnsaved
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:124
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
MediaWiki\Tests\Storage\MutableRevisionSlotsTest\testSetMultipleSlots
testSetMultipleSlots()
Definition: MutableRevisionSlotsTest.php:15
MediaWiki\Storage\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:32
MediaWiki\Storage\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:38
MediaWiki\Tests\Storage\RevisionSlotsTest
Definition: RevisionSlotsTest.php:11
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:56
MediaWiki\Storage\MutableRevisionSlots
Mutable version of RevisionSlots, for constructing a new revision.
Definition: MutableRevisionSlots.php:32