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}
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.
testComputeSize( $expected, $contentStrings)
provideComputeSize \MediaWiki\Storage\RevisionSlots::computeSize
testGetSlotRoles_noSlots()
\MediaWiki\Storage\RevisionSlots::getSlotRoles
testGetContent()
\MediaWiki\Storage\RevisionSlots::getContent
testHasSlot()
\MediaWiki\Storage\RevisionSlots::hasSlot
testComputeSha1( $expected, $contentStrings)
provideComputeSha1 \MediaWiki\Storage\RevisionSlots::computeSha1
testGetSlots()
\MediaWiki\Storage\RevisionSlots::getSlots
testGetSlot()
\MediaWiki\Storage\RevisionSlots::getSlot
testGetSlotRoles_someSlots()
\MediaWiki\Storage\RevisionSlots::getSlotRoles
Content object for wiki text pages.