2 namespace MediaWiki\Tests\Revision
;
4 use MediaWiki\MediaWikiServices
;
5 use MediaWiki\Revision\SlotRecord
;
10 * Tests RevisionStore against the post-migration MCR DB schema.
12 * @group RevisionStore
16 class RevisionQueryInfoTest
extends MediaWikiTestCase
{
18 protected function getRevisionQueryFields( $returnTextIdField = true ) {
29 if ( $returnTextIdField ) {
30 $fields[] = 'rev_text_id';
35 protected function getArchiveQueryFields( $returnTextFields = true ) {
49 if ( $returnTextFields ) {
50 $fields[] = 'ar_text_id';
55 protected function getOldCommentQueryFields( $prefix ) {
57 "{$prefix}_comment_text" => "{$prefix}_comment",
58 "{$prefix}_comment_data" => 'NULL',
59 "{$prefix}_comment_cid" => 'NULL',
63 protected function getCompatCommentQueryFields( $prefix ) {
65 "{$prefix}_comment_text"
66 => "COALESCE( comment_{$prefix}_comment.comment_text, {$prefix}_comment )",
67 "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
68 "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
72 protected function getNewCommentQueryFields( $prefix ) {
74 "{$prefix}_comment_text" => "comment_{$prefix}_comment.comment_text",
75 "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
76 "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
80 protected function getOldActorQueryFields( $prefix ) {
82 "{$prefix}_user" => "{$prefix}_user",
83 "{$prefix}_user_text" => "{$prefix}_user_text",
84 "{$prefix}_actor" => 'NULL',
88 protected function getNewActorQueryFields( $prefix, $tmp = false ) {
90 "{$prefix}_user" => "actor_{$prefix}_user.actor_user",
91 "{$prefix}_user_text" => "actor_{$prefix}_user.actor_name",
92 "{$prefix}_actor" => $tmp ?
: "{$prefix}_actor",
96 protected function getNewActorJoins( $prefix ) {
98 "temp_{$prefix}_user" => [
100 "temp_{$prefix}_user.revactor_{$prefix} = {$prefix}_id",
102 "actor_{$prefix}_user" => [
104 "actor_{$prefix}_user.actor_id = temp_{$prefix}_user.revactor_actor",
109 protected function getCompatCommentJoins( $prefix ) {
111 "temp_{$prefix}_comment" => [
113 "temp_{$prefix}_comment.revcomment_{$prefix} = {$prefix}_id",
115 "comment_{$prefix}_comment" => [
117 "comment_{$prefix}_comment.comment_id = temp_{$prefix}_comment.revcomment_comment_id",
122 protected function getTextQueryFields() {
129 protected function getPageQueryFields() {
140 protected function getUserQueryFields() {
146 protected function getContentHandlerQueryFields( $prefix ) {
148 "{$prefix}_content_format",
149 "{$prefix}_content_model",
153 public function provideArchiveQueryInfo() {
154 yield
'MCR, comment, actor' => [
156 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
157 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
158 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
163 'actor_ar_user' => 'actor',
164 'comment_ar_comment' => 'comment',
166 'fields' => array_merge(
167 $this->getArchiveQueryFields( false ),
168 $this->getNewActorQueryFields( 'ar' ),
169 $this->getNewCommentQueryFields( 'ar' )
173 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
174 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
178 yield
'read-new MCR, comment, actor' => [
180 'wgContentHandlerUseDB' => true,
181 'wgMultiContentRevisionSchemaMigrationStage'
182 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
183 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
184 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
189 'actor_ar_user' => 'actor',
190 'comment_ar_comment' => 'comment',
192 'fields' => array_merge(
193 $this->getArchiveQueryFields( false ),
194 $this->getNewActorQueryFields( 'ar' ),
195 $this->getCompatCommentQueryFields( 'ar' )
199 => [ 'LEFT JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
200 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
204 yield
'MCR write-both/read-old' => [
206 'wgContentHandlerUseDB' => true,
207 'wgMultiContentRevisionSchemaMigrationStage'
208 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
209 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
210 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
215 'comment_ar_comment' => 'comment',
217 'fields' => array_merge(
218 $this->getArchiveQueryFields( true ),
219 $this->getContentHandlerQueryFields( 'ar' ),
220 $this->getOldActorQueryFields( 'ar' ),
221 $this->getCompatCommentQueryFields( 'ar' )
225 => [ 'LEFT JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
229 yield
'pre-MCR, no model' => [
231 'wgContentHandlerUseDB' => false,
232 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
233 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
234 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
240 'fields' => array_merge(
241 $this->getArchiveQueryFields( true ),
242 $this->getOldActorQueryFields( 'ar' ),
243 $this->getOldCommentQueryFields( 'ar' )
250 public function provideQueryInfo() {
251 // TODO: more option variations
252 yield
'MCR, page, user, comment, actor' => [
254 'wgContentHandlerUseDB' => true,
255 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
256 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
257 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
265 'temp_rev_user' => 'revision_actor_temp',
266 'temp_rev_comment' => 'revision_comment_temp',
267 'actor_rev_user' => 'actor',
268 'comment_rev_comment' => 'comment',
270 'fields' => array_merge(
271 $this->getRevisionQueryFields( false ),
272 $this->getPageQueryFields(),
273 $this->getUserQueryFields(),
274 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
275 $this->getNewCommentQueryFields( 'rev' )
278 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
281 [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
283 'comment_rev_comment' => [
285 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
287 'actor_rev_user' => [
289 'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
291 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
292 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
296 yield
'MCR read-new, page, user, comment, actor' => [
298 'wgContentHandlerUseDB' => true,
299 'wgMultiContentRevisionSchemaMigrationStage'
300 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
301 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
302 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
310 'temp_rev_user' => 'revision_actor_temp',
311 'temp_rev_comment' => 'revision_comment_temp',
312 'actor_rev_user' => 'actor',
313 'comment_rev_comment' => 'comment',
315 'fields' => array_merge(
316 $this->getRevisionQueryFields( false ),
317 $this->getPageQueryFields(),
318 $this->getUserQueryFields(),
319 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
320 $this->getCompatCommentQueryFields( 'rev' )
322 'joins' => array_merge(
324 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
328 'actor_rev_user.actor_user != 0',
329 'user_id = actor_rev_user.actor_user',
333 $this->getNewActorJoins( 'rev' ),
334 $this->getCompatCommentJoins( 'rev' )
338 yield
'MCR read-new' => [
340 'wgContentHandlerUseDB' => true,
341 'wgMultiContentRevisionSchemaMigrationStage'
342 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
343 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
344 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
352 'temp_rev_user' => 'revision_actor_temp',
353 'temp_rev_comment' => 'revision_comment_temp',
354 'actor_rev_user' => 'actor',
355 'comment_rev_comment' => 'comment',
357 'fields' => array_merge(
358 $this->getRevisionQueryFields( false ),
359 $this->getPageQueryFields(),
360 $this->getUserQueryFields(),
361 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
362 $this->getCompatCommentQueryFields( 'rev' )
364 'joins' => array_merge(
366 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
370 'actor_rev_user.actor_user != 0',
371 'user_id = actor_rev_user.actor_user'
375 $this->getNewActorJoins( 'rev' ),
376 $this->getCompatCommentJoins( 'rev' )
380 yield
'MCR write-both/read-old' => [
382 'wgContentHandlerUseDB' => true,
383 'wgMultiContentRevisionSchemaMigrationStage'
384 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
385 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
386 '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->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
399 $this->getCompatCommentQueryFields( 'rev' )
401 'joins' => array_merge(
402 $this->getCompatCommentJoins( 'rev' )
406 yield
'MCR write-both/read-old, page, user' => [
408 'wgContentHandlerUseDB' => true,
409 'wgMultiContentRevisionSchemaMigrationStage'
410 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
411 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
412 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
420 'temp_rev_comment' => 'revision_comment_temp',
421 'comment_rev_comment' => 'comment',
423 'fields' => array_merge(
424 $this->getRevisionQueryFields( true ),
425 $this->getContentHandlerQueryFields( 'rev' ),
426 $this->getUserQueryFields(),
427 $this->getPageQueryFields(),
428 $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
429 $this->getCompatCommentQueryFields( 'rev' )
431 'joins' => array_merge(
433 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
442 $this->getCompatCommentJoins( 'rev' )
448 'wgContentHandlerUseDB' => true,
449 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
450 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
451 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
455 'tables' => [ 'revision' ],
456 'fields' => array_merge(
457 $this->getRevisionQueryFields( true ),
458 $this->getContentHandlerQueryFields( 'rev' ),
459 $this->getOldActorQueryFields( 'rev' ),
460 $this->getOldCommentQueryFields( 'rev' )
465 yield
'pre-MCR, page, user' => [
467 'wgContentHandlerUseDB' => true,
468 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
469 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
470 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
474 'tables' => [ 'revision', 'page', 'user' ],
475 'fields' => array_merge(
476 $this->getRevisionQueryFields( true ),
477 $this->getContentHandlerQueryFields( 'rev' ),
478 $this->getPageQueryFields(),
479 $this->getUserQueryFields(),
480 $this->getOldActorQueryFields( 'rev' ),
481 $this->getOldCommentQueryFields( 'rev' )
484 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
485 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
489 yield
'pre-MCR, no model' => [
491 'wgContentHandlerUseDB' => false,
492 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
493 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
494 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
498 'tables' => [ 'revision' ],
499 'fields' => array_merge(
500 $this->getRevisionQueryFields( true ),
501 $this->getOldActorQueryFields( 'rev' ),
502 $this->getOldCommentQueryFields( 'rev' )
507 yield
'pre-MCR, no model, page' => [
509 'wgContentHandlerUseDB' => false,
510 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
511 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
512 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
516 'tables' => [ 'revision', 'page' ],
517 'fields' => array_merge(
518 $this->getRevisionQueryFields( true ),
519 $this->getPageQueryFields(),
520 $this->getOldActorQueryFields( 'rev' ),
521 $this->getOldCommentQueryFields( 'rev' )
524 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ], ],
528 yield
'pre-MCR, no model, user' => [
530 'wgContentHandlerUseDB' => false,
531 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
532 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
533 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
537 'tables' => [ 'revision', 'user' ],
538 'fields' => array_merge(
539 $this->getRevisionQueryFields( true ),
540 $this->getUserQueryFields(),
541 $this->getOldActorQueryFields( 'rev' ),
542 $this->getOldCommentQueryFields( 'rev' )
545 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
549 yield
'pre-MCR, no model, text' => [
551 'wgContentHandlerUseDB' => false,
552 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
553 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
554 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
558 'tables' => [ 'revision', 'text' ],
559 'fields' => array_merge(
560 $this->getRevisionQueryFields( true ),
561 $this->getTextQueryFields(),
562 $this->getOldActorQueryFields( 'rev' ),
563 $this->getOldCommentQueryFields( 'rev' )
566 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ],
570 yield
'pre-MCR, no model, text, page, user' => [
572 'wgContentHandlerUseDB' => false,
573 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
574 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
575 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
577 [ 'text', 'page', 'user' ],
580 'revision', 'page', 'user', 'text'
582 'fields' => array_merge(
583 $this->getRevisionQueryFields( true ),
584 $this->getPageQueryFields(),
585 $this->getUserQueryFields(),
586 $this->getTextQueryFields(),
587 $this->getOldActorQueryFields( 'rev' ),
588 $this->getOldCommentQueryFields( 'rev' )
593 [ 'page_id = rev_page' ],
599 'user_id = rev_user',
604 [ 'rev_text_id=old_id' ],
611 public function provideSlotsQueryInfo() {
612 yield
'MCR, no options' => [
614 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
630 yield
'MCR, role option' => [
632 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
648 'slot_roles' => [ 'LEFT JOIN', [ 'slot_role_id = role_id' ] ],
652 yield
'MCR read-new, content option' => [
654 'wgMultiContentRevisionSchemaMigrationStage'
655 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
674 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
678 yield
'MCR read-new, content and model options' => [
680 'wgMultiContentRevisionSchemaMigrationStage'
681 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
683 [ 'content', 'model' ],
702 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
703 'content_models' => [ 'LEFT JOIN', [ 'content_model = model_id' ] ],
708 $db = wfGetDB( DB_REPLICA
);
710 yield
'MCR write-both/read-old' => [
712 'wgMultiContentRevisionSchemaMigrationStage'
713 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
718 'slots' => 'revision',
720 'fields' => array_merge(
722 'slot_revision_id' => 'slots.rev_id',
723 'slot_content_id' => 'NULL',
724 'slot_origin' => 'slots.rev_id',
725 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
731 yield
'MCR write-both/read-old, content' => [
733 'wgMultiContentRevisionSchemaMigrationStage'
734 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
739 'slots' => 'revision',
741 'fields' => array_merge(
743 'slot_revision_id' => 'slots.rev_id',
744 'slot_content_id' => 'NULL',
745 'slot_origin' => 'slots.rev_id',
746 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
747 'content_size' => 'slots.rev_len',
748 'content_sha1' => 'slots.rev_sha1',
749 'content_address' => $db->buildConcat( [
750 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
751 'model_name' => 'slots.rev_content_model',
757 yield
'MCR write-both/read-old, content, model, role' => [
759 'wgMultiContentRevisionSchemaMigrationStage'
760 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
762 [ 'content', 'model', 'role' ],
765 'slots' => 'revision',
767 'fields' => array_merge(
769 'slot_revision_id' => 'slots.rev_id',
770 'slot_content_id' => 'NULL',
771 'slot_origin' => 'slots.rev_id',
772 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
773 'content_size' => 'slots.rev_len',
774 'content_sha1' => 'slots.rev_sha1',
775 'content_address' => $db->buildConcat( [
776 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
777 'model_name' => 'slots.rev_content_model',
785 'wgMultiContentRevisionSchemaMigrationStage'
786 => SCHEMA_COMPAT_OLD
,
791 'slots' => 'revision',
793 'fields' => array_merge(
795 'slot_revision_id' => 'slots.rev_id',
796 'slot_content_id' => 'NULL',
797 'slot_origin' => 'slots.rev_id',
798 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
804 yield
'pre-MCR, content' => [
806 'wgMultiContentRevisionSchemaMigrationStage'
807 => SCHEMA_COMPAT_OLD
,
812 'slots' => 'revision',
814 'fields' => array_merge(
816 'slot_revision_id' => 'slots.rev_id',
817 'slot_content_id' => 'NULL',
818 'slot_origin' => 'slots.rev_id',
819 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
820 'content_size' => 'slots.rev_len',
821 'content_sha1' => 'slots.rev_sha1',
823 $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
824 'model_name' => 'slots.rev_content_model',
832 public function provideSelectFields() {
833 yield
'with model, comment, and actor' => [
835 'wgContentHandlerUseDB' => true,
836 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
837 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
839 'fields' => array_merge(
847 'rev_actor' => 'NULL',
854 $this->getContentHandlerQueryFields( 'rev' ),
856 'rev_comment_old' => 'rev_comment',
857 'rev_comment_pk' => 'rev_id',
861 yield
'no mode, no comment, no actor' => [
863 'wgContentHandlerUseDB' => false,
864 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
865 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
867 'fields' => array_merge(
875 'rev_actor' => 'NULL',
882 $this->getOldCommentQueryFields( 'rev' )
887 public function provideSelectArchiveFields() {
888 yield
'with model, comment, and actor' => [
890 'wgContentHandlerUseDB' => true,
891 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
892 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
894 'fields' => array_merge(
903 'ar_actor' => 'NULL',
910 $this->getContentHandlerQueryFields( 'ar' ),
912 'ar_comment_old' => 'ar_comment',
913 'ar_comment_id' => 'ar_comment_id',
917 yield
'no mode, no comment, no actor' => [
919 'wgContentHandlerUseDB' => false,
920 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
921 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
923 'fields' => array_merge(
932 'ar_actor' => 'NULL',
939 $this->getOldCommentQueryFields( 'ar' )
945 * @dataProvider provideSelectFields
946 * @covers Revision::selectFields
948 public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
949 $this->setMwGlobals( $migrationStageSettings );
950 $this->overrideMwServices();
952 $this->hideDeprecated( 'Revision::selectFields' );
953 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectFields() );
957 * @dataProvider provideSelectArchiveFields
958 * @covers Revision::selectArchiveFields
960 public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
961 $this->setMwGlobals( $migrationStageSettings );
962 $this->overrideMwServices();
964 $this->hideDeprecated( 'Revision::selectArchiveFields' );
965 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectArchiveFields() );
969 * @covers Revision::userJoinCond
971 public function testRevisionUserJoinCond() {
972 $this->hideDeprecated( 'Revision::userJoinCond' );
973 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD
);
974 $this->overrideMwServices();
976 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
977 Revision
::userJoinCond()
982 * @covers Revision::pageJoinCond
984 public function testRevisionPageJoinCond() {
985 $this->hideDeprecated( 'Revision::pageJoinCond' );
987 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
988 Revision
::pageJoinCond()
993 * @covers Revision::selectTextFields
995 public function testRevisionSelectTextFields() {
996 $this->hideDeprecated( 'Revision::selectTextFields' );
998 $this->getTextQueryFields(),
999 Revision
::selectTextFields()
1004 * @covers Revision::selectPageFields
1006 public function testRevisionSelectPageFields() {
1007 $this->hideDeprecated( 'Revision::selectPageFields' );
1008 $this->assertEquals(
1009 $this->getPageQueryFields(),
1010 Revision
::selectPageFields()
1015 * @covers Revision::selectUserFields
1017 public function testRevisionSelectUserFields() {
1018 $this->hideDeprecated( 'Revision::selectUserFields' );
1019 $this->assertEquals(
1020 $this->getUserQueryFields(),
1021 Revision
::selectUserFields()
1026 * @covers Revision::getArchiveQueryInfo
1027 * @dataProvider provideArchiveQueryInfo
1029 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1030 $this->setMwGlobals( $migrationStageSettings );
1031 $this->overrideMwServices();
1033 $queryInfo = Revision
::getArchiveQueryInfo();
1034 $this->assertQueryInfoEquals( $expected, $queryInfo );
1038 * @covers Revision::getQueryInfo
1039 * @dataProvider provideQueryInfo
1041 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1042 $this->setMwGlobals( $migrationStageSettings );
1043 $this->overrideMwServices();
1045 $queryInfo = Revision
::getQueryInfo( $options );
1046 $this->assertQueryInfoEquals( $expected, $queryInfo );
1050 * @dataProvider provideQueryInfo
1051 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
1053 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1054 $this->setMwGlobals( $migrationStageSettings );
1055 $this->overrideMwServices();
1057 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1059 $queryInfo = $store->getQueryInfo( $options );
1060 $this->assertQueryInfoEquals( $expected, $queryInfo );
1064 * @dataProvider provideSlotsQueryInfo
1065 * @covers \MediaWiki\Revision\RevisionStore::getSlotsQueryInfo
1067 public function testRevisionStoreGetSlotsQueryInfo(
1068 $migrationStageSettings,
1072 $this->setMwGlobals( $migrationStageSettings );
1073 $this->overrideMwServices();
1075 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1077 $queryInfo = $store->getSlotsQueryInfo( $options );
1078 $this->assertQueryInfoEquals( $expected, $queryInfo );
1082 * @dataProvider provideArchiveQueryInfo
1083 * @covers \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
1085 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1086 $this->setMwGlobals( $migrationStageSettings );
1087 $this->overrideMwServices();
1089 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1091 $queryInfo = $store->getArchiveQueryInfo();
1092 $this->assertQueryInfoEquals( $expected, $queryInfo );
1095 private function assertQueryInfoEquals( $expected, $queryInfo ) {
1096 $this->assertArrayEqualsIgnoringIntKeyOrder(
1097 $expected['tables'],
1098 $queryInfo['tables'],
1101 $this->assertArrayEqualsIgnoringIntKeyOrder(
1102 $expected['fields'],
1103 $queryInfo['fields'],
1106 $this->assertArrayEqualsIgnoringIntKeyOrder(
1108 $queryInfo['joins'],
1114 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1117 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1118 * split into a string key array and an int key array before assertions occur.
1120 * @param array $expected
1121 * @param array $actual
1123 private function assertArrayEqualsIgnoringIntKeyOrder(
1128 $this->objectAssociativeSort( $expected );
1129 $this->objectAssociativeSort( $actual );
1131 // Separate the int key values from the string key values so that assertion failures are
1132 // easier to understand.
1133 $expectedIntKeyValues = [];
1134 $actualIntKeyValues = [];
1136 // Remove all int keys and re add them at the end after sorting by value
1137 // This will result in all int keys being in the same order with same ints at the end of
1139 foreach ( $expected as $key => $value ) {
1140 if ( is_int( $key ) ) {
1141 unset( $expected[$key] );
1142 $expectedIntKeyValues[] = $value;
1145 foreach ( $actual as $key => $value ) {
1146 if ( is_int( $key ) ) {
1147 unset( $actual[$key] );
1148 $actualIntKeyValues[] = $value;
1152 $this->objectAssociativeSort( $expected );
1153 $this->objectAssociativeSort( $actual );
1155 $this->objectAssociativeSort( $expectedIntKeyValues );
1156 $this->objectAssociativeSort( $actualIntKeyValues );
1158 $this->assertEquals( $expected, $actual, $message );
1159 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );