MediaWiki  REL1_31
RevisionSlotsTest.php
Go to the documentation of this file.
1 <?php
2 
4 
10 
12 
17  protected function newRevisionSlots( $slots = [] ) {
18  return new RevisionSlots( $slots );
19  }
20 
24  public function testGetSlot() {
25  $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
26  $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
27  $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
28 
29  $this->assertSame( $mainSlot, $slots->getSlot( 'main' ) );
30  $this->assertSame( $auxSlot, $slots->getSlot( 'aux' ) );
31  $this->setExpectedException( RevisionAccessException::class );
32  $slots->getSlot( 'nothere' );
33  }
34 
38  public function testHasSlot() {
39  $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
40  $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
41  $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
42 
43  $this->assertTrue( $slots->hasSlot( 'main' ) );
44  $this->assertTrue( $slots->hasSlot( 'aux' ) );
45  $this->assertFalse( $slots->hasSlot( 'AUX' ) );
46  $this->assertFalse( $slots->hasSlot( 'xyz' ) );
47  }
48 
52  public function testGetContent() {
53  $mainContent = new WikitextContent( 'A' );
54  $auxContent = new WikitextContent( 'B' );
55  $mainSlot = SlotRecord::newUnsaved( 'main', $mainContent );
56  $auxSlot = SlotRecord::newUnsaved( 'aux', $auxContent );
57  $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
58 
59  $this->assertSame( $mainContent, $slots->getContent( 'main' ) );
60  $this->assertSame( $auxContent, $slots->getContent( 'aux' ) );
61  $this->setExpectedException( RevisionAccessException::class );
62  $slots->getContent( 'nothere' );
63  }
64 
68  public function testGetSlotRoles_someSlots() {
69  $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
70  $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
71  $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
72 
73  $this->assertSame( [ 'main', 'aux' ], $slots->getSlotRoles() );
74  }
75 
79  public function testGetSlotRoles_noSlots() {
80  $slots = $this->newRevisionSlots( [] );
81 
82  $this->assertSame( [], $slots->getSlotRoles() );
83  }
84 
88  public function testGetSlots() {
89  $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
90  $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
91  $slotsArray = [ $mainSlot, $auxSlot ];
92  $slots = $this->newRevisionSlots( $slotsArray );
93 
94  $this->assertEquals( [ 'main' => $mainSlot, 'aux' => $auxSlot ], $slots->getSlots() );
95  }
96 
97  public function provideComputeSize() {
98  yield [ 1, [ 'A' ] ];
99  yield [ 2, [ 'AA' ] ];
100  yield [ 4, [ 'AA', 'X', 'H' ] ];
101  }
102 
107  public function testComputeSize( $expected, $contentStrings ) {
108  $slotsArray = [];
109  foreach ( $contentStrings as $key => $contentString ) {
110  $slotsArray[] = SlotRecord::newUnsaved( strval( $key ), new WikitextContent( $contentString ) );
111  }
112  $slots = $this->newRevisionSlots( $slotsArray );
113 
114  $this->assertSame( $expected, $slots->computeSize() );
115  }
116 
117  public function provideComputeSha1() {
118  yield [ 'ctqm7794fr2dp1taki8a88ovwnvmnmj', [ 'A' ] ];
119  yield [ 'eyq8wiwlcofnaiy4eid97gyfy60uw51', [ 'AA' ] ];
120  yield [ 'lavctqfpxartyjr31f853drgfl4kj1g', [ 'AA', 'X', 'H' ] ];
121  }
122 
129  public function testComputeSha1( $expected, $contentStrings ) {
130  $slotsArray = [];
131  foreach ( $contentStrings as $key => $contentString ) {
132  $slotsArray[] = SlotRecord::newUnsaved( strval( $key ), new WikitextContent( $contentString ) );
133  }
134  $slots = $this->newRevisionSlots( $slotsArray );
135 
136  $this->assertSame( $expected, $slots->computeSha1() );
137  }
138 
139 }
MediaWiki\Tests\Storage\RevisionSlotsTest\newRevisionSlots
newRevisionSlots( $slots=[])
Definition: RevisionSlotsTest.php:17
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\RevisionSlotsTest\provideComputeSize
provideComputeSize()
Definition: RevisionSlotsTest.php:97
MediaWiki\Tests\Storage\RevisionSlotsTest\testComputeSize
testComputeSize( $expected, $contentStrings)
provideComputeSize \MediaWiki\Storage\RevisionSlots::computeSize
Definition: RevisionSlotsTest.php:107
MediaWiki\Tests\Storage\RevisionSlotsTest\testGetSlotRoles_someSlots
testGetSlotRoles_someSlots()
\MediaWiki\Storage\RevisionSlots::getSlotRoles
Definition: RevisionSlotsTest.php:68
MediaWiki\Storage\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition: RevisionSlots.php:34
MediaWiki\Tests\Storage\RevisionSlotsTest\testGetSlotRoles_noSlots
testGetSlotRoles_noSlots()
\MediaWiki\Storage\RevisionSlots::getSlotRoles
Definition: RevisionSlotsTest.php:79
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\RevisionSlotsTest\testComputeSha1
testComputeSha1( $expected, $contentStrings)
provideComputeSha1 \MediaWiki\Storage\RevisionSlots::computeSha1
Definition: RevisionSlotsTest.php:129
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
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\Storage\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:32
MediaWiki\Tests\Storage\RevisionSlotsTest\testGetSlot
testGetSlot()
\MediaWiki\Storage\RevisionSlots::getSlot
Definition: RevisionSlotsTest.php:24
MediaWiki\Tests\Storage\RevisionSlotsTest\testGetSlots
testGetSlots()
\MediaWiki\Storage\RevisionSlots::getSlots
Definition: RevisionSlotsTest.php:88
MediaWiki\Storage\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:38
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
MediaWiki\Tests\Storage\RevisionSlotsTest\provideComputeSha1
provideComputeSha1()
Definition: RevisionSlotsTest.php:117
MediaWiki\Tests\Storage\RevisionSlotsTest
Definition: RevisionSlotsTest.php:11
MediaWiki\Tests\Storage\RevisionSlotsTest\testGetContent
testGetContent()
\MediaWiki\Storage\RevisionSlots::getContent
Definition: RevisionSlotsTest.php:52
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\Tests\Storage\RevisionSlotsTest\testHasSlot
testHasSlot()
\MediaWiki\Storage\RevisionSlots::hasSlot
Definition: RevisionSlotsTest.php:38