Consolidate tests for getQueryInfo() and related methods.
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / McrWriteBothRevisionStoreDbTest.php
1 <?php
2 namespace MediaWiki\Tests\Storage;
3
4 use InvalidArgumentException;
5 use MediaWiki\Storage\RevisionRecord;
6 use MediaWiki\Storage\SlotRecord;
7 use Revision;
8 use WikitextContent;
9
10 /**
11 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
12 *
13 * @covers \MediaWiki\Storage\RevisionStore
14 *
15 * @group RevisionStore
16 * @group Storage
17 * @group Database
18 * @group medium
19 */
20 class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase {
21
22 use McrWriteBothSchemaOverride;
23
24 protected function revisionToRow( Revision $rev, $options = [ 'page', 'user', 'comment' ] ) {
25 $row = parent::revisionToRow( $rev, $options );
26
27 $row->rev_text_id = (string)$rev->getTextId();
28 $row->rev_content_format = (string)$rev->getContentFormat();
29 $row->rev_content_model = (string)$rev->getContentModel();
30
31 return $row;
32 }
33
34 protected function assertRevisionExistsInDatabase( RevisionRecord $rev ) {
35 // New schema is being written
36 $this->assertSelect(
37 'slots',
38 [ 'count(*)' ],
39 [ 'slot_revision_id' => $rev->getId() ],
40 [ [ '1' ] ]
41 );
42
43 $this->assertSelect(
44 'content',
45 [ 'count(*)' ],
46 [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
47 [ [ '1' ] ]
48 );
49
50 // Legacy schema is still being written
51 $this->assertSelect(
52 [ 'revision', 'text' ],
53 [ 'count(*)' ],
54 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
55 [ [ 1 ] ],
56 [],
57 [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ]
58 );
59
60 parent::assertRevisionExistsInDatabase( $rev );
61 }
62
63 /**
64 * @param SlotRecord $a
65 * @param SlotRecord $b
66 */
67 protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
68 parent::assertSameSlotContent( $a, $b );
69
70 // Assert that the same content ID has been used
71 if ( $a->hasContentId() && $b->hasContentId() ) {
72 $this->assertSame( $a->getContentId(), $b->getContentId() );
73 }
74 }
75
76 public function provideInsertRevisionOn_failures() {
77 foreach ( parent::provideInsertRevisionOn_failures() as $case ) {
78 yield $case;
79 }
80
81 yield 'slot that is not main slot' => [
82 [
83 'content' => [
84 'main' => new WikitextContent( 'Chicken' ),
85 'lalala' => new WikitextContent( 'Duck' ),
86 ],
87 'comment' => $this->getRandomCommentStoreComment(),
88 'timestamp' => '20171117010101',
89 'user' => true,
90 ],
91 new InvalidArgumentException( 'Only the main slot is supported' )
92 ];
93 }
94
95 public function provideNewMutableRevisionFromArray() {
96 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
97 yield $case;
98 }
99
100 yield 'Basic array, with page & id' => [
101 [
102 'id' => 2,
103 'page' => 1,
104 'text_id' => 2,
105 'timestamp' => '20171017114835',
106 'user_text' => '111.0.1.2',
107 'user' => 0,
108 'minor_edit' => false,
109 'deleted' => 0,
110 'len' => 46,
111 'parent_id' => 1,
112 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
113 'comment' => 'Goat Comment!',
114 'content_format' => 'text/x-wiki',
115 'content_model' => 'wikitext',
116 ]
117 ];
118 }
119
120 }