2 namespace MediaWiki\Tests\Storage
;
4 use InvalidArgumentException
;
5 use MediaWiki\Storage\RevisionRecord
;
6 use MediaWiki\Storage\SlotRecord
;
11 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
13 * @covers \MediaWiki\Storage\RevisionStore
15 * @group RevisionStore
20 class McrWriteBothRevisionStoreDbTest
extends RevisionStoreDbTestBase
{
22 use McrWriteBothSchemaOverride
;
24 protected function revisionToRow( Revision
$rev, $options = [ 'page', 'user', 'comment' ] ) {
25 $row = parent
::revisionToRow( $rev, $options );
27 $row->rev_text_id
= (string)$rev->getTextId();
28 $row->rev_content_format
= (string)$rev->getContentFormat();
29 $row->rev_content_model
= (string)$rev->getContentModel();
34 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
35 // New schema is being written
39 [ 'slot_revision_id' => $rev->getId() ],
46 [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
50 // Legacy schema is still being written
52 [ 'revision', 'text' ],
54 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
57 [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ]
60 parent
::assertRevisionExistsInDatabase( $rev );
64 * @param SlotRecord $a
65 * @param SlotRecord $b
67 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
68 parent
::assertSameSlotContent( $a, $b );
70 // Assert that the same content ID has been used
71 if ( $a->hasContentId() && $b->hasContentId() ) {
72 $this->assertSame( $a->getContentId(), $b->getContentId() );
76 public function provideGetArchiveQueryInfo() {
79 'tables' => [ 'archive' ],
80 'fields' => array_merge(
81 $this->getDefaultArchiveFields(),
83 'ar_comment_text' => 'ar_comment',
84 'ar_comment_data' => 'NULL',
85 'ar_comment_cid' => 'NULL',
86 'ar_user_text' => 'ar_user_text',
87 'ar_user' => 'ar_user',
98 public function provideGetQueryInfo() {
102 'tables' => [ 'revision' ],
103 'fields' => array_merge(
104 $this->getDefaultQueryFields(),
105 $this->getCommentQueryFields(),
106 $this->getActorQueryFields(),
107 $this->getContentHandlerQueryFields()
115 'tables' => [ 'revision', 'page', 'user' ],
116 'fields' => array_merge(
117 $this->getDefaultQueryFields(),
118 $this->getCommentQueryFields(),
119 $this->getActorQueryFields(),
120 $this->getContentHandlerQueryFields(),
132 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
133 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
139 public function provideGetSlotsQueryInfo() {
140 $db = wfGetDB( DB_REPLICA
);
146 'slots' => 'revision',
148 'fields' => array_merge(
150 'slot_revision_id' => 'slots.rev_id',
151 'slot_content_id' => 'NULL',
152 'slot_origin' => 'slots.rev_id',
153 'role_name' => $db->addQuotes( 'main' ),
163 'slots' => 'revision',
165 'fields' => array_merge(
167 'slot_revision_id' => 'slots.rev_id',
168 'slot_content_id' => 'NULL',
169 'slot_origin' => 'slots.rev_id',
170 'role_name' => $db->addQuotes( 'main' ),
171 'content_size' => 'slots.rev_len',
172 'content_sha1' => 'slots.rev_sha1',
173 'content_address' => $db->buildConcat( [
174 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
175 'model_name' => 'slots.rev_content_model',
183 public function provideInsertRevisionOn_failures() {
184 foreach ( parent
::provideInsertRevisionOn_failures() as $case ) {
188 yield
'slot that is not main slot' => [
191 'main' => new WikitextContent( 'Chicken' ),
192 'lalala' => new WikitextContent( 'Duck' ),
194 'comment' => $this->getRandomCommentStoreComment(),
195 'timestamp' => '20171117010101',
198 new InvalidArgumentException( 'Only the main slot is supported' )
202 public function provideNewMutableRevisionFromArray() {
203 foreach ( parent
::provideNewMutableRevisionFromArray() as $case ) {
207 yield
'Basic array, with page & id' => [
212 'timestamp' => '20171017114835',
213 'user_text' => '111.0.1.2',
215 'minor_edit' => false,
219 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
220 'comment' => 'Goat Comment!',
221 'content_format' => 'text/x-wiki',
222 'content_model' => 'wikitext',