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 getNewCommentQueryFields( $prefix ) {
57 "{$prefix}_comment_text" => "comment_{$prefix}_comment.comment_text",
58 "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
59 "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
63 protected function getOldActorQueryFields( $prefix ) {
65 "{$prefix}_user" => "{$prefix}_user",
66 "{$prefix}_user_text" => "{$prefix}_user_text",
67 "{$prefix}_actor" => 'NULL',
71 protected function getNewActorQueryFields( $prefix, $tmp = false ) {
73 "{$prefix}_user" => "actor_{$prefix}_user.actor_user",
74 "{$prefix}_user_text" => "actor_{$prefix}_user.actor_name",
75 "{$prefix}_actor" => $tmp ?
: "{$prefix}_actor",
79 protected function getNewActorJoins( $prefix ) {
81 "temp_{$prefix}_user" => [
83 "temp_{$prefix}_user.revactor_{$prefix} = {$prefix}_id",
85 "actor_{$prefix}_user" => [
87 "actor_{$prefix}_user.actor_id = temp_{$prefix}_user.revactor_actor",
92 protected function getTextQueryFields() {
99 protected function getPageQueryFields() {
110 protected function getUserQueryFields() {
116 protected function getContentHandlerQueryFields( $prefix ) {
118 "{$prefix}_content_format",
119 "{$prefix}_content_model",
123 public function provideArchiveQueryInfo() {
124 yield
'MCR, comment, actor' => [
126 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
127 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
132 'actor_ar_user' => 'actor',
133 'comment_ar_comment' => 'comment',
135 'fields' => array_merge(
136 $this->getArchiveQueryFields( false ),
137 $this->getNewActorQueryFields( 'ar' ),
138 $this->getNewCommentQueryFields( 'ar' )
142 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
143 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
147 yield
'read-new MCR, comment, actor' => [
149 'wgContentHandlerUseDB' => true,
150 'wgMultiContentRevisionSchemaMigrationStage'
151 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
152 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
157 'actor_ar_user' => 'actor',
158 'comment_ar_comment' => 'comment',
160 'fields' => array_merge(
161 $this->getArchiveQueryFields( false ),
162 $this->getNewActorQueryFields( 'ar' ),
163 $this->getNewCommentQueryFields( 'ar' )
167 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
168 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
172 yield
'MCR write-both/read-old' => [
174 'wgContentHandlerUseDB' => true,
175 'wgMultiContentRevisionSchemaMigrationStage'
176 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
177 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
182 'comment_ar_comment' => 'comment',
184 'fields' => array_merge(
185 $this->getArchiveQueryFields( true ),
186 $this->getContentHandlerQueryFields( 'ar' ),
187 $this->getOldActorQueryFields( 'ar' ),
188 $this->getNewCommentQueryFields( 'ar' )
192 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
196 yield
'pre-MCR, no model' => [
198 'wgContentHandlerUseDB' => false,
199 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
200 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
205 'comment_ar_comment' => 'comment',
207 'fields' => array_merge(
208 $this->getArchiveQueryFields( true ),
209 $this->getOldActorQueryFields( 'ar' ),
210 $this->getNewCommentQueryFields( 'ar' )
214 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
220 public function provideQueryInfo() {
221 // TODO: more option variations
222 yield
'MCR, page, user, comment, actor' => [
224 'wgContentHandlerUseDB' => true,
225 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
226 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
234 'temp_rev_user' => 'revision_actor_temp',
235 'temp_rev_comment' => 'revision_comment_temp',
236 'actor_rev_user' => 'actor',
237 'comment_rev_comment' => 'comment',
239 'fields' => array_merge(
240 $this->getRevisionQueryFields( false ),
241 $this->getPageQueryFields(),
242 $this->getUserQueryFields(),
243 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
244 $this->getNewCommentQueryFields( 'rev' )
247 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
250 [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
252 'comment_rev_comment' => [
254 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
256 'actor_rev_user' => [
258 'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
260 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
261 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
265 yield
'MCR read-new, page, user, comment, actor' => [
267 'wgContentHandlerUseDB' => true,
268 'wgMultiContentRevisionSchemaMigrationStage'
269 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
270 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
278 'temp_rev_user' => 'revision_actor_temp',
279 'temp_rev_comment' => 'revision_comment_temp',
280 'actor_rev_user' => 'actor',
281 'comment_rev_comment' => 'comment',
283 'fields' => array_merge(
284 $this->getRevisionQueryFields( false ),
285 $this->getPageQueryFields(),
286 $this->getUserQueryFields(),
287 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
288 $this->getNewCommentQueryFields( 'rev' )
290 'joins' => array_merge(
292 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
296 'actor_rev_user.actor_user != 0',
297 'user_id = actor_rev_user.actor_user',
300 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
301 'comment_rev_comment'
302 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
304 $this->getNewActorJoins( 'rev' )
308 yield
'MCR read-new' => [
310 'wgContentHandlerUseDB' => true,
311 'wgMultiContentRevisionSchemaMigrationStage'
312 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
313 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
321 'temp_rev_user' => 'revision_actor_temp',
322 'temp_rev_comment' => 'revision_comment_temp',
323 'actor_rev_user' => 'actor',
324 'comment_rev_comment' => 'comment',
326 'fields' => array_merge(
327 $this->getRevisionQueryFields( false ),
328 $this->getPageQueryFields(),
329 $this->getUserQueryFields(),
330 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
331 $this->getNewCommentQueryFields( 'rev' )
333 'joins' => array_merge(
335 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
339 'actor_rev_user.actor_user != 0',
340 'user_id = actor_rev_user.actor_user'
343 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
344 'comment_rev_comment'
345 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
347 $this->getNewActorJoins( 'rev' )
351 yield
'MCR write-both/read-old' => [
353 'wgContentHandlerUseDB' => true,
354 'wgMultiContentRevisionSchemaMigrationStage'
355 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
356 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
362 'temp_rev_comment' => 'revision_comment_temp',
363 'comment_rev_comment' => 'comment',
365 'fields' => array_merge(
366 $this->getRevisionQueryFields( true ),
367 $this->getContentHandlerQueryFields( 'rev' ),
368 $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
369 $this->getNewCommentQueryFields( 'rev' )
372 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
373 'comment_rev_comment'
374 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
378 yield
'MCR write-both/read-old, page, user' => [
380 'wgContentHandlerUseDB' => true,
381 'wgMultiContentRevisionSchemaMigrationStage'
382 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
383 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
391 'temp_rev_comment' => 'revision_comment_temp',
392 'comment_rev_comment' => 'comment',
394 'fields' => array_merge(
395 $this->getRevisionQueryFields( true ),
396 $this->getContentHandlerQueryFields( 'rev' ),
397 $this->getUserQueryFields(),
398 $this->getPageQueryFields(),
399 $this->getOldActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
400 $this->getNewCommentQueryFields( 'rev' )
402 'joins' => array_merge(
404 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
412 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
413 'comment_rev_comment'
414 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
421 'wgContentHandlerUseDB' => true,
422 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
423 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
429 'temp_rev_comment' => 'revision_comment_temp',
430 'comment_rev_comment' => 'comment',
432 'fields' => array_merge(
433 $this->getRevisionQueryFields( true ),
434 $this->getContentHandlerQueryFields( 'rev' ),
435 $this->getOldActorQueryFields( 'rev' ),
436 $this->getNewCommentQueryFields( 'rev' )
439 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
440 'comment_rev_comment'
441 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
445 yield
'pre-MCR, page, user' => [
447 'wgContentHandlerUseDB' => true,
448 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
449 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
454 'revision', 'page', 'user',
455 'temp_rev_comment' => 'revision_comment_temp',
456 'comment_rev_comment' => 'comment',
458 'fields' => array_merge(
459 $this->getRevisionQueryFields( true ),
460 $this->getContentHandlerQueryFields( 'rev' ),
461 $this->getPageQueryFields(),
462 $this->getUserQueryFields(),
463 $this->getOldActorQueryFields( 'rev' ),
464 $this->getNewCommentQueryFields( 'rev' )
467 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
468 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
469 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
470 'comment_rev_comment'
471 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
475 yield
'pre-MCR, no model' => [
477 'wgContentHandlerUseDB' => false,
478 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
479 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
485 'temp_rev_comment' => 'revision_comment_temp',
486 'comment_rev_comment' => 'comment',
488 'fields' => array_merge(
489 $this->getRevisionQueryFields( true ),
490 $this->getOldActorQueryFields( 'rev' ),
491 $this->getNewCommentQueryFields( 'rev' )
494 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
495 'comment_rev_comment'
496 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
500 yield
'pre-MCR, no model, page' => [
502 'wgContentHandlerUseDB' => false,
503 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
504 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
510 'temp_rev_comment' => 'revision_comment_temp',
511 'comment_rev_comment' => 'comment',
513 'fields' => array_merge(
514 $this->getRevisionQueryFields( true ),
515 $this->getPageQueryFields(),
516 $this->getOldActorQueryFields( 'rev' ),
517 $this->getNewCommentQueryFields( 'rev' )
520 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ], ],
521 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
522 'comment_rev_comment'
523 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
527 yield
'pre-MCR, no model, user' => [
529 'wgContentHandlerUseDB' => false,
530 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
531 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
537 'temp_rev_comment' => 'revision_comment_temp',
538 'comment_rev_comment' => 'comment',
540 'fields' => array_merge(
541 $this->getRevisionQueryFields( true ),
542 $this->getUserQueryFields(),
543 $this->getOldActorQueryFields( 'rev' ),
544 $this->getNewCommentQueryFields( 'rev' )
547 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
548 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
549 'comment_rev_comment'
550 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
554 yield
'pre-MCR, no model, text' => [
556 'wgContentHandlerUseDB' => false,
557 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
558 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
564 'temp_rev_comment' => 'revision_comment_temp',
565 'comment_rev_comment' => 'comment',
567 'fields' => array_merge(
568 $this->getRevisionQueryFields( true ),
569 $this->getTextQueryFields(),
570 $this->getOldActorQueryFields( 'rev' ),
571 $this->getNewCommentQueryFields( 'rev' )
574 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ],
575 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
576 'comment_rev_comment'
577 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
581 yield
'pre-MCR, no model, text, page, user' => [
583 'wgContentHandlerUseDB' => false,
584 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
585 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
587 [ 'text', 'page', 'user' ],
590 'revision', 'page', 'user', 'text',
591 'temp_rev_comment' => 'revision_comment_temp',
592 'comment_rev_comment' => 'comment',
594 'fields' => array_merge(
595 $this->getRevisionQueryFields( true ),
596 $this->getPageQueryFields(),
597 $this->getUserQueryFields(),
598 $this->getTextQueryFields(),
599 $this->getOldActorQueryFields( 'rev' ),
600 $this->getNewCommentQueryFields( 'rev' )
605 [ 'page_id = rev_page' ],
611 'user_id = rev_user',
616 [ 'rev_text_id=old_id' ],
618 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
619 'comment_rev_comment'
620 => [ 'JOIN', 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
626 public function provideSlotsQueryInfo() {
627 yield
'MCR, no options' => [
629 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
645 yield
'MCR, role option' => [
647 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
663 'slot_roles' => [ 'LEFT JOIN', [ 'slot_role_id = role_id' ] ],
667 yield
'MCR read-new, content option' => [
669 'wgMultiContentRevisionSchemaMigrationStage'
670 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
689 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
693 yield
'MCR read-new, content and model options' => [
695 'wgMultiContentRevisionSchemaMigrationStage'
696 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
698 [ 'content', 'model' ],
717 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
718 'content_models' => [ 'LEFT JOIN', [ 'content_model = model_id' ] ],
723 $db = wfGetDB( DB_REPLICA
);
725 yield
'MCR write-both/read-old' => [
727 'wgMultiContentRevisionSchemaMigrationStage'
728 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
733 'slots' => 'revision',
735 'fields' => array_merge(
737 'slot_revision_id' => 'slots.rev_id',
738 'slot_content_id' => 'NULL',
739 'slot_origin' => 'slots.rev_id',
740 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
746 yield
'MCR write-both/read-old, content' => [
748 'wgMultiContentRevisionSchemaMigrationStage'
749 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
754 'slots' => 'revision',
756 'fields' => array_merge(
758 'slot_revision_id' => 'slots.rev_id',
759 'slot_content_id' => 'NULL',
760 'slot_origin' => 'slots.rev_id',
761 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
762 'content_size' => 'slots.rev_len',
763 'content_sha1' => 'slots.rev_sha1',
764 'content_address' => $db->buildConcat( [
765 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
766 'model_name' => 'slots.rev_content_model',
772 yield
'MCR write-both/read-old, content, model, role' => [
774 'wgMultiContentRevisionSchemaMigrationStage'
775 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
777 [ 'content', 'model', 'role' ],
780 'slots' => 'revision',
782 'fields' => array_merge(
784 'slot_revision_id' => 'slots.rev_id',
785 'slot_content_id' => 'NULL',
786 'slot_origin' => 'slots.rev_id',
787 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
788 'content_size' => 'slots.rev_len',
789 'content_sha1' => 'slots.rev_sha1',
790 'content_address' => $db->buildConcat( [
791 $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
792 'model_name' => 'slots.rev_content_model',
800 'wgMultiContentRevisionSchemaMigrationStage'
801 => SCHEMA_COMPAT_OLD
,
806 'slots' => 'revision',
808 'fields' => array_merge(
810 'slot_revision_id' => 'slots.rev_id',
811 'slot_content_id' => 'NULL',
812 'slot_origin' => 'slots.rev_id',
813 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
819 yield
'pre-MCR, content' => [
821 'wgMultiContentRevisionSchemaMigrationStage'
822 => SCHEMA_COMPAT_OLD
,
827 'slots' => 'revision',
829 'fields' => array_merge(
831 'slot_revision_id' => 'slots.rev_id',
832 'slot_content_id' => 'NULL',
833 'slot_origin' => 'slots.rev_id',
834 'role_name' => $db->addQuotes( SlotRecord
::MAIN
),
835 'content_size' => 'slots.rev_len',
836 'content_sha1' => 'slots.rev_sha1',
838 $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] ),
839 'model_name' => 'slots.rev_content_model',
847 public function provideSelectFields() {
848 yield
'with model, comment, and actor' => [
850 'wgContentHandlerUseDB' => true,
851 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
853 'fields' => array_merge(
861 'rev_actor' => 'NULL',
868 $this->getContentHandlerQueryFields( 'rev' ),
870 'rev_comment_pk' => 'rev_id',
874 yield
'no mode, no comment, no actor' => [
876 'wgContentHandlerUseDB' => false,
877 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
879 'fields' => array_merge(
887 'rev_actor' => 'NULL',
893 'rev_comment_pk' => 'rev_id',
899 public function provideSelectArchiveFields() {
900 yield
'with model, comment, and actor' => [
902 'wgContentHandlerUseDB' => true,
903 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
905 'fields' => array_merge(
914 'ar_actor' => 'NULL',
921 $this->getContentHandlerQueryFields( 'ar' ),
923 'ar_comment_id' => 'ar_comment_id',
927 yield
'no mode, no comment, no actor' => [
929 'wgContentHandlerUseDB' => false,
930 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
932 'fields' => array_merge(
941 'ar_actor' => 'NULL',
947 'ar_comment_id' => 'ar_comment_id',
954 * @dataProvider provideSelectFields
955 * @covers Revision::selectFields
957 public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
958 $this->setMwGlobals( $migrationStageSettings );
959 $this->overrideMwServices();
961 $this->hideDeprecated( 'Revision::selectFields' );
962 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectFields() );
966 * @dataProvider provideSelectArchiveFields
967 * @covers Revision::selectArchiveFields
969 public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
970 $this->setMwGlobals( $migrationStageSettings );
971 $this->overrideMwServices();
973 $this->hideDeprecated( 'Revision::selectArchiveFields' );
974 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectArchiveFields() );
978 * @covers Revision::userJoinCond
980 public function testRevisionUserJoinCond() {
981 $this->hideDeprecated( 'Revision::userJoinCond' );
982 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD
);
983 $this->overrideMwServices();
985 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
986 Revision
::userJoinCond()
991 * @covers Revision::pageJoinCond
993 public function testRevisionPageJoinCond() {
994 $this->hideDeprecated( 'Revision::pageJoinCond' );
996 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
997 Revision
::pageJoinCond()
1002 * @covers Revision::selectTextFields
1004 public function testRevisionSelectTextFields() {
1005 $this->hideDeprecated( 'Revision::selectTextFields' );
1006 $this->assertEquals(
1007 $this->getTextQueryFields(),
1008 Revision
::selectTextFields()
1013 * @covers Revision::selectPageFields
1015 public function testRevisionSelectPageFields() {
1016 $this->hideDeprecated( 'Revision::selectPageFields' );
1017 $this->assertEquals(
1018 $this->getPageQueryFields(),
1019 Revision
::selectPageFields()
1024 * @covers Revision::selectUserFields
1026 public function testRevisionSelectUserFields() {
1027 $this->hideDeprecated( 'Revision::selectUserFields' );
1028 $this->assertEquals(
1029 $this->getUserQueryFields(),
1030 Revision
::selectUserFields()
1035 * @covers Revision::getArchiveQueryInfo
1036 * @dataProvider provideArchiveQueryInfo
1038 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1039 $this->setMwGlobals( $migrationStageSettings );
1040 $this->overrideMwServices();
1042 $queryInfo = Revision
::getArchiveQueryInfo();
1043 $this->assertQueryInfoEquals( $expected, $queryInfo );
1047 * @covers Revision::getQueryInfo
1048 * @dataProvider provideQueryInfo
1050 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1051 $this->setMwGlobals( $migrationStageSettings );
1052 $this->overrideMwServices();
1054 $queryInfo = Revision
::getQueryInfo( $options );
1055 $this->assertQueryInfoEquals( $expected, $queryInfo );
1059 * @dataProvider provideQueryInfo
1060 * @covers \MediaWiki\Revision\RevisionStore::getQueryInfo
1062 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1063 $this->setMwGlobals( $migrationStageSettings );
1064 $this->overrideMwServices();
1066 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1068 $queryInfo = $store->getQueryInfo( $options );
1069 $this->assertQueryInfoEquals( $expected, $queryInfo );
1073 * @dataProvider provideSlotsQueryInfo
1074 * @covers \MediaWiki\Revision\RevisionStore::getSlotsQueryInfo
1076 public function testRevisionStoreGetSlotsQueryInfo(
1077 $migrationStageSettings,
1081 $this->setMwGlobals( $migrationStageSettings );
1082 $this->overrideMwServices();
1084 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1086 $queryInfo = $store->getSlotsQueryInfo( $options );
1087 $this->assertQueryInfoEquals( $expected, $queryInfo );
1091 * @dataProvider provideArchiveQueryInfo
1092 * @covers \MediaWiki\Revision\RevisionStore::getArchiveQueryInfo
1094 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1095 $this->setMwGlobals( $migrationStageSettings );
1096 $this->overrideMwServices();
1098 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1100 $queryInfo = $store->getArchiveQueryInfo();
1101 $this->assertQueryInfoEquals( $expected, $queryInfo );
1104 private function assertQueryInfoEquals( $expected, $queryInfo ) {
1105 $this->assertArrayEqualsIgnoringIntKeyOrder(
1106 $expected['tables'],
1107 $queryInfo['tables'],
1110 $this->assertArrayEqualsIgnoringIntKeyOrder(
1111 $expected['fields'],
1112 $queryInfo['fields'],
1115 $this->assertArrayEqualsIgnoringIntKeyOrder(
1117 $queryInfo['joins'],
1123 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1126 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1127 * split into a string key array and an int key array before assertions occur.
1129 * @param array $expected
1130 * @param array $actual
1132 private function assertArrayEqualsIgnoringIntKeyOrder(
1137 $this->objectAssociativeSort( $expected );
1138 $this->objectAssociativeSort( $actual );
1140 // Separate the int key values from the string key values so that assertion failures are
1141 // easier to understand.
1142 $expectedIntKeyValues = [];
1143 $actualIntKeyValues = [];
1145 // Remove all int keys and re add them at the end after sorting by value
1146 // This will result in all int keys being in the same order with same ints at the end of
1148 foreach ( $expected as $key => $value ) {
1149 if ( is_int( $key ) ) {
1150 unset( $expected[$key] );
1151 $expectedIntKeyValues[] = $value;
1154 foreach ( $actual as $key => $value ) {
1155 if ( is_int( $key ) ) {
1156 unset( $actual[$key] );
1157 $actualIntKeyValues[] = $value;
1161 $this->objectAssociativeSort( $expected );
1162 $this->objectAssociativeSort( $actual );
1164 $this->objectAssociativeSort( $expectedIntKeyValues );
1165 $this->objectAssociativeSort( $actualIntKeyValues );
1167 $this->assertEquals( $expected, $actual, $message );
1168 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );