2 namespace MediaWiki\Tests\Storage
;
4 use MediaWiki\MediaWikiServices
;
9 * Tests RevisionStore against the post-migration MCR DB schema.
11 * @group RevisionStore
15 class RevisionQueryInfoTest
extends MediaWikiTestCase
{
17 protected function getRevisionQueryFields( $returnTextIdField = true ) {
28 if ( $returnTextIdField ) {
29 $fields[] = 'rev_text_id';
34 protected function getArchiveQueryFields( $returnTextFields = true ) {
48 if ( $returnTextFields ) {
49 $fields[] = 'ar_text_id';
54 protected function getOldCommentQueryFields( $prefix ) {
56 "{$prefix}_comment_text" => "{$prefix}_comment",
57 "{$prefix}_comment_data" => 'NULL',
58 "{$prefix}_comment_cid" => 'NULL',
62 protected function getCompatCommentQueryFields( $prefix ) {
64 "{$prefix}_comment_text"
65 => "COALESCE( comment_{$prefix}_comment.comment_text, {$prefix}_comment )",
66 "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
67 "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
71 protected function getNewCommentQueryFields( $prefix ) {
73 "{$prefix}_comment_text" => "comment_{$prefix}_comment.comment_text",
74 "{$prefix}_comment_data" => "comment_{$prefix}_comment.comment_data",
75 "{$prefix}_comment_cid" => "comment_{$prefix}_comment.comment_id",
79 protected function getOldActorQueryFields( $prefix ) {
81 "{$prefix}_user" => "{$prefix}_user",
82 "{$prefix}_user_text" => "{$prefix}_user_text",
83 "{$prefix}_actor" => 'NULL',
87 protected function getNewActorQueryFields( $prefix, $tmp = false ) {
89 "{$prefix}_user" => "actor_{$prefix}_user.actor_user",
90 "{$prefix}_user_text" => "actor_{$prefix}_user.actor_name",
91 "{$prefix}_actor" => $tmp ?
: "{$prefix}_actor",
95 protected function getCompatActorQueryFields( $prefix, $tmp = false ) {
97 "{$prefix}_user" => "COALESCE( actor_{$prefix}_user.actor_user, {$prefix}_user )",
98 "{$prefix}_user_text" => "COALESCE( actor_{$prefix}_user.actor_name, {$prefix}_user_text )",
99 "{$prefix}_actor" => $tmp ?
: "{$prefix}_actor",
103 protected function getCompatActorJoins( $prefix ) {
105 "temp_{$prefix}_user" => [
107 "temp_{$prefix}_user.revactor_{$prefix} = {$prefix}_id",
109 "actor_{$prefix}_user" => [
111 "actor_{$prefix}_user.actor_id = temp_{$prefix}_user.revactor_actor",
116 protected function getCompatCommentJoins( $prefix ) {
118 "temp_{$prefix}_comment" => [
120 "temp_{$prefix}_comment.revcomment_{$prefix} = {$prefix}_id",
122 "comment_{$prefix}_comment" => [
124 "comment_{$prefix}_comment.comment_id = temp_{$prefix}_comment.revcomment_comment_id",
129 protected function getTextQueryFields() {
136 protected function getPageQueryFields() {
147 protected function getUserQueryFields() {
153 protected function getContentHandlerQueryFields( $prefix ) {
155 "{$prefix}_content_format",
156 "{$prefix}_content_model",
160 public function provideArchiveQueryInfo() {
161 yield
'MCR, comment, actor' => [
163 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
164 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
165 'wgActorTableSchemaMigrationStage' => MIGRATION_NEW
,
170 'actor_ar_user' => 'actor',
171 'comment_ar_comment' => 'comment',
173 'fields' => array_merge(
174 $this->getArchiveQueryFields( false ),
175 $this->getNewActorQueryFields( 'ar' ),
176 $this->getNewCommentQueryFields( 'ar' )
180 => [ 'JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
181 'actor_ar_user' => [ 'JOIN', 'actor_ar_user.actor_id = ar_actor' ],
185 yield
'read-new MCR, comment, actor' => [
187 'wgContentHandlerUseDB' => true,
188 'wgMultiContentRevisionSchemaMigrationStage'
189 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
190 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
191 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
196 'actor_ar_user' => 'actor',
197 'comment_ar_comment' => 'comment',
199 'fields' => array_merge(
200 $this->getArchiveQueryFields( false ),
201 $this->getCompatActorQueryFields( 'ar' ),
202 $this->getCompatCommentQueryFields( 'ar' )
206 => [ 'LEFT JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
207 'actor_ar_user' => [ 'LEFT JOIN', 'actor_ar_user.actor_id = ar_actor' ],
211 yield
'MCR write-both/read-old' => [
213 'wgContentHandlerUseDB' => true,
214 'wgMultiContentRevisionSchemaMigrationStage'
215 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
216 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
217 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
222 'actor_ar_user' => 'actor',
223 'comment_ar_comment' => 'comment',
225 'fields' => array_merge(
226 $this->getArchiveQueryFields( true ),
227 $this->getContentHandlerQueryFields( 'ar' ),
228 $this->getCompatActorQueryFields( 'ar' ),
229 $this->getCompatCommentQueryFields( 'ar' )
233 => [ 'LEFT JOIN', 'comment_ar_comment.comment_id = ar_comment_id' ],
234 'actor_ar_user' => [ 'LEFT JOIN', 'actor_ar_user.actor_id = ar_actor' ],
238 yield
'pre-MCR, no model' => [
240 'wgContentHandlerUseDB' => false,
241 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
242 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
243 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
249 'fields' => array_merge(
250 $this->getArchiveQueryFields( true ),
251 $this->getOldActorQueryFields( 'ar' ),
252 $this->getOldCommentQueryFields( 'ar' )
259 public function provideQueryInfo() {
260 // TODO: more option variations
261 yield
'MCR, page, user, comment, actor' => [
263 'wgContentHandlerUseDB' => true,
264 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_NEW
,
265 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
266 'wgActorTableSchemaMigrationStage' => MIGRATION_NEW
,
274 'temp_rev_user' => 'revision_actor_temp',
275 'temp_rev_comment' => 'revision_comment_temp',
276 'actor_rev_user' => 'actor',
277 'comment_rev_comment' => 'comment',
279 'fields' => array_merge(
280 $this->getRevisionQueryFields( false ),
281 $this->getPageQueryFields(),
282 $this->getUserQueryFields(),
283 $this->getNewActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
284 $this->getNewCommentQueryFields( 'rev' )
287 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
290 [ 'actor_rev_user.actor_user != 0', 'user_id = actor_rev_user.actor_user' ],
292 'comment_rev_comment' => [
294 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
296 'actor_rev_user' => [
298 'actor_rev_user.actor_id = temp_rev_user.revactor_actor',
300 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
301 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
305 yield
'MCR read-new, page, user, comment, actor' => [
307 'wgContentHandlerUseDB' => true,
308 'wgMultiContentRevisionSchemaMigrationStage'
309 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
310 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
311 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
319 'temp_rev_user' => 'revision_actor_temp',
320 'temp_rev_comment' => 'revision_comment_temp',
321 'actor_rev_user' => 'actor',
322 'comment_rev_comment' => 'comment',
324 'fields' => array_merge(
325 $this->getRevisionQueryFields( false ),
326 $this->getPageQueryFields(),
327 $this->getUserQueryFields(),
328 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
329 $this->getCompatCommentQueryFields( 'rev' )
331 'joins' => array_merge(
333 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
337 'COALESCE( actor_rev_user.actor_user, rev_user ) != 0',
338 'user_id = COALESCE( actor_rev_user.actor_user, rev_user )'
342 $this->getCompatActorJoins( 'rev' ),
343 $this->getCompatCommentJoins( 'rev' )
347 yield
'MCR read-new' => [
349 'wgContentHandlerUseDB' => true,
350 'wgMultiContentRevisionSchemaMigrationStage'
351 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW
,
352 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
353 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
361 'temp_rev_user' => 'revision_actor_temp',
362 'temp_rev_comment' => 'revision_comment_temp',
363 'actor_rev_user' => 'actor',
364 'comment_rev_comment' => 'comment',
366 'fields' => array_merge(
367 $this->getRevisionQueryFields( false ),
368 $this->getPageQueryFields(),
369 $this->getUserQueryFields(),
370 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
371 $this->getCompatCommentQueryFields( 'rev' )
373 'joins' => array_merge(
375 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
379 'COALESCE( actor_rev_user.actor_user, rev_user ) != 0',
380 'user_id = COALESCE( actor_rev_user.actor_user, rev_user )'
384 $this->getCompatActorJoins( 'rev' ),
385 $this->getCompatCommentJoins( 'rev' )
389 yield
'MCR write-both/read-old' => [
391 'wgContentHandlerUseDB' => true,
392 'wgMultiContentRevisionSchemaMigrationStage'
393 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
394 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
395 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
401 'temp_rev_user' => 'revision_actor_temp',
402 'temp_rev_comment' => 'revision_comment_temp',
403 'actor_rev_user' => 'actor',
404 'comment_rev_comment' => 'comment',
406 'fields' => array_merge(
407 $this->getRevisionQueryFields( true ),
408 $this->getContentHandlerQueryFields( 'rev' ),
409 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
410 $this->getCompatCommentQueryFields( 'rev' )
412 'joins' => array_merge(
413 $this->getCompatActorJoins( 'rev' ),
414 $this->getCompatCommentJoins( 'rev' )
418 yield
'MCR write-both/read-old, page, user' => [
420 'wgContentHandlerUseDB' => true,
421 'wgMultiContentRevisionSchemaMigrationStage'
422 => SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD
,
423 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
424 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
432 'temp_rev_user' => 'revision_actor_temp',
433 'temp_rev_comment' => 'revision_comment_temp',
434 'actor_rev_user' => 'actor',
435 'comment_rev_comment' => 'comment',
437 'fields' => array_merge(
438 $this->getRevisionQueryFields( true ),
439 $this->getContentHandlerQueryFields( 'rev' ),
440 $this->getUserQueryFields(),
441 $this->getPageQueryFields(),
442 $this->getCompatActorQueryFields( 'rev', 'temp_rev_user.revactor_actor' ),
443 $this->getCompatCommentQueryFields( 'rev' )
445 'joins' => array_merge(
447 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
451 'COALESCE( actor_rev_user.actor_user, rev_user ) != 0',
452 'user_id = COALESCE( actor_rev_user.actor_user, rev_user )'
456 $this->getCompatActorJoins( 'rev' ),
457 $this->getCompatCommentJoins( 'rev' )
463 'wgContentHandlerUseDB' => true,
464 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
465 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
466 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
470 'tables' => [ 'revision' ],
471 'fields' => array_merge(
472 $this->getRevisionQueryFields( true ),
473 $this->getContentHandlerQueryFields( 'rev' ),
474 $this->getOldActorQueryFields( 'rev' ),
475 $this->getOldCommentQueryFields( 'rev' )
480 yield
'pre-MCR, page, user' => [
482 'wgContentHandlerUseDB' => true,
483 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
484 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
485 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
489 'tables' => [ 'revision', 'page', 'user' ],
490 'fields' => array_merge(
491 $this->getRevisionQueryFields( true ),
492 $this->getContentHandlerQueryFields( 'rev' ),
493 $this->getPageQueryFields(),
494 $this->getUserQueryFields(),
495 $this->getOldActorQueryFields( 'rev' ),
496 $this->getOldCommentQueryFields( 'rev' )
499 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
500 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
504 yield
'pre-MCR, no model' => [
506 'wgContentHandlerUseDB' => false,
507 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
508 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
509 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
513 'tables' => [ 'revision' ],
514 'fields' => array_merge(
515 $this->getRevisionQueryFields( true ),
516 $this->getOldActorQueryFields( 'rev' ),
517 $this->getOldCommentQueryFields( 'rev' )
522 yield
'pre-MCR, no model, page' => [
524 'wgContentHandlerUseDB' => false,
525 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
526 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
527 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
531 'tables' => [ 'revision', 'page' ],
532 'fields' => array_merge(
533 $this->getRevisionQueryFields( true ),
534 $this->getPageQueryFields(),
535 $this->getOldActorQueryFields( 'rev' ),
536 $this->getOldCommentQueryFields( 'rev' )
539 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ], ],
543 yield
'pre-MCR, no model, user' => [
545 'wgContentHandlerUseDB' => false,
546 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
547 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
548 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
552 'tables' => [ 'revision', 'user' ],
553 'fields' => array_merge(
554 $this->getRevisionQueryFields( true ),
555 $this->getUserQueryFields(),
556 $this->getOldActorQueryFields( 'rev' ),
557 $this->getOldCommentQueryFields( 'rev' )
560 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
564 yield
'pre-MCR, no model, text' => [
566 'wgContentHandlerUseDB' => false,
567 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
568 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
569 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
573 'tables' => [ 'revision', 'text' ],
574 'fields' => array_merge(
575 $this->getRevisionQueryFields( true ),
576 $this->getTextQueryFields(),
577 $this->getOldActorQueryFields( 'rev' ),
578 $this->getOldCommentQueryFields( 'rev' )
581 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ],
585 yield
'pre-MCR, no model, text, page, user' => [
587 'wgContentHandlerUseDB' => false,
588 'wgMultiContentRevisionSchemaMigrationStage' => SCHEMA_COMPAT_OLD
,
589 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
590 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
592 [ 'text', 'page', 'user' ],
595 'revision', 'page', 'user', 'text'
597 'fields' => array_merge(
598 $this->getRevisionQueryFields( true ),
599 $this->getPageQueryFields(),
600 $this->getUserQueryFields(),
601 $this->getTextQueryFields(),
602 $this->getOldActorQueryFields( 'rev' ),
603 $this->getOldCommentQueryFields( 'rev' )
608 [ 'page_id = rev_page' ],
614 'user_id = rev_user',
619 [ 'rev_text_id=old_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( '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( '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( '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( '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( '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 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
852 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
854 'fields' => array_merge(
862 'rev_actor' => 'NULL',
869 $this->getContentHandlerQueryFields( 'rev' ),
871 'rev_comment_old' => 'rev_comment',
872 'rev_comment_pk' => 'rev_id',
876 yield
'no mode, no comment, no actor' => [
878 'wgContentHandlerUseDB' => false,
879 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
880 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
882 'fields' => array_merge(
890 'rev_actor' => 'NULL',
897 $this->getOldCommentQueryFields( 'rev' )
902 public function provideSelectArchiveFields() {
903 yield
'with model, comment, and actor' => [
905 'wgContentHandlerUseDB' => true,
906 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
907 'wgActorTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
909 'fields' => array_merge(
918 'ar_actor' => 'NULL',
925 $this->getContentHandlerQueryFields( 'ar' ),
927 'ar_comment_old' => 'ar_comment',
928 'ar_comment_id' => 'ar_comment_id',
932 yield
'no mode, no comment, no actor' => [
934 'wgContentHandlerUseDB' => false,
935 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
936 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD
,
938 'fields' => array_merge(
947 'ar_actor' => 'NULL',
954 $this->getOldCommentQueryFields( 'ar' )
960 * @dataProvider provideSelectFields
961 * @covers Revision::selectFields
963 public function testRevisionSelectFields( $migrationStageSettings, $expected ) {
964 $this->setMwGlobals( $migrationStageSettings );
965 $this->overrideMwServices();
967 $this->hideDeprecated( 'Revision::selectFields' );
968 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectFields() );
972 * @dataProvider provideSelectArchiveFields
973 * @covers Revision::selectArchiveFields
975 public function testRevisionSelectArchiveFields( $migrationStageSettings, $expected ) {
976 $this->setMwGlobals( $migrationStageSettings );
977 $this->overrideMwServices();
979 $this->hideDeprecated( 'Revision::selectArchiveFields' );
980 $this->assertArrayEqualsIgnoringIntKeyOrder( $expected, Revision
::selectArchiveFields() );
984 * @covers Revision::userJoinCond
986 public function testRevisionUserJoinCond() {
987 $this->hideDeprecated( 'Revision::userJoinCond' );
988 $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_OLD
);
989 $this->overrideMwServices();
991 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
992 Revision
::userJoinCond()
997 * @covers Revision::pageJoinCond
999 public function testRevisionPageJoinCond() {
1000 $this->hideDeprecated( 'Revision::pageJoinCond' );
1001 $this->assertEquals(
1002 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
1003 Revision
::pageJoinCond()
1008 * @covers Revision::selectTextFields
1010 public function testRevisionSelectTextFields() {
1011 $this->hideDeprecated( 'Revision::selectTextFields' );
1012 $this->assertEquals(
1013 $this->getTextQueryFields(),
1014 Revision
::selectTextFields()
1019 * @covers Revision::selectPageFields
1021 public function testRevisionSelectPageFields() {
1022 $this->hideDeprecated( 'Revision::selectPageFields' );
1023 $this->assertEquals(
1024 $this->getPageQueryFields(),
1025 Revision
::selectPageFields()
1030 * @covers Revision::selectUserFields
1032 public function testRevisionSelectUserFields() {
1033 $this->hideDeprecated( 'Revision::selectUserFields' );
1034 $this->assertEquals(
1035 $this->getUserQueryFields(),
1036 Revision
::selectUserFields()
1041 * @covers Revision::getArchiveQueryInfo
1042 * @dataProvider provideArchiveQueryInfo
1044 public function testRevisionGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1045 $this->setMwGlobals( $migrationStageSettings );
1046 $this->overrideMwServices();
1048 $queryInfo = Revision
::getArchiveQueryInfo();
1049 $this->assertQueryInfoEquals( $expected, $queryInfo );
1053 * @covers Revision::getQueryInfo
1054 * @dataProvider provideQueryInfo
1056 public function testRevisionGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1057 $this->setMwGlobals( $migrationStageSettings );
1058 $this->overrideMwServices();
1060 $queryInfo = Revision
::getQueryInfo( $options );
1061 $this->assertQueryInfoEquals( $expected, $queryInfo );
1065 * @dataProvider provideQueryInfo
1066 * @covers \MediaWiki\Storage\RevisionStore::getQueryInfo
1068 public function testRevisionStoreGetQueryInfo( $migrationStageSettings, $options, $expected ) {
1069 $this->setMwGlobals( $migrationStageSettings );
1070 $this->overrideMwServices();
1072 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1074 $queryInfo = $store->getQueryInfo( $options );
1075 $this->assertQueryInfoEquals( $expected, $queryInfo );
1079 * @dataProvider provideSlotsQueryInfo
1080 * @covers \MediaWiki\Storage\RevisionStore::getSlotsQueryInfo
1082 public function testRevisionStoreGetSlotsQueryInfo(
1083 $migrationStageSettings,
1087 $this->setMwGlobals( $migrationStageSettings );
1088 $this->overrideMwServices();
1090 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1092 $queryInfo = $store->getSlotsQueryInfo( $options );
1093 $this->assertQueryInfoEquals( $expected, $queryInfo );
1097 * @dataProvider provideArchiveQueryInfo
1098 * @covers \MediaWiki\Storage\RevisionStore::getArchiveQueryInfo
1100 public function testRevisionStoreGetArchiveQueryInfo( $migrationStageSettings, $expected ) {
1101 $this->setMwGlobals( $migrationStageSettings );
1102 $this->overrideMwServices();
1104 $store = MediaWikiServices
::getInstance()->getRevisionStore();
1106 $queryInfo = $store->getArchiveQueryInfo();
1107 $this->assertQueryInfoEquals( $expected, $queryInfo );
1110 private function assertQueryInfoEquals( $expected, $queryInfo ) {
1111 $this->assertArrayEqualsIgnoringIntKeyOrder(
1112 $expected['tables'],
1113 $queryInfo['tables'],
1116 $this->assertArrayEqualsIgnoringIntKeyOrder(
1117 $expected['fields'],
1118 $queryInfo['fields'],
1121 $this->assertArrayEqualsIgnoringIntKeyOrder(
1123 $queryInfo['joins'],
1129 * Assert that the two arrays passed are equal, ignoring the order of the values that integer
1132 * Note: Failures of this assertion can be slightly confusing as the arrays are actually
1133 * split into a string key array and an int key array before assertions occur.
1135 * @param array $expected
1136 * @param array $actual
1138 private function assertArrayEqualsIgnoringIntKeyOrder(
1143 $this->objectAssociativeSort( $expected );
1144 $this->objectAssociativeSort( $actual );
1146 // Separate the int key values from the string key values so that assertion failures are
1147 // easier to understand.
1148 $expectedIntKeyValues = [];
1149 $actualIntKeyValues = [];
1151 // Remove all int keys and re add them at the end after sorting by value
1152 // This will result in all int keys being in the same order with same ints at the end of
1154 foreach ( $expected as $key => $value ) {
1155 if ( is_int( $key ) ) {
1156 unset( $expected[$key] );
1157 $expectedIntKeyValues[] = $value;
1160 foreach ( $actual as $key => $value ) {
1161 if ( is_int( $key ) ) {
1162 unset( $actual[$key] );
1163 $actualIntKeyValues[] = $value;
1167 $this->objectAssociativeSort( $expected );
1168 $this->objectAssociativeSort( $actual );
1170 $this->objectAssociativeSort( $expectedIntKeyValues );
1171 $this->objectAssociativeSort( $actualIntKeyValues );
1173 $this->assertEquals( $expected, $actual, $message );
1174 $this->assertEquals( $expectedIntKeyValues, $actualIntKeyValues, $message );