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
,
734 'slots' => 'revision',
736 'fields' => array_merge(
738 'slot_revision_id' => 'slots.rev_id',
739 'slot_content_id' => 'NULL',
740 'slot_origin' => 'slots.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
,
755 'slots' => 'revision',
757 'fields' => array_merge(
759 'slot_revision_id' => 'slots.rev_id',
760 'slot_content_id' => 'NULL',
761 'slot_origin' => 'slots.rev_id',
762 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
763 'content_size' => 'slots.rev_len',
764 'content_sha1' => 'slots.rev_sha1',
765 'content_address' => $db->buildConcat( [
766 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
767 'model_name' => 'slots.rev_content_model',
773 yield
'MCR write-both/read-old, content, model, role' => [
775 'wgMultiContentRevisionSchemaMigrationStage'
776 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
778 [ 'content', 'model', 'role' ],
781 'slots' => 'revision',
783 'fields' => array_merge(
785 'slot_revision_id' => 'slots.rev_id',
786 'slot_content_id' => 'NULL',
787 'slot_origin' => 'slots.rev_id',
788 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
789 'content_size' => 'slots.rev_len',
790 'content_sha1' => 'slots.rev_sha1',
791 'content_address' => $db->buildConcat( [
792 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
793 'model_name' => 'slots.rev_content_model',
801 'wgMultiContentRevisionSchemaMigrationStage'
802 => SCHEMA_COMPAT_OLD
,
807 'slots' => 'revision',
809 'fields' => array_merge(
811 'slot_revision_id' => 'slots.rev_id',
812 'slot_content_id' => 'NULL',
813 'slot_origin' => 'slots.rev_id',
814 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
820 yield
'pre-MCR, content' => [
822 'wgMultiContentRevisionSchemaMigrationStage'
823 => SCHEMA_COMPAT_OLD
,
828 'slots' => 'revision',
830 'fields' => array_merge(
832 'slot_revision_id' => 'slots.rev_id',
833 'slot_content_id' => 'NULL',
834 'slot_origin' => 'slots.rev_id',
835 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
836 'content_size' => 'slots.rev_len',
837 'content_sha1' => 'slots.rev_sha1',
839 $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
840 'model_name' => 'slots.rev_content_model',
848 public function provideSelectFields() {
849 yield
'with model, comment, and actor' => [
851 'wgContentHandlerUseDB' => true,
852 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
854 'fields' => array_merge(
862 'rev_actor' => 'NULL',
869 $this->getContentHandlerQueryFields( 'rev' ),
871 'rev_comment_pk' => 'rev_id',
875 yield
'no mode, no comment, no actor' => [
877 'wgContentHandlerUseDB' => false,
878 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
880 'fields' => array_merge(
888 'rev_actor' => 'NULL',
894 'rev_comment_pk' => 'rev_id',
900 public function provideSelectArchiveFields() {
901 yield
'with model, comment, and actor' => [
903 'wgContentHandlerUseDB' => true,
904 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
906 'fields' => array_merge(
915 'ar_actor' => 'NULL',
922 $this->getContentHandlerQueryFields( 'ar' ),
924 'ar_comment_id' => 'ar_comment_id',
928 yield
'no mode, no comment, no actor' => [
930 'wgContentHandlerUseDB' => false,
931 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
933 'fields' => array_merge(
942 'ar_actor' => 'NULL',
948 'ar_comment_id' => 'ar_comment_id',
955 * @dataProvider provideSelectFields
956 * @covers Revision::selectFields
958 public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
959 $this->setMwGlobals( $migrationStageSettings );
960 $this->overrideMwServices();
962 $this->hideDeprecated( 'Revision::selectFields' );
963 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectFields() );
967 * @dataProvider provideSelectArchiveFields
968 * @covers Revision::selectArchiveFields
970 public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
971 $this->setMwGlobals( $migrationStageSettings );
972 $this->overrideMwServices();
974 $this->hideDeprecated( 'Revision::selectArchiveFields' );
975 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectArchiveFields() );
979 * @covers Revision::userJoinCond
981 public function testRevisionUserJoinCond() {
982 $this->hideDeprecated( 'Revision::userJoinCond' );
983 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD
);
984 $this->overrideMwServices();
986 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
987 Revision
::userJoinCond()
992 * @covers Revision::pageJoinCond
994 public function testRevisionPageJoinCond() {
995 $this->hideDeprecated( 'Revision::pageJoinCond' );
997 [ 'JOIN', [ 'page_id = rev_page' ] ],
998 Revision
::pageJoinCond()
1003 * @covers Revision::selectTextFields
1005 public function testRevisionSelectTextFields() {
1006 $this->hideDeprecated( 'Revision::selectTextFields' );
1007 $this->assertEquals(
1008 $this->getTextQueryFields(),
1009 Revision
::selectTextFields()
1014 * @covers Revision::selectPageFields
1016 public function testRevisionSelectPageFields() {
1017 $this->hideDeprecated( 'Revision::selectPageFields' );
1018 $this->assertEquals(
1019 $this->getPageQueryFields(),
1020 Revision
::selectPageFields()
1025 * @covers Revision::selectUserFields
1027 public function testRevisionSelectUserFields() {
1028 $this->hideDeprecated( 'Revision::selectUserFields' );
1029 $this->assertEquals(
1030 $this->getUserQueryFields(),
1031 Revision
::selectUserFields()
1036 * @covers Revision::getArchiveQueryInfo
1037 * @dataProvider provideArchiveQueryInfo
1039 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1040 $this->setMwGlobals( $migrationStageSettings );
1041 $this->overrideMwServices();
1043 $queryInfo = Revision
::getArchiveQueryInfo();
1044 $this->assertQueryInfoEquals( $expected, $queryInfo );
1048 * @covers Revision::getQueryInfo
1049 * @dataProvider provideQueryInfo
1051 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1052 $this->setMwGlobals( $migrationStageSettings );
1053 $this->overrideMwServices();
1055 $queryInfo = Revision
::getQueryInfo( $options );
1056 $this->assertQueryInfoEquals( $expected, $queryInfo );
1060 * @dataProvider provideQueryInfo
1061 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
1063 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1064 $this->setMwGlobals( $migrationStageSettings );
1065 $this->overrideMwServices();
1067 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1069 $queryInfo = $store->getQueryInfo( $options );
1070 $this->assertQueryInfoEquals( $expected, $queryInfo );
1074 * @dataProvider provideSlotsQueryInfo
1075 * @covers \MediaWiki\Revision\RevisionStore::getSlotsQueryInfo
1077 public function testRevisionStoreGetSlotsQueryInfo(
1078 $migrationStageSettings,
1082 $this->setMwGlobals( $migrationStageSettings );
1083 $this->overrideMwServices();
1085 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1087 $queryInfo = $store->getSlotsQueryInfo( $options );
1088 $this->assertQueryInfoEquals( $expected, $queryInfo );
1092 * @dataProvider provideArchiveQueryInfo
1093 * @covers \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
1095 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1096 $this->setMwGlobals( $migrationStageSettings );
1097 $this->overrideMwServices();
1099 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1101 $queryInfo = $store->getArchiveQueryInfo();
1102 $this->assertQueryInfoEquals( $expected, $queryInfo );
1105 private function assertQueryInfoEquals( $expected, $queryInfo ) {
1106 $this->assertArrayEqualsIgnoringIntKeyOrder(
1107 $expected['tables'],
1108 $queryInfo['tables'],
1111 $this->assertArrayEqualsIgnoringIntKeyOrder(
1112 $expected['fields'],
1113 $queryInfo['fields'],
1116 $this->assertArrayEqualsIgnoringIntKeyOrder(
1118 $queryInfo['joins'],
1124 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1127 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1128 * split into a string key array and an int key array before assertions occur.
1130 * @param array $expected
1131 * @param array $actual
1133 private function assertArrayEqualsIgnoringIntKeyOrder(
1138 $this->objectAssociativeSort( $expected );
1139 $this->objectAssociativeSort( $actual );
1141 // Separate the int key values from the string key values so that assertion failures are
1142 // easier to understand.
1143 $expectedIntKeyValues = [];
1144 $actualIntKeyValues = [];
1146 // Remove all int keys and re add them at the end after sorting by value
1147 // This will result in all int keys being in the same order with same ints at the end of
1149 foreach ( $expected as $key => $value ) {
1150 if ( is_int( $key ) ) {
1151 unset( $expected[$key] );
1152 $expectedIntKeyValues[] = $value;
1155 foreach ( $actual as $key => $value ) {
1156 if ( is_int( $key ) ) {
1157 unset( $actual[$key] );
1158 $actualIntKeyValues[] = $value;
1162 $this->objectAssociativeSort( $expected );
1163 $this->objectAssociativeSort( $actual );
1165 $this->objectAssociativeSort( $expectedIntKeyValues );
1166 $this->objectAssociativeSort( $actualIntKeyValues );
1168 $this->assertEquals( $expected, $actual, $message );
1169 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );