2 namespace MediaWiki\Tests\Storage
;
4 use MediaWiki\MediaWikiServices
;
5 use MediaWiki\Storage\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 getCompatActorQueryFields( $prefix, $tmp = false ) {
98 "{$prefix}_user" => "COALESCE( actor_{$prefix}_user.actor_user, {$prefix}_user )",
99 "{$prefix}_user_text" => "COALESCE( actor_{$prefix}_user.actor_name, {$prefix}_user_text )",
100 "{$prefix}_actor" => $tmp ?
: "{$prefix}_actor",
104 protected function getCompatActorJoins( $prefix ) {
106 "temp_{$prefix}_user" => [
108 "temp_{$prefix}_user.revactor_{$prefix} = {$prefix}_id",
110 "actor_{$prefix}_user" => [
112 "actor_{$prefix}_user.actor_id = temp_{$prefix}_user.revactor_actor",
117 protected function getCompatCommentJoins( $prefix ) {
119 "temp_{$prefix}_comment" => [
121 "temp_{$prefix}_comment.revcomment_{$prefix} = {$prefix}_id",
123 "comment_{$prefix}_comment" => [
125 "comment_{$prefix}_comment.comment_id = temp_{$prefix}_comment.revcomment_comment_id",
130 protected function getTextQueryFields() {
137 protected function getPageQueryFields() {
148 protected function getUserQueryFields() {
154 protected function getContentHandlerQueryFields( $prefix ) {
156 "{$prefix}_content_format",
157 "{$prefix}_content_model",
161 public function provideArchiveQueryInfo() {
162 yield
'MCR, comment, actor' => [
164 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
165 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
166 'wgActorTableSchemaMigrationStage' => MIGRATION_NEW
,
171 'actor_ar_user' => 'actor',
172 'comment_ar_comment' => 'comment',
174 'fields' => array_merge(
175 $this->getArchiveQueryFields( false ),
176 $this->getNewActorQueryFields( 'ar' ),
177 $this->getNewCommentQueryFields( 'ar' )
181 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
182 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
186 yield
'read-new MCR, comment, actor' => [
188 'wgContentHandlerUseDB' => true,
189 'wgMultiContentRevisionSchemaMigrationStage'
190 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
191 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
192 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
197 'actor_ar_user' => 'actor',
198 'comment_ar_comment' => 'comment',
200 'fields' => array_merge(
201 $this->getArchiveQueryFields( false ),
202 $this->getCompatActorQueryFields( 'ar' ),
203 $this->getCompatCommentQueryFields( 'ar' )
207 => [ 'LEFT JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
208 'actor_ar_user' => [ 'LEFT JOIN', 'actor_ar_user.actor_id = ar_actor' ],
212 yield
'MCR write-both/read-old' => [
214 'wgContentHandlerUseDB' => true,
215 'wgMultiContentRevisionSchemaMigrationStage'
216 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
217 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
218 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
223 'actor_ar_user' => 'actor',
224 'comment_ar_comment' => 'comment',
226 'fields' => array_merge(
227 $this->getArchiveQueryFields( true ),
228 $this->getContentHandlerQueryFields( 'ar' ),
229 $this->getCompatActorQueryFields( 'ar' ),
230 $this->getCompatCommentQueryFields( 'ar' )
234 => [ 'LEFT JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
235 'actor_ar_user' => [ 'LEFT JOIN', 'actor_ar_user.actor_id = ar_actor' ],
239 yield
'pre-MCR, no model' => [
241 'wgContentHandlerUseDB' => false,
242 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
243 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
244 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
250 'fields' => array_merge(
251 $this->getArchiveQueryFields( true ),
252 $this->getOldActorQueryFields( 'ar' ),
253 $this->getOldCommentQueryFields( 'ar' )
260 public function provideQueryInfo() {
261 // TODO: more option variations
262 yield
'MCR, page, user, comment, actor' => [
264 'wgContentHandlerUseDB' => true,
265 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
266 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
267 'wgActorTableSchemaMigrationStage' => MIGRATION_NEW
,
275 'temp_rev_user' => 'revision_actor_temp',
276 'temp_rev_comment' => 'revision_comment_temp',
277 'actor_rev_user' => 'actor',
278 'comment_rev_comment' => 'comment',
280 'fields' => array_merge(
281 $this->getRevisionQueryFields( false ),
282 $this->getPageQueryFields(),
283 $this->getUserQueryFields(),
284 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
285 $this->getNewCommentQueryFields( 'rev' )
288 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
291 [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
293 'comment_rev_comment' => [
295 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
297 'actor_rev_user' => [
299 'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
301 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
302 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
306 yield
'MCR read-new, page, user, comment, actor' => [
308 'wgContentHandlerUseDB' => true,
309 'wgMultiContentRevisionSchemaMigrationStage'
310 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
311 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
312 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
320 'temp_rev_user' => 'revision_actor_temp',
321 'temp_rev_comment' => 'revision_comment_temp',
322 'actor_rev_user' => 'actor',
323 'comment_rev_comment' => 'comment',
325 'fields' => array_merge(
326 $this->getRevisionQueryFields( false ),
327 $this->getPageQueryFields(),
328 $this->getUserQueryFields(),
329 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
330 $this->getCompatCommentQueryFields( 'rev' )
332 'joins' => array_merge(
334 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
338 'COALESCE( actor_rev_user.actor_user, rev_user ) != 0',
339 'user_id = COALESCE( actor_rev_user.actor_user, rev_user )'
343 $this->getCompatActorJoins( 'rev' ),
344 $this->getCompatCommentJoins( 'rev' )
348 yield
'MCR read-new' => [
350 'wgContentHandlerUseDB' => true,
351 'wgMultiContentRevisionSchemaMigrationStage'
352 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
353 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
354 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
362 'temp_rev_user' => 'revision_actor_temp',
363 'temp_rev_comment' => 'revision_comment_temp',
364 'actor_rev_user' => 'actor',
365 'comment_rev_comment' => 'comment',
367 'fields' => array_merge(
368 $this->getRevisionQueryFields( false ),
369 $this->getPageQueryFields(),
370 $this->getUserQueryFields(),
371 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
372 $this->getCompatCommentQueryFields( 'rev' )
374 'joins' => array_merge(
376 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
380 'COALESCE( actor_rev_user.actor_user, rev_user ) != 0',
381 'user_id = COALESCE( actor_rev_user.actor_user, rev_user )'
385 $this->getCompatActorJoins( 'rev' ),
386 $this->getCompatCommentJoins( 'rev' )
390 yield
'MCR write-both/read-old' => [
392 'wgContentHandlerUseDB' => true,
393 'wgMultiContentRevisionSchemaMigrationStage'
394 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
395 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
396 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
402 'temp_rev_user' => 'revision_actor_temp',
403 'temp_rev_comment' => 'revision_comment_temp',
404 'actor_rev_user' => 'actor',
405 'comment_rev_comment' => 'comment',
407 'fields' => array_merge(
408 $this->getRevisionQueryFields( true ),
409 $this->getContentHandlerQueryFields( 'rev' ),
410 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
411 $this->getCompatCommentQueryFields( 'rev' )
413 'joins' => array_merge(
414 $this->getCompatActorJoins( 'rev' ),
415 $this->getCompatCommentJoins( 'rev' )
419 yield
'MCR write-both/read-old, page, user' => [
421 'wgContentHandlerUseDB' => true,
422 'wgMultiContentRevisionSchemaMigrationStage'
423 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
424 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
425 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
433 'temp_rev_user' => 'revision_actor_temp',
434 'temp_rev_comment' => 'revision_comment_temp',
435 'actor_rev_user' => 'actor',
436 'comment_rev_comment' => 'comment',
438 'fields' => array_merge(
439 $this->getRevisionQueryFields( true ),
440 $this->getContentHandlerQueryFields( 'rev' ),
441 $this->getUserQueryFields(),
442 $this->getPageQueryFields(),
443 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
444 $this->getCompatCommentQueryFields( 'rev' )
446 'joins' => array_merge(
448 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
452 'COALESCE( actor_rev_user.actor_user, rev_user ) != 0',
453 'user_id = COALESCE( actor_rev_user.actor_user, rev_user )'
457 $this->getCompatActorJoins( 'rev' ),
458 $this->getCompatCommentJoins( 'rev' )
464 'wgContentHandlerUseDB' => true,
465 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
466 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
467 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
471 'tables' => [ 'revision' ],
472 'fields' => array_merge(
473 $this->getRevisionQueryFields( true ),
474 $this->getContentHandlerQueryFields( 'rev' ),
475 $this->getOldActorQueryFields( 'rev' ),
476 $this->getOldCommentQueryFields( 'rev' )
481 yield
'pre-MCR, page, user' => [
483 'wgContentHandlerUseDB' => true,
484 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
485 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
486 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
490 'tables' => [ 'revision', 'page', 'user' ],
491 'fields' => array_merge(
492 $this->getRevisionQueryFields( true ),
493 $this->getContentHandlerQueryFields( 'rev' ),
494 $this->getPageQueryFields(),
495 $this->getUserQueryFields(),
496 $this->getOldActorQueryFields( 'rev' ),
497 $this->getOldCommentQueryFields( 'rev' )
500 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
501 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
505 yield
'pre-MCR, no model' => [
507 'wgContentHandlerUseDB' => false,
508 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
509 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
510 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
514 'tables' => [ 'revision' ],
515 'fields' => array_merge(
516 $this->getRevisionQueryFields( true ),
517 $this->getOldActorQueryFields( 'rev' ),
518 $this->getOldCommentQueryFields( 'rev' )
523 yield
'pre-MCR, no model, page' => [
525 'wgContentHandlerUseDB' => false,
526 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
527 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
528 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
532 'tables' => [ 'revision', 'page' ],
533 'fields' => array_merge(
534 $this->getRevisionQueryFields( true ),
535 $this->getPageQueryFields(),
536 $this->getOldActorQueryFields( 'rev' ),
537 $this->getOldCommentQueryFields( 'rev' )
540 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ], ],
544 yield
'pre-MCR, no model, user' => [
546 'wgContentHandlerUseDB' => false,
547 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
548 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
549 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
553 'tables' => [ 'revision', 'user' ],
554 'fields' => array_merge(
555 $this->getRevisionQueryFields( true ),
556 $this->getUserQueryFields(),
557 $this->getOldActorQueryFields( 'rev' ),
558 $this->getOldCommentQueryFields( 'rev' )
561 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
565 yield
'pre-MCR, no model, text' => [
567 'wgContentHandlerUseDB' => false,
568 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
569 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
570 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
574 'tables' => [ 'revision', 'text' ],
575 'fields' => array_merge(
576 $this->getRevisionQueryFields( true ),
577 $this->getTextQueryFields(),
578 $this->getOldActorQueryFields( 'rev' ),
579 $this->getOldCommentQueryFields( 'rev' )
582 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ],
586 yield
'pre-MCR, no model, text, page, user' => [
588 'wgContentHandlerUseDB' => false,
589 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
590 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
591 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
593 [ 'text', 'page', 'user' ],
596 'revision', 'page', 'user', 'text'
598 'fields' => array_merge(
599 $this->getRevisionQueryFields( true ),
600 $this->getPageQueryFields(),
601 $this->getUserQueryFields(),
602 $this->getTextQueryFields(),
603 $this->getOldActorQueryFields( 'rev' ),
604 $this->getOldCommentQueryFields( 'rev' )
609 [ 'page_id = rev_page' ],
615 'user_id = rev_user',
620 [ 'rev_text_id=old_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' => [ 'INNER 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' => [ 'INNER 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 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
853 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
855 'fields' => array_merge(
863 'rev_actor' => 'NULL',
870 $this->getContentHandlerQueryFields( 'rev' ),
872 'rev_comment_old' => 'rev_comment',
873 'rev_comment_pk' => 'rev_id',
877 yield
'no mode, no comment, no actor' => [
879 'wgContentHandlerUseDB' => false,
880 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
881 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
883 'fields' => array_merge(
891 'rev_actor' => 'NULL',
898 $this->getOldCommentQueryFields( 'rev' )
903 public function provideSelectArchiveFields() {
904 yield
'with model, comment, and actor' => [
906 'wgContentHandlerUseDB' => true,
907 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
908 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
910 'fields' => array_merge(
919 'ar_actor' => 'NULL',
926 $this->getContentHandlerQueryFields( 'ar' ),
928 'ar_comment_old' => 'ar_comment',
929 'ar_comment_id' => 'ar_comment_id',
933 yield
'no mode, no comment, no actor' => [
935 'wgContentHandlerUseDB' => false,
936 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
937 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
939 'fields' => array_merge(
948 'ar_actor' => 'NULL',
955 $this->getOldCommentQueryFields( 'ar' )
961 * @dataProvider provideSelectFields
962 * @covers Revision::selectFields
964 public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
965 $this->setMwGlobals( $migrationStageSettings );
966 $this->overrideMwServices();
968 $this->hideDeprecated( 'Revision::selectFields' );
969 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectFields() );
973 * @dataProvider provideSelectArchiveFields
974 * @covers Revision::selectArchiveFields
976 public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
977 $this->setMwGlobals( $migrationStageSettings );
978 $this->overrideMwServices();
980 $this->hideDeprecated( 'Revision::selectArchiveFields' );
981 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectArchiveFields() );
985 * @covers Revision::userJoinCond
987 public function testRevisionUserJoinCond() {
988 $this->hideDeprecated( 'Revision::userJoinCond' );
989 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_OLD
);
990 $this->overrideMwServices();
992 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
993 Revision
::userJoinCond()
998 * @covers Revision::pageJoinCond
1000 public function testRevisionPageJoinCond() {
1001 $this->hideDeprecated( 'Revision::pageJoinCond' );
1002 $this->assertEquals(
1003 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
1004 Revision
::pageJoinCond()
1009 * @covers Revision::selectTextFields
1011 public function testRevisionSelectTextFields() {
1012 $this->hideDeprecated( 'Revision::selectTextFields' );
1013 $this->assertEquals(
1014 $this->getTextQueryFields(),
1015 Revision
::selectTextFields()
1020 * @covers Revision::selectPageFields
1022 public function testRevisionSelectPageFields() {
1023 $this->hideDeprecated( 'Revision::selectPageFields' );
1024 $this->assertEquals(
1025 $this->getPageQueryFields(),
1026 Revision
::selectPageFields()
1031 * @covers Revision::selectUserFields
1033 public function testRevisionSelectUserFields() {
1034 $this->hideDeprecated( 'Revision::selectUserFields' );
1035 $this->assertEquals(
1036 $this->getUserQueryFields(),
1037 Revision
::selectUserFields()
1042 * @covers Revision::getArchiveQueryInfo
1043 * @dataProvider provideArchiveQueryInfo
1045 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1046 $this->setMwGlobals( $migrationStageSettings );
1047 $this->overrideMwServices();
1049 $queryInfo = Revision
::getArchiveQueryInfo();
1050 $this->assertQueryInfoEquals( $expected, $queryInfo );
1054 * @covers Revision::getQueryInfo
1055 * @dataProvider provideQueryInfo
1057 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1058 $this->setMwGlobals( $migrationStageSettings );
1059 $this->overrideMwServices();
1061 $queryInfo = Revision
::getQueryInfo( $options );
1062 $this->assertQueryInfoEquals( $expected, $queryInfo );
1066 * @dataProvider provideQueryInfo
1067 * @covers \MediaWiki\Storage\RevisionStore::getQueryInfo
1069 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1070 $this->setMwGlobals( $migrationStageSettings );
1071 $this->overrideMwServices();
1073 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1075 $queryInfo = $store->getQueryInfo( $options );
1076 $this->assertQueryInfoEquals( $expected, $queryInfo );
1080 * @dataProvider provideSlotsQueryInfo
1081 * @covers \MediaWiki\Storage\RevisionStore::getSlotsQueryInfo
1083 public function testRevisionStoreGetSlotsQueryInfo(
1084 $migrationStageSettings,
1088 $this->setMwGlobals( $migrationStageSettings );
1089 $this->overrideMwServices();
1091 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1093 $queryInfo = $store->getSlotsQueryInfo( $options );
1094 $this->assertQueryInfoEquals( $expected, $queryInfo );
1098 * @dataProvider provideArchiveQueryInfo
1099 * @covers \MediaWiki\Storage\RevisionStore::getArchiveQueryInfo
1101 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1102 $this->setMwGlobals( $migrationStageSettings );
1103 $this->overrideMwServices();
1105 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1107 $queryInfo = $store->getArchiveQueryInfo();
1108 $this->assertQueryInfoEquals( $expected, $queryInfo );
1111 private function assertQueryInfoEquals( $expected, $queryInfo ) {
1112 $this->assertArrayEqualsIgnoringIntKeyOrder(
1113 $expected['tables'],
1114 $queryInfo['tables'],
1117 $this->assertArrayEqualsIgnoringIntKeyOrder(
1118 $expected['fields'],
1119 $queryInfo['fields'],
1122 $this->assertArrayEqualsIgnoringIntKeyOrder(
1124 $queryInfo['joins'],
1130 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1133 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1134 * split into a string key array and an int key array before assertions occur.
1136 * @param array $expected
1137 * @param array $actual
1139 private function assertArrayEqualsIgnoringIntKeyOrder(
1144 $this->objectAssociativeSort( $expected );
1145 $this->objectAssociativeSort( $actual );
1147 // Separate the int key values from the string key values so that assertion failures are
1148 // easier to understand.
1149 $expectedIntKeyValues = [];
1150 $actualIntKeyValues = [];
1152 // Remove all int keys and re add them at the end after sorting by value
1153 // This will result in all int keys being in the same order with same ints at the end of
1155 foreach ( $expected as $key => $value ) {
1156 if ( is_int( $key ) ) {
1157 unset( $expected[$key] );
1158 $expectedIntKeyValues[] = $value;
1161 foreach ( $actual as $key => $value ) {
1162 if ( is_int( $key ) ) {
1163 unset( $actual[$key] );
1164 $actualIntKeyValues[] = $value;
1168 $this->objectAssociativeSort( $expected );
1169 $this->objectAssociativeSort( $actual );
1171 $this->objectAssociativeSort( $expectedIntKeyValues );
1172 $this->objectAssociativeSort( $actualIntKeyValues );
1174 $this->assertEquals( $expected, $actual, $message );
1175 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );