3 namespace MediaWiki\Tests\Revision
;
5 use MediaWiki\MediaWikiServices
;
6 use MediaWiki\Revision\SlotRecord
;
11 * Tests RevisionStore against the post-migration MCR DB schema.
13 * @group RevisionStore
17 class RevisionQueryInfoTest
extends MediaWikiTestCase
{
19 protected function getRevisionQueryFields( $returnTextIdField = true ) {
30 if ( $returnTextIdField ) {
31 $fields[] = 'rev_text_id';
36 protected function getArchiveQueryFields( $returnTextFields = true ) {
50 if ( $returnTextFields ) {
51 $fields[] = 'ar_text_id';
56 protected function getNewCommentQueryFields( $prefix ) {
58 "{$prefix}_comment_text" => "comment_{$prefix}_comment.comment_text",
59 "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
60 "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
64 protected function getNewActorQueryFields( $prefix, $tmp = false ) {
66 "{$prefix}_user" => "actor_{$prefix}_user.actor_user",
67 "{$prefix}_user_text" => "actor_{$prefix}_user.actor_name",
68 "{$prefix}_actor" => $tmp ?
"temp_{$prefix}_user.{$prefix}actor_actor" : "{$prefix}_actor",
72 protected function getTextQueryFields() {
79 protected function getPageQueryFields() {
90 protected function getUserQueryFields() {
96 protected function getContentHandlerQueryFields( $prefix ) {
98 "{$prefix}_content_format",
99 "{$prefix}_content_model",
103 public function provideArchiveQueryInfo() {
104 yield
'MCR, comment, actor' => [
106 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
111 'actor_ar_user' => 'actor',
112 'comment_ar_comment' => 'comment',
114 'fields' => array_merge(
115 $this->getArchiveQueryFields( false ),
116 $this->getNewActorQueryFields( 'ar' ),
117 $this->getNewCommentQueryFields( 'ar' )
121 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
122 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
126 yield
'read-new MCR, comment, actor' => [
128 'wgContentHandlerUseDB' => true,
129 'wgMultiContentRevisionSchemaMigrationStage'
130 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
135 'actor_ar_user' => 'actor',
136 'comment_ar_comment' => 'comment',
138 'fields' => array_merge(
139 $this->getArchiveQueryFields( false ),
140 $this->getNewActorQueryFields( 'ar' ),
141 $this->getNewCommentQueryFields( 'ar' )
145 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
146 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
150 yield
'MCR write-both/read-old' => [
152 'wgContentHandlerUseDB' => true,
153 'wgMultiContentRevisionSchemaMigrationStage'
154 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
159 'actor_ar_user' => 'actor',
160 'comment_ar_comment' => 'comment',
162 'fields' => array_merge(
163 $this->getArchiveQueryFields( true ),
164 $this->getContentHandlerQueryFields( 'ar' ),
165 $this->getNewActorQueryFields( 'ar' ),
166 $this->getNewCommentQueryFields( 'ar' )
170 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
171 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
175 yield
'pre-MCR, no model' => [
177 'wgContentHandlerUseDB' => false,
178 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
183 'actor_ar_user' => 'actor',
184 'comment_ar_comment' => 'comment',
186 'fields' => array_merge(
187 $this->getArchiveQueryFields( true ),
188 $this->getNewActorQueryFields( 'ar' ),
189 $this->getNewCommentQueryFields( 'ar' )
193 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
194 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
200 public function provideQueryInfo() {
201 // TODO: more option variations
202 yield
'MCR, page, user, comment, actor' => [
204 'wgContentHandlerUseDB' => true,
205 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
213 'temp_rev_user' => 'revision_actor_temp',
214 'temp_rev_comment' => 'revision_comment_temp',
215 'actor_rev_user' => 'actor',
216 'comment_rev_comment' => 'comment',
218 'fields' => array_merge(
219 $this->getRevisionQueryFields( false ),
220 $this->getPageQueryFields(),
221 $this->getUserQueryFields(),
222 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
223 $this->getNewCommentQueryFields( 'rev' )
226 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
229 [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
231 'comment_rev_comment' => [
233 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
235 'actor_rev_user' => [
237 'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
239 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
240 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
241 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
242 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
246 yield
'MCR read-new, page, user, comment, actor' => [
248 'wgContentHandlerUseDB' => true,
249 'wgMultiContentRevisionSchemaMigrationStage'
250 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
258 'temp_rev_user' => 'revision_actor_temp',
259 'temp_rev_comment' => 'revision_comment_temp',
260 'actor_rev_user' => 'actor',
261 'comment_rev_comment' => 'comment',
263 'fields' => array_merge(
264 $this->getRevisionQueryFields( false ),
265 $this->getPageQueryFields(),
266 $this->getUserQueryFields(),
267 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
268 $this->getNewCommentQueryFields( 'rev' )
271 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
275 'actor_rev_user.actor_user != 0',
276 'user_id = actor_rev_user.actor_user',
279 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
280 'comment_rev_comment'
281 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
282 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
283 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
287 yield
'MCR read-new' => [
289 'wgContentHandlerUseDB' => true,
290 'wgMultiContentRevisionSchemaMigrationStage'
291 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
299 'temp_rev_user' => 'revision_actor_temp',
300 'temp_rev_comment' => 'revision_comment_temp',
301 'actor_rev_user' => 'actor',
302 'comment_rev_comment' => 'comment',
304 'fields' => array_merge(
305 $this->getRevisionQueryFields( false ),
306 $this->getPageQueryFields(),
307 $this->getUserQueryFields(),
308 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
309 $this->getNewCommentQueryFields( 'rev' )
312 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
316 'actor_rev_user.actor_user != 0',
317 'user_id = actor_rev_user.actor_user'
320 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
321 'comment_rev_comment'
322 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
323 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
324 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
328 yield
'MCR write-both/read-old' => [
330 'wgContentHandlerUseDB' => true,
331 'wgMultiContentRevisionSchemaMigrationStage'
332 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
338 'temp_rev_comment' => 'revision_comment_temp',
339 'comment_rev_comment' => 'comment',
340 'temp_rev_user' => 'revision_actor_temp',
341 'actor_rev_user' => 'actor',
343 'fields' => array_merge(
344 $this->getRevisionQueryFields( true ),
345 $this->getContentHandlerQueryFields( 'rev' ),
346 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
347 $this->getNewCommentQueryFields( 'rev' )
350 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
351 'comment_rev_comment'
352 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
353 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
354 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
358 yield
'MCR write-both/read-old, page, user' => [
360 'wgContentHandlerUseDB' => true,
361 'wgMultiContentRevisionSchemaMigrationStage'
362 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
370 'temp_rev_comment' => 'revision_comment_temp',
371 'comment_rev_comment' => 'comment',
372 'temp_rev_user' => 'revision_actor_temp',
373 'actor_rev_user' => 'actor',
375 'fields' => array_merge(
376 $this->getRevisionQueryFields( true ),
377 $this->getContentHandlerQueryFields( 'rev' ),
378 $this->getUserQueryFields(),
379 $this->getPageQueryFields(),
380 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
381 $this->getNewCommentQueryFields( 'rev' )
384 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
388 'actor_rev_user.actor_user != 0',
389 'user_id = actor_rev_user.actor_user',
392 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
393 'comment_rev_comment'
394 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
395 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
396 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
402 'wgContentHandlerUseDB' => true,
403 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
409 'temp_rev_comment' => 'revision_comment_temp',
410 'comment_rev_comment' => 'comment',
411 'temp_rev_user' => 'revision_actor_temp',
412 'actor_rev_user' => 'actor',
414 'fields' => array_merge(
415 $this->getRevisionQueryFields( true ),
416 $this->getContentHandlerQueryFields( 'rev' ),
417 $this->getNewActorQueryFields( 'rev', true ),
418 $this->getNewCommentQueryFields( 'rev' )
421 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
422 'comment_rev_comment'
423 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
424 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
425 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
429 yield
'pre-MCR, page, user' => [
431 'wgContentHandlerUseDB' => true,
432 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
437 'revision', 'page', 'user',
438 'temp_rev_comment' => 'revision_comment_temp',
439 'comment_rev_comment' => 'comment',
440 'temp_rev_user' => 'revision_actor_temp',
441 'actor_rev_user' => 'actor',
443 'fields' => array_merge(
444 $this->getRevisionQueryFields( true ),
445 $this->getContentHandlerQueryFields( 'rev' ),
446 $this->getPageQueryFields(),
447 $this->getUserQueryFields(),
448 $this->getNewActorQueryFields( 'rev', true ),
449 $this->getNewCommentQueryFields( 'rev' )
452 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
453 'user' => [ 'LEFT JOIN', [
454 'actor_rev_user.actor_user != 0',
455 'user_id = actor_rev_user.actor_user',
457 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
458 'comment_rev_comment'
459 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
460 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
461 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
465 yield
'pre-MCR, no model' => [
467 'wgContentHandlerUseDB' => false,
468 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
474 'temp_rev_comment' => 'revision_comment_temp',
475 'comment_rev_comment' => 'comment',
476 'temp_rev_user' => 'revision_actor_temp',
477 'actor_rev_user' => 'actor',
479 'fields' => array_merge(
480 $this->getRevisionQueryFields( true ),
481 $this->getNewActorQueryFields( 'rev', true ),
482 $this->getNewCommentQueryFields( 'rev' )
485 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
486 'comment_rev_comment'
487 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
488 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
489 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
493 yield
'pre-MCR, no model, page' => [
495 'wgContentHandlerUseDB' => false,
496 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
502 'temp_rev_comment' => 'revision_comment_temp',
503 'comment_rev_comment' => 'comment',
504 'temp_rev_user' => 'revision_actor_temp',
505 'actor_rev_user' => 'actor',
507 'fields' => array_merge(
508 $this->getRevisionQueryFields( true ),
509 $this->getPageQueryFields(),
510 $this->getNewActorQueryFields( 'rev', true ),
511 $this->getNewCommentQueryFields( 'rev' )
514 'page' => [ 'JOIN', [ 'page_id = rev_page' ], ],
515 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
516 'comment_rev_comment'
517 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
518 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
519 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
523 yield
'pre-MCR, no model, user' => [
525 'wgContentHandlerUseDB' => false,
526 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
532 'temp_rev_comment' => 'revision_comment_temp',
533 'comment_rev_comment' => 'comment',
534 'temp_rev_user' => 'revision_actor_temp',
535 'actor_rev_user' => 'actor',
537 'fields' => array_merge(
538 $this->getRevisionQueryFields( true ),
539 $this->getUserQueryFields(),
540 $this->getNewActorQueryFields( 'rev', true ),
541 $this->getNewCommentQueryFields( 'rev' )
544 'user' => [ 'LEFT JOIN', [
545 'actor_rev_user.actor_user != 0',
546 'user_id = actor_rev_user.actor_user',
548 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
549 'comment_rev_comment'
550 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
551 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
552 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
556 yield
'pre-MCR, no model, text' => [
558 'wgContentHandlerUseDB' => false,
559 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
565 'temp_rev_comment' => 'revision_comment_temp',
566 'comment_rev_comment' => 'comment',
567 'temp_rev_user' => 'revision_actor_temp',
568 'actor_rev_user' => 'actor',
570 'fields' => array_merge(
571 $this->getRevisionQueryFields( true ),
572 $this->getTextQueryFields(),
573 $this->getNewActorQueryFields( 'rev', true ),
574 $this->getNewCommentQueryFields( 'rev' )
577 'text' => [ 'JOIN', [ 'rev_text_id=old_id' ] ],
578 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
579 'comment_rev_comment'
580 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
581 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
582 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
586 yield
'pre-MCR, no model, text, page, user' => [
588 'wgContentHandlerUseDB' => false,
589 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
591 [ 'text', 'page', 'user' ],
594 'revision', 'page', 'user', 'text',
595 'temp_rev_comment' => 'revision_comment_temp',
596 'comment_rev_comment' => 'comment',
597 'temp_rev_user' => 'revision_actor_temp',
598 'actor_rev_user' => 'actor',
600 'fields' => array_merge(
601 $this->getRevisionQueryFields( true ),
602 $this->getPageQueryFields(),
603 $this->getUserQueryFields(),
604 $this->getTextQueryFields(),
605 $this->getNewActorQueryFields( 'rev', true ),
606 $this->getNewCommentQueryFields( 'rev' )
611 [ 'page_id = rev_page' ],
616 'actor_rev_user.actor_user != 0',
617 'user_id = actor_rev_user.actor_user',
622 [ 'rev_text_id=old_id' ],
624 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
625 'comment_rev_comment'
626 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
627 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
628 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
634 public function provideSlotsQueryInfo() {
635 yield
'MCR, no options' => [
637 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
653 yield
'MCR, role option' => [
655 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
671 'slot_roles' => [ 'LEFT JOIN', [ 'slot_role_id = role_id' ] ],
675 yield
'MCR read-new, content option' => [
677 'wgMultiContentRevisionSchemaMigrationStage'
678 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
697 'content' => [ 'JOIN', [ 'slot_content_id = content_id' ] ],
701 yield
'MCR read-new, content and model options' => [
703 'wgMultiContentRevisionSchemaMigrationStage'
704 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
706 [ 'content', 'model' ],
725 'content' => [ 'JOIN', [ 'slot_content_id = content_id' ] ],
726 'content_models' => [ 'LEFT JOIN', [ 'content_model = model_id' ] ],
731 $db = wfGetDB( DB_REPLICA
);
733 yield
'MCR write-both/read-old' => [
735 'wgMultiContentRevisionSchemaMigrationStage'
736 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
743 'fields' => array_merge(
745 'slot_revision_id' => 'rev_id',
746 'slot_content_id' => 'NULL',
747 'slot_origin' => 'rev_id',
748 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
754 yield
'MCR write-both/read-old, content' => [
756 'wgMultiContentRevisionSchemaMigrationStage'
757 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
764 'fields' => array_merge(
766 'slot_revision_id' => 'rev_id',
767 'slot_content_id' => 'NULL',
768 'slot_origin' => 'rev_id',
769 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
770 'content_size' => 'rev_len',
771 'content_sha1' => 'rev_sha1',
772 'content_address' => $db->buildConcat( [
773 $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
774 'rev_text_id' => 'rev_text_id',
775 'model_name' => 'rev_content_model',
781 yield
'MCR write-both/read-old, content, model, role' => [
783 'wgMultiContentRevisionSchemaMigrationStage'
784 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
786 [ 'content', 'model', 'role' ],
791 'fields' => array_merge(
793 'slot_revision_id' => 'rev_id',
794 'slot_content_id' => 'NULL',
795 'slot_origin' => 'rev_id',
796 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
797 'content_size' => 'rev_len',
798 'content_sha1' => 'rev_sha1',
799 'content_address' => $db->buildConcat( [
800 $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
801 'rev_text_id' => 'rev_text_id',
802 'model_name' => 'rev_content_model',
810 'wgMultiContentRevisionSchemaMigrationStage'
811 => SCHEMA_COMPAT_OLD
,
818 'fields' => array_merge(
820 'slot_revision_id' => 'rev_id',
821 'slot_content_id' => 'NULL',
822 'slot_origin' => 'rev_id',
823 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
829 yield
'pre-MCR, content' => [
831 'wgMultiContentRevisionSchemaMigrationStage'
832 => SCHEMA_COMPAT_OLD
,
839 'fields' => array_merge(
841 'slot_revision_id' => 'rev_id',
842 'slot_content_id' => 'NULL',
843 'slot_origin' => 'rev_id',
844 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
845 'content_size' => 'rev_len',
846 'content_sha1' => 'rev_sha1',
848 $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
849 'rev_text_id' => 'rev_text_id',
850 'model_name' => 'rev_content_model',
859 * @covers Revision::getArchiveQueryInfo
860 * @dataProvider provideArchiveQueryInfo
862 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
863 $this->setMwGlobals( $migrationStageSettings );
865 $queryInfo = Revision
::getArchiveQueryInfo();
866 $this->assertQueryInfoEquals( $expected, $queryInfo );
870 * @covers Revision::getQueryInfo
871 * @dataProvider provideQueryInfo
873 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
874 $this->setMwGlobals( $migrationStageSettings );
876 $queryInfo = Revision
::getQueryInfo( $options );
877 $this->assertQueryInfoEquals( $expected, $queryInfo );
881 * @dataProvider provideQueryInfo
882 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
884 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
885 $this->setMwGlobals( $migrationStageSettings );
887 $store = MediaWikiServices
::getInstance()->getRevisionStore();
889 $queryInfo = $store->getQueryInfo( $options );
890 $this->assertQueryInfoEquals( $expected, $queryInfo );
894 * @dataProvider provideSlotsQueryInfo
895 * @covers \MediaWiki\Revision\RevisionStore::getSlotsQueryInfo
897 public function testRevisionStoreGetSlotsQueryInfo(
898 $migrationStageSettings,
902 $this->setMwGlobals( $migrationStageSettings );
904 $store = MediaWikiServices
::getInstance()->getRevisionStore();
906 $queryInfo = $store->getSlotsQueryInfo( $options );
907 $this->assertQueryInfoEquals( $expected, $queryInfo );
911 * @dataProvider provideArchiveQueryInfo
912 * @covers \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
914 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
915 $this->setMwGlobals( $migrationStageSettings );
917 $store = MediaWikiServices
::getInstance()->getRevisionStore();
919 $queryInfo = $store->getArchiveQueryInfo();
920 $this->assertQueryInfoEquals( $expected, $queryInfo );
923 private function assertQueryInfoEquals( $expected, $queryInfo ) {
924 $this->assertArrayEqualsIgnoringIntKeyOrder(
926 $queryInfo['tables'],
929 $this->assertArrayEqualsIgnoringIntKeyOrder(
931 $queryInfo['fields'],
934 $this->assertArrayEqualsIgnoringIntKeyOrder(
942 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
945 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
946 * split into a string key array and an int key array before assertions occur.
948 * @param array $expected
949 * @param array $actual
951 private function assertArrayEqualsIgnoringIntKeyOrder(
956 $this->objectAssociativeSort( $expected );
957 $this->objectAssociativeSort( $actual );
959 // Separate the int key values from the string key values so that assertion failures are
960 // easier to understand.
961 $expectedIntKeyValues = [];
962 $actualIntKeyValues = [];
964 // Remove all int keys and re add them at the end after sorting by value
965 // This will result in all int keys being in the same order with same ints at the end of
967 foreach ( $expected as $key => $value ) {
968 if ( is_int( $key ) ) {
969 unset( $expected[$key] );
970 $expectedIntKeyValues[] = $value;
973 foreach ( $actual as $key => $value ) {
974 if ( is_int( $key ) ) {
975 unset( $actual[$key] );
976 $actualIntKeyValues[] = $value;
980 $this->objectAssociativeSort( $expected );
981 $this->objectAssociativeSort( $actual );
983 $this->objectAssociativeSort( $expectedIntKeyValues );
984 $this->objectAssociativeSort( $actualIntKeyValues );
986 $this->assertEquals( $expected, $actual, $message );
987 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );