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 getOldActorQueryFields( $prefix ) {
66 "{$prefix}_user" => "{$prefix}_user",
67 "{$prefix}_user_text" => "{$prefix}_user_text",
68 "{$prefix}_actor" => 'NULL',
72 protected function getNewActorQueryFields( $prefix, $tmp = false ) {
74 "{$prefix}_user" => "actor_{$prefix}_user.actor_user",
75 "{$prefix}_user_text" => "actor_{$prefix}_user.actor_name",
76 "{$prefix}_actor" => $tmp ?
: "{$prefix}_actor",
80 protected function getNewActorJoins( $prefix ) {
82 "temp_{$prefix}_user" => [
84 "temp_{$prefix}_user.revactor_{$prefix} = {$prefix}_id",
86 "actor_{$prefix}_user" => [
88 "actor_{$prefix}_user.actor_id = temp_{$prefix}_user.revactor_actor",
93 protected function getTextQueryFields() {
100 protected function getPageQueryFields() {
111 protected function getUserQueryFields() {
117 protected function getContentHandlerQueryFields( $prefix ) {
119 "{$prefix}_content_format",
120 "{$prefix}_content_model",
124 public function provideArchiveQueryInfo() {
125 yield
'MCR, comment, actor' => [
127 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
128 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
133 'actor_ar_user' => 'actor',
134 'comment_ar_comment' => 'comment',
136 'fields' => array_merge(
137 $this->getArchiveQueryFields( false ),
138 $this->getNewActorQueryFields( 'ar' ),
139 $this->getNewCommentQueryFields( 'ar' )
143 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
144 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
148 yield
'read-new MCR, comment, actor' => [
150 'wgContentHandlerUseDB' => true,
151 'wgMultiContentRevisionSchemaMigrationStage'
152 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
153 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
158 'actor_ar_user' => 'actor',
159 'comment_ar_comment' => 'comment',
161 'fields' => array_merge(
162 $this->getArchiveQueryFields( false ),
163 $this->getNewActorQueryFields( 'ar' ),
164 $this->getNewCommentQueryFields( 'ar' )
168 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
169 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
173 yield
'MCR write-both/read-old' => [
175 'wgContentHandlerUseDB' => true,
176 'wgMultiContentRevisionSchemaMigrationStage'
177 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
178 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
183 'comment_ar_comment' => 'comment',
185 'fields' => array_merge(
186 $this->getArchiveQueryFields( true ),
187 $this->getContentHandlerQueryFields( 'ar' ),
188 $this->getOldActorQueryFields( 'ar' ),
189 $this->getNewCommentQueryFields( 'ar' )
193 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
197 yield
'pre-MCR, no model' => [
199 'wgContentHandlerUseDB' => false,
200 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
201 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
206 'comment_ar_comment' => 'comment',
208 'fields' => array_merge(
209 $this->getArchiveQueryFields( true ),
210 $this->getOldActorQueryFields( 'ar' ),
211 $this->getNewCommentQueryFields( 'ar' )
215 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
221 public function provideQueryInfo() {
222 // TODO: more option variations
223 yield
'MCR, page, user, comment, actor' => [
225 'wgContentHandlerUseDB' => true,
226 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
227 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
235 'temp_rev_user' => 'revision_actor_temp',
236 'temp_rev_comment' => 'revision_comment_temp',
237 'actor_rev_user' => 'actor',
238 'comment_rev_comment' => 'comment',
240 'fields' => array_merge(
241 $this->getRevisionQueryFields( false ),
242 $this->getPageQueryFields(),
243 $this->getUserQueryFields(),
244 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
245 $this->getNewCommentQueryFields( 'rev' )
248 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
251 [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
253 'comment_rev_comment' => [
255 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
257 'actor_rev_user' => [
259 'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
261 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
262 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
266 yield
'MCR read-new, page, user, comment, actor' => [
268 'wgContentHandlerUseDB' => true,
269 'wgMultiContentRevisionSchemaMigrationStage'
270 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
271 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
279 'temp_rev_user' => 'revision_actor_temp',
280 'temp_rev_comment' => 'revision_comment_temp',
281 'actor_rev_user' => 'actor',
282 'comment_rev_comment' => 'comment',
284 'fields' => array_merge(
285 $this->getRevisionQueryFields( false ),
286 $this->getPageQueryFields(),
287 $this->getUserQueryFields(),
288 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
289 $this->getNewCommentQueryFields( 'rev' )
291 'joins' => array_merge(
293 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
297 'actor_rev_user.actor_user != 0',
298 'user_id = actor_rev_user.actor_user',
301 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
302 'comment_rev_comment'
303 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
305 $this->getNewActorJoins( 'rev' )
309 yield
'MCR read-new' => [
311 'wgContentHandlerUseDB' => true,
312 'wgMultiContentRevisionSchemaMigrationStage'
313 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
314 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
322 'temp_rev_user' => 'revision_actor_temp',
323 'temp_rev_comment' => 'revision_comment_temp',
324 'actor_rev_user' => 'actor',
325 'comment_rev_comment' => 'comment',
327 'fields' => array_merge(
328 $this->getRevisionQueryFields( false ),
329 $this->getPageQueryFields(),
330 $this->getUserQueryFields(),
331 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
332 $this->getNewCommentQueryFields( 'rev' )
334 'joins' => array_merge(
336 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
340 'actor_rev_user.actor_user != 0',
341 'user_id = actor_rev_user.actor_user'
344 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
345 'comment_rev_comment'
346 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
348 $this->getNewActorJoins( 'rev' )
352 yield
'MCR write-both/read-old' => [
354 'wgContentHandlerUseDB' => true,
355 'wgMultiContentRevisionSchemaMigrationStage'
356 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
357 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
363 'temp_rev_comment' => 'revision_comment_temp',
364 'comment_rev_comment' => 'comment',
366 'fields' => array_merge(
367 $this->getRevisionQueryFields( true ),
368 $this->getContentHandlerQueryFields( 'rev' ),
369 $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
370 $this->getNewCommentQueryFields( 'rev' )
373 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
374 'comment_rev_comment'
375 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
379 yield
'MCR write-both/read-old, page, user' => [
381 'wgContentHandlerUseDB' => true,
382 'wgMultiContentRevisionSchemaMigrationStage'
383 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
384 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
392 'temp_rev_comment' => 'revision_comment_temp',
393 'comment_rev_comment' => 'comment',
395 'fields' => array_merge(
396 $this->getRevisionQueryFields( true ),
397 $this->getContentHandlerQueryFields( 'rev' ),
398 $this->getUserQueryFields(),
399 $this->getPageQueryFields(),
400 $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
401 $this->getNewCommentQueryFields( 'rev' )
403 'joins' => array_merge(
405 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
413 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
414 'comment_rev_comment'
415 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
422 'wgContentHandlerUseDB' => true,
423 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
424 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
430 'temp_rev_comment' => 'revision_comment_temp',
431 'comment_rev_comment' => 'comment',
433 'fields' => array_merge(
434 $this->getRevisionQueryFields( true ),
435 $this->getContentHandlerQueryFields( 'rev' ),
436 $this->getOldActorQueryFields( 'rev' ),
437 $this->getNewCommentQueryFields( 'rev' )
440 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
441 'comment_rev_comment'
442 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
446 yield
'pre-MCR, page, user' => [
448 'wgContentHandlerUseDB' => true,
449 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
450 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
455 'revision', 'page', 'user',
456 'temp_rev_comment' => 'revision_comment_temp',
457 'comment_rev_comment' => 'comment',
459 'fields' => array_merge(
460 $this->getRevisionQueryFields( true ),
461 $this->getContentHandlerQueryFields( 'rev' ),
462 $this->getPageQueryFields(),
463 $this->getUserQueryFields(),
464 $this->getOldActorQueryFields( 'rev' ),
465 $this->getNewCommentQueryFields( 'rev' )
468 'page' => [ 'JOIN', [ 'page_id = rev_page' ] ],
469 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
470 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
471 'comment_rev_comment'
472 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
476 yield
'pre-MCR, no model' => [
478 'wgContentHandlerUseDB' => false,
479 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
480 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
486 'temp_rev_comment' => 'revision_comment_temp',
487 'comment_rev_comment' => 'comment',
489 'fields' => array_merge(
490 $this->getRevisionQueryFields( true ),
491 $this->getOldActorQueryFields( 'rev' ),
492 $this->getNewCommentQueryFields( 'rev' )
495 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
496 'comment_rev_comment'
497 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
501 yield
'pre-MCR, no model, page' => [
503 'wgContentHandlerUseDB' => false,
504 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
505 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
511 'temp_rev_comment' => 'revision_comment_temp',
512 'comment_rev_comment' => 'comment',
514 'fields' => array_merge(
515 $this->getRevisionQueryFields( true ),
516 $this->getPageQueryFields(),
517 $this->getOldActorQueryFields( 'rev' ),
518 $this->getNewCommentQueryFields( 'rev' )
521 'page' => [ 'JOIN', [ 'page_id = rev_page' ], ],
522 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
523 'comment_rev_comment'
524 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
528 yield
'pre-MCR, no model, user' => [
530 'wgContentHandlerUseDB' => false,
531 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
532 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
538 'temp_rev_comment' => 'revision_comment_temp',
539 'comment_rev_comment' => 'comment',
541 'fields' => array_merge(
542 $this->getRevisionQueryFields( true ),
543 $this->getUserQueryFields(),
544 $this->getOldActorQueryFields( 'rev' ),
545 $this->getNewCommentQueryFields( 'rev' )
548 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
549 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
550 'comment_rev_comment'
551 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
555 yield
'pre-MCR, no model, text' => [
557 'wgContentHandlerUseDB' => false,
558 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
559 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
565 'temp_rev_comment' => 'revision_comment_temp',
566 'comment_rev_comment' => 'comment',
568 'fields' => array_merge(
569 $this->getRevisionQueryFields( true ),
570 $this->getTextQueryFields(),
571 $this->getOldActorQueryFields( 'rev' ),
572 $this->getNewCommentQueryFields( 'rev' )
575 'text' => [ 'JOIN', [ 'rev_text_id=old_id' ] ],
576 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
577 'comment_rev_comment'
578 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
582 yield
'pre-MCR, no model, text, page, user' => [
584 'wgContentHandlerUseDB' => false,
585 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
586 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
588 [ 'text', 'page', 'user' ],
591 'revision', 'page', 'user', 'text',
592 'temp_rev_comment' => 'revision_comment_temp',
593 'comment_rev_comment' => 'comment',
595 'fields' => array_merge(
596 $this->getRevisionQueryFields( true ),
597 $this->getPageQueryFields(),
598 $this->getUserQueryFields(),
599 $this->getTextQueryFields(),
600 $this->getOldActorQueryFields( 'rev' ),
601 $this->getNewCommentQueryFields( 'rev' )
606 [ 'page_id = rev_page' ],
612 'user_id = rev_user',
617 [ 'rev_text_id=old_id' ],
619 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
620 'comment_rev_comment'
621 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
627 public function provideSlotsQueryInfo() {
628 yield
'MCR, no options' => [
630 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
646 yield
'MCR, role option' => [
648 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
664 'slot_roles' => [ 'LEFT JOIN', [ 'slot_role_id = role_id' ] ],
668 yield
'MCR read-new, content option' => [
670 'wgMultiContentRevisionSchemaMigrationStage'
671 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
690 'content' => [ 'JOIN', [ 'slot_content_id = content_id' ] ],
694 yield
'MCR read-new, content and model options' => [
696 'wgMultiContentRevisionSchemaMigrationStage'
697 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
699 [ 'content', 'model' ],
718 'content' => [ 'JOIN', [ 'slot_content_id = content_id' ] ],
719 'content_models' => [ 'LEFT JOIN', [ 'content_model = model_id' ] ],
724 $db = wfGetDB( DB_REPLICA
);
726 yield
'MCR write-both/read-old' => [
728 'wgMultiContentRevisionSchemaMigrationStage'
729 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
736 'fields' => array_merge(
738 'slot_revision_id' => 'rev_id',
739 'slot_content_id' => 'NULL',
740 'slot_origin' => 'rev_id',
741 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
747 yield
'MCR write-both/read-old, content' => [
749 'wgMultiContentRevisionSchemaMigrationStage'
750 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
757 'fields' => array_merge(
759 'slot_revision_id' => 'rev_id',
760 'slot_content_id' => 'NULL',
761 'slot_origin' => 'rev_id',
762 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
763 'content_size' => 'rev_len',
764 'content_sha1' => 'rev_sha1',
765 'content_address' => $db->buildConcat( [
766 $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
767 'rev_text_id' => 'rev_text_id',
768 'model_name' => 'rev_content_model',
774 yield
'MCR write-both/read-old, content, model, role' => [
776 'wgMultiContentRevisionSchemaMigrationStage'
777 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
779 [ 'content', 'model', 'role' ],
784 'fields' => array_merge(
786 'slot_revision_id' => 'rev_id',
787 'slot_content_id' => 'NULL',
788 'slot_origin' => 'rev_id',
789 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
790 'content_size' => 'rev_len',
791 'content_sha1' => 'rev_sha1',
792 'content_address' => $db->buildConcat( [
793 $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
794 'rev_text_id' => 'rev_text_id',
795 'model_name' => 'rev_content_model',
803 'wgMultiContentRevisionSchemaMigrationStage'
804 => SCHEMA_COMPAT_OLD
,
811 'fields' => array_merge(
813 'slot_revision_id' => 'rev_id',
814 'slot_content_id' => 'NULL',
815 'slot_origin' => 'rev_id',
816 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
822 yield
'pre-MCR, content' => [
824 'wgMultiContentRevisionSchemaMigrationStage'
825 => SCHEMA_COMPAT_OLD
,
832 'fields' => array_merge(
834 'slot_revision_id' => 'rev_id',
835 'slot_content_id' => 'NULL',
836 'slot_origin' => 'rev_id',
837 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
838 'content_size' => 'rev_len',
839 'content_sha1' => 'rev_sha1',
841 $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'rev_text_id' ] ),
842 'rev_text_id' => 'rev_text_id',
843 'model_name' => 'rev_content_model',
851 public function provideSelectFields() {
852 yield
'with model, comment, and actor' => [
854 'wgContentHandlerUseDB' => true,
855 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
857 'fields' => array_merge(
865 'rev_actor' => 'NULL',
872 $this->getContentHandlerQueryFields( 'rev' ),
874 'rev_comment_pk' => 'rev_id',
878 yield
'no mode, no comment, no actor' => [
880 'wgContentHandlerUseDB' => false,
881 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
883 'fields' => array_merge(
891 'rev_actor' => 'NULL',
897 'rev_comment_pk' => 'rev_id',
903 public function provideSelectArchiveFields() {
904 yield
'with model, comment, and actor' => [
906 'wgContentHandlerUseDB' => true,
907 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
909 'fields' => array_merge(
918 'ar_actor' => 'NULL',
925 $this->getContentHandlerQueryFields( 'ar' ),
927 'ar_comment_id' => 'ar_comment_id',
931 yield
'no mode, no comment, no actor' => [
933 'wgContentHandlerUseDB' => false,
934 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
936 'fields' => array_merge(
945 'ar_actor' => 'NULL',
951 'ar_comment_id' => 'ar_comment_id',
958 * @dataProvider provideSelectFields
959 * @covers Revision::selectFields
961 public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
962 $this->setMwGlobals( $migrationStageSettings );
963 $this->overrideMwServices();
965 $this->hideDeprecated( 'Revision::selectFields' );
966 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectFields() );
970 * @dataProvider provideSelectArchiveFields
971 * @covers Revision::selectArchiveFields
973 public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
974 $this->setMwGlobals( $migrationStageSettings );
975 $this->overrideMwServices();
977 $this->hideDeprecated( 'Revision::selectArchiveFields' );
978 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectArchiveFields() );
982 * @covers Revision::userJoinCond
984 public function testRevisionUserJoinCond() {
985 $this->hideDeprecated( 'Revision::userJoinCond' );
986 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD
);
987 $this->overrideMwServices();
989 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
990 Revision
::userJoinCond()
995 * @covers Revision::pageJoinCond
997 public function testRevisionPageJoinCond() {
998 $this->hideDeprecated( 'Revision::pageJoinCond' );
1000 [ 'JOIN', [ 'page_id = rev_page' ] ],
1001 Revision
::pageJoinCond()
1006 * @covers Revision::selectTextFields
1008 public function testRevisionSelectTextFields() {
1009 $this->hideDeprecated( 'Revision::selectTextFields' );
1010 $this->assertEquals(
1011 $this->getTextQueryFields(),
1012 Revision
::selectTextFields()
1017 * @covers Revision::selectPageFields
1019 public function testRevisionSelectPageFields() {
1020 $this->hideDeprecated( 'Revision::selectPageFields' );
1021 $this->assertEquals(
1022 $this->getPageQueryFields(),
1023 Revision
::selectPageFields()
1028 * @covers Revision::selectUserFields
1030 public function testRevisionSelectUserFields() {
1031 $this->hideDeprecated( 'Revision::selectUserFields' );
1032 $this->assertEquals(
1033 $this->getUserQueryFields(),
1034 Revision
::selectUserFields()
1039 * @covers Revision::getArchiveQueryInfo
1040 * @dataProvider provideArchiveQueryInfo
1042 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1043 $this->setMwGlobals( $migrationStageSettings );
1044 $this->overrideMwServices();
1046 $queryInfo = Revision
::getArchiveQueryInfo();
1047 $this->assertQueryInfoEquals( $expected, $queryInfo );
1051 * @covers Revision::getQueryInfo
1052 * @dataProvider provideQueryInfo
1054 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1055 $this->setMwGlobals( $migrationStageSettings );
1056 $this->overrideMwServices();
1058 $queryInfo = Revision
::getQueryInfo( $options );
1059 $this->assertQueryInfoEquals( $expected, $queryInfo );
1063 * @dataProvider provideQueryInfo
1064 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
1066 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1067 $this->setMwGlobals( $migrationStageSettings );
1068 $this->overrideMwServices();
1070 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1072 $queryInfo = $store->getQueryInfo( $options );
1073 $this->assertQueryInfoEquals( $expected, $queryInfo );
1077 * @dataProvider provideSlotsQueryInfo
1078 * @covers \MediaWiki\Revision\RevisionStore::getSlotsQueryInfo
1080 public function testRevisionStoreGetSlotsQueryInfo(
1081 $migrationStageSettings,
1085 $this->setMwGlobals( $migrationStageSettings );
1086 $this->overrideMwServices();
1088 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1090 $queryInfo = $store->getSlotsQueryInfo( $options );
1091 $this->assertQueryInfoEquals( $expected, $queryInfo );
1095 * @dataProvider provideArchiveQueryInfo
1096 * @covers \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
1098 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1099 $this->setMwGlobals( $migrationStageSettings );
1100 $this->overrideMwServices();
1102 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1104 $queryInfo = $store->getArchiveQueryInfo();
1105 $this->assertQueryInfoEquals( $expected, $queryInfo );
1108 private function assertQueryInfoEquals( $expected, $queryInfo ) {
1109 $this->assertArrayEqualsIgnoringIntKeyOrder(
1110 $expected['tables'],
1111 $queryInfo['tables'],
1114 $this->assertArrayEqualsIgnoringIntKeyOrder(
1115 $expected['fields'],
1116 $queryInfo['fields'],
1119 $this->assertArrayEqualsIgnoringIntKeyOrder(
1121 $queryInfo['joins'],
1127 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1130 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1131 * split into a string key array and an int key array before assertions occur.
1133 * @param array $expected
1134 * @param array $actual
1136 private function assertArrayEqualsIgnoringIntKeyOrder(
1141 $this->objectAssociativeSort( $expected );
1142 $this->objectAssociativeSort( $actual );
1144 // Separate the int key values from the string key values so that assertion failures are
1145 // easier to understand.
1146 $expectedIntKeyValues = [];
1147 $actualIntKeyValues = [];
1149 // Remove all int keys and re add them at the end after sorting by value
1150 // This will result in all int keys being in the same order with same ints at the end of
1152 foreach ( $expected as $key => $value ) {
1153 if ( is_int( $key ) ) {
1154 unset( $expected[$key] );
1155 $expectedIntKeyValues[] = $value;
1158 foreach ( $actual as $key => $value ) {
1159 if ( is_int( $key ) ) {
1160 unset( $actual[$key] );
1161 $actualIntKeyValues[] = $value;
1165 $this->objectAssociativeSort( $expected );
1166 $this->objectAssociativeSort( $actual );
1168 $this->objectAssociativeSort( $expectedIntKeyValues );
1169 $this->objectAssociativeSort( $actualIntKeyValues );
1171 $this->assertEquals( $expected, $actual, $message );
1172 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );