Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / includes / Revision / McrReadNewRevisionStoreDbTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Revision;
4
5 use CommentStoreComment;
6 use MediaWiki\MediaWikiServices;
7 use MediaWiki\Revision\RevisionRecord;
8 use MediaWiki\Revision\SlotRecord;
9 use TextContent;
10 use Title;
11 use WikitextContent;
12
13 /**
14 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
15 *
16 * @covers \MediaWiki\Revision\RevisionStore
17 *
18 * @group RevisionStore
19 * @group Storage
20 * @group Database
21 * @group medium
22 */
23 class McrReadNewRevisionStoreDbTest extends RevisionStoreDbTestBase {
24
25 use McrReadNewSchemaOverride;
26
27 protected function assertRevisionExistsInDatabase( RevisionRecord $rev ) {
28 $numberOfSlots = count( $rev->getSlotRoles() );
29
30 // new schema is written
31 $this->assertSelect(
32 'slots',
33 [ 'count(*)' ],
34 [ 'slot_revision_id' => $rev->getId() ],
35 [ [ (string)$numberOfSlots ] ]
36 );
37
38 $store = MediaWikiServices::getInstance()->getRevisionStore();
39 $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
40
41 $this->assertSelect(
42 $revQuery['tables'],
43 [ 'count(*)' ],
44 [
45 'slot_revision_id' => $rev->getId(),
46 ],
47 [ [ (string)$numberOfSlots ] ],
48 [],
49 $revQuery['joins']
50 );
51
52 // Legacy schema is still being written
53 $this->assertSelect(
54 [ 'revision', 'text' ],
55 [ 'count(*)' ],
56 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
57 [ [ 1 ] ],
58 [],
59 [ 'text' => [ 'JOIN', [ 'rev_text_id = old_id' ] ] ]
60 );
61
62 parent::assertRevisionExistsInDatabase( $rev );
63 }
64
65 /**
66 * @param SlotRecord $a
67 * @param SlotRecord $b
68 */
69 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
70 parent::assertSameSlotContent( $a, $b );
71
72 // Assert that the same content ID has been used
73 $this->assertSame( $a->getContentId(), $b->getContentId() );
74 }
75
76 public function provideInsertRevisionOn_successes() {
77 foreach ( parent::provideInsertRevisionOn_successes() as $case ) {
78 yield $case;
79 }
80
81 yield 'Multi-slot revision insertion' => [
82 [
83 'content' => [
84 'main' => new WikitextContent( 'Chicken' ),
85 'aux' => new TextContent( 'Egg' ),
86 ],
87 'page' => true,
88 'comment' => $this->getRandomCommentStoreComment(),
89 'timestamp' => '20171117010101',
90 'user' => true,
91 ],
92 ];
93 }
94
95 public function provideNewNullRevision() {
96 foreach ( parent::provideNewNullRevision() as $case ) {
97 yield $case;
98 }
99
100 yield [
101 Title::newFromText( 'UTPage_notAutoCreated' ),
102 [
103 'content' => [
104 'main' => new WikitextContent( 'Chicken' ),
105 'aux' => new WikitextContent( 'Omelet' ),
106 ],
107 ],
108 CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment multi' ),
109 ];
110 }
111
112 public function testGetQueryInfo_NoSlotDataJoin() {
113 $store = MediaWikiServices::getInstance()->getRevisionStore();
114 $queryInfo = $store->getQueryInfo();
115
116 // with the new schema enabled, query info should not join the main slot info
117 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
118 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
119 }
120
121 public function provideNewMutableRevisionFromArray() {
122 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
123 yield $case;
124 }
125
126 yield 'Basic array, multiple roles' => [
127 [
128 'id' => 2,
129 'page' => 1,
130 'timestamp' => '20171017114835',
131 'user_text' => '111.0.1.2',
132 'user' => 0,
133 'minor_edit' => false,
134 'deleted' => 0,
135 'len' => 29,
136 'parent_id' => 1,
137 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
138 'comment' => 'Goat Comment!',
139 'content' => [
140 'main' => new WikitextContent( 'Söme Cöntent' ),
141 'aux' => new TextContent( 'Öther Cöntent' ),
142 ]
143 ]
144 ];
145 }
146
147 /**
148 * Conditions to use together with getSlotsQueryInfo() when selecting slot rows for a given
149 * revision.
150 *
151 * @return array
152 */
153 protected function getSlotRevisionConditions( $revId ) {
154 return [ 'slot_revision_id' => $revId ];
155 }
156
157 }