Mailing List Archive

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Mock CommentStore in RevisionTest
Addshore has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/406142 )

Change subject: Mock CommentStore in RevisionTest
......................................................................

Mock CommentStore in RevisionTest

Change-Id: I16b00a5514547d93a2308393098e3b363505374e
---
M tests/phpunit/includes/RevisionTest.php
1 file changed, 71 insertions(+), 303 deletions(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/42/406142/1

diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php
index 73d69a5..54d60c4 100644
--- a/tests/phpunit/includes/RevisionTest.php
+++ b/tests/phpunit/includes/RevisionTest.php
@@ -882,6 +882,31 @@
);
}

+ private function overrideCommentStoreFactory() {
+ $mockStore = $this->getMockBuilder( CommentStore::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockStore->expects( $this->any() )
+ ->method( 'getFields' )
+ ->willReturn( [ 'commentstore' => 'fields' ] );
+ $mockStore->expects( $this->any() )
+ ->method( 'getJoin' )
+ ->willReturn( [
+ 'tables' => [ 'commentstore-table' ],
+ 'fields' => [ 'commentstore-field' ],
+ 'joins' => [ 'commentstore-join' ],
+ ] );
+
+ $mockFactory = $this->getMockBuilder( CommentStoreFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockFactory->expects( $this->any() )
+ ->method( 'newForKey' )
+ ->willReturn( $mockStore );
+
+ $this->setService( 'CommentStoreFactory', $mockFactory );
+ }
+
public function provideSelectFields() {
yield [.
true,
@@ -897,9 +922,7 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore' => 'fields',
'rev_content_format',
'rev_content_model',
]
@@ -918,9 +941,7 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore' => 'fields',
]
];
}
@@ -928,12 +949,11 @@
/**
* @dataProvider provideSelectFields
* @covers Revision::selectFields
- * @todo a true unit test would mock CommentStore
*/
public function testSelectFields( $contentHandlerUseDB, $expected ) {
+ $this->overrideCommentStoreFactory();
$this->hideDeprecated( 'Revision::selectFields' );
$this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
- $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
$this->assertEquals( $expected, Revision::selectFields() );
}

@@ -954,9 +974,7 @@
'ar_len',
'ar_parent_id',
'ar_sha1',
- 'ar_comment_text' => 'ar_comment',
- 'ar_comment_data' => 'NULL',
- 'ar_comment_cid' => 'NULL',
+ 'commentstore' => 'fields',
'ar_content_format',
'ar_content_model',
]
@@ -977,9 +995,7 @@
'ar_len',
'ar_parent_id',
'ar_sha1',
- 'ar_comment_text' => 'ar_comment',
- 'ar_comment_data' => 'NULL',
- 'ar_comment_cid' => 'NULL',
+ 'commentstore' => 'fields',
]
];
}
@@ -987,12 +1003,11 @@
/**
* @dataProvider provideSelectArchiveFields
* @covers Revision::selectArchiveFields
- * @todo a true unit test would mock CommentStore
*/
public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
+ $this->overrideCommentStoreFactory();
$this->hideDeprecated( 'Revision::selectArchiveFields' );
$this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
- $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
$this->assertEquals( $expected, Revision::selectArchiveFields() );
}

@@ -1042,13 +1057,15 @@
}

public function provideGetArchiveQueryInfo() {
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [.
+ yield 'wgContentHandlerUseDB false' => [
[
'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[
- 'tables' => [ 'archive' ],
+ 'tables' => [
+ 'archive',
+ 'commentstore-table',
+ ],
'fields' => [.
'ar_id',
'ar_page_id',
@@ -1065,20 +1082,20 @@
'ar_len',
'ar_parent_id',
'ar_sha1',
- 'ar_comment_text' => 'ar_comment',
- 'ar_comment_data' => 'NULL',
- 'ar_comment_cid' => 'NULL',
+ 'commentstore-field'
],
- 'joins' => [],
+ 'joins' => [ 'commentstore-join' ],
]
];
- yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD' => [.
+ yield 'wgContentHandlerUseDB true' => [
[
'wgContentHandlerUseDB' => true,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[
- 'tables' => [ 'archive' ],
+ 'tables' => [
+ 'archive',
+ 'commentstore-table',
+ ],
'fields' => [.
'ar_id',
'ar_page_id',
@@ -1095,127 +1112,11 @@
'ar_len',
'ar_parent_id',
'ar_sha1',
- 'ar_comment_text' => 'ar_comment',
- 'ar_comment_data' => 'NULL',
- 'ar_comment_cid' => 'NULL',
+ 'commentstore-field',
'ar_content_format',
'ar_content_model',
],
- 'joins' => [],
- ]
- ];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH' => [.
- [
- 'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
- ],
- [.
- 'tables' => [
- 'archive',
- 'comment_ar_comment' => 'comment',
- ],
- 'fields' => [.
- 'ar_id',
- 'ar_page_id',
- 'ar_namespace',
- 'ar_title',
- 'ar_rev_id',
- 'ar_text',
- 'ar_text_id',
- 'ar_timestamp',
- 'ar_user_text',
- 'ar_user',
- 'ar_minor_edit',
- 'ar_deleted',
- 'ar_len',
- 'ar_parent_id',
- 'ar_sha1',
- 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
- 'ar_comment_data' => 'comment_ar_comment.comment_data',
- 'ar_comment_cid' => 'comment_ar_comment.comment_id',
- ],
- 'joins' => [.
- 'comment_ar_comment' => [
- 'LEFT JOIN',
- 'comment_ar_comment.comment_id = ar_comment_id',
- ],
- ],
- ]
- ];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW' => [.
- [
- 'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
- ],
- [.
- 'tables' => [
- 'archive',
- 'comment_ar_comment' => 'comment',
- ],
- 'fields' => [.
- 'ar_id',
- 'ar_page_id',
- 'ar_namespace',
- 'ar_title',
- 'ar_rev_id',
- 'ar_text',
- 'ar_text_id',
- 'ar_timestamp',
- 'ar_user_text',
- 'ar_user',
- 'ar_minor_edit',
- 'ar_deleted',
- 'ar_len',
- 'ar_parent_id',
- 'ar_sha1',
- 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
- 'ar_comment_data' => 'comment_ar_comment.comment_data',
- 'ar_comment_cid' => 'comment_ar_comment.comment_id',
- ],
- 'joins' => [.
- 'comment_ar_comment' => [
- 'LEFT JOIN',
- 'comment_ar_comment.comment_id = ar_comment_id',
- ],
- ],
- ]
- ];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [.
- [
- 'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
- ],
- [.
- 'tables' => [
- 'archive',
- 'comment_ar_comment' => 'comment',
- ],
- 'fields' => [.
- 'ar_id',
- 'ar_page_id',
- 'ar_namespace',
- 'ar_title',
- 'ar_rev_id',
- 'ar_text',
- 'ar_text_id',
- 'ar_timestamp',
- 'ar_user_text',
- 'ar_user',
- 'ar_minor_edit',
- 'ar_deleted',
- 'ar_len',
- 'ar_parent_id',
- 'ar_sha1',
- 'ar_comment_text' => 'comment_ar_comment.comment_text',
- 'ar_comment_data' => 'comment_ar_comment.comment_data',
- 'ar_comment_cid' => 'comment_ar_comment.comment_id',
- ],
- 'joins' => [.
- 'comment_ar_comment' => [
- 'JOIN',
- 'comment_ar_comment.comment_id = ar_comment_id',
- ],
- ],
+ 'joins' => [ 'commentstore-join' ],
]
];
}
@@ -1226,11 +1127,11 @@
*/
public function testGetArchiveQueryInfo( $globals, $expected ) {
$this->setMwGlobals( $globals );
+ $this->overrideCommentStoreFactory();

$revisionStore = $this->getRevisionStore();
$revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
$this->setService( 'RevisionStore', $revisionStore );
-
$this->assertEquals(
$expected,
Revision::getArchiveQueryInfo()
@@ -1238,14 +1139,13 @@
}

public function provideGetQueryInfo() {
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts none' => [.
+ yield 'wgContentHandlerUseDB false, opts none' => [
[
'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[],
[
- 'tables' => [ 'revision' ],
+ 'tables' => [ 'revision', 'commentstore-table' ],
'fields' => [.
'rev_id',
'rev_page',
@@ -1258,21 +1158,18 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore-field',
],
- 'joins' => [],
+ 'joins' => [ 'commentstore-join' ],
],
];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts page' => [.
+ yield 'wgContentHandlerUseDB false, opts page' => [
[
'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[ 'page' ],
[
- 'tables' => [ 'revision', 'page' ],
+ 'tables' => [ 'revision', 'commentstore-table', 'page' ],
'fields' => [.
'rev_id',
'rev_page',
@@ -1285,9 +1182,7 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore-field',
'page_namespace',
'page_title',
'page_id',
@@ -1300,17 +1195,17 @@
'INNER JOIN',
[ 'page_id = rev_page' ],
],
+ 'commentstore-join',
],
],
];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts user' => [.
+ yield 'wgContentHandlerUseDB false, opts user' => [
[
'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[ 'user' ],
[
- 'tables' => [ 'revision', 'user' ],
+ 'tables' => [ 'revision', 'commentstore-table', 'user' ],
'fields' => [.
'rev_id',
'rev_page',
@@ -1323,9 +1218,7 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore-field',
'user_name',
],
'joins' => [
@@ -1336,17 +1229,17 @@
'user_id = rev_user',
],
],
+ 'commentstore-join',
],
],
];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts text' => [.
+ yield 'wgContentHandlerUseDB false, opts text' => [
[
'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[ 'text' ],
[
- 'tables' => [ 'revision', 'text' ],
+ 'tables' => [ 'revision', 'commentstore-table', 'text' ],
'fields' => [.
'rev_id',
'rev_page',
@@ -1359,9 +1252,7 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore-field',
'old_text',
'old_flags',
],
@@ -1370,17 +1261,17 @@
'INNER JOIN',
[ 'rev_text_id=old_id' ],
],
+ 'commentstore-join',
],
],
];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts 3' => [.
+ yield 'wgContentHandlerUseDB false, opts 3' => [
[
'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[ 'text', 'page', 'user' ],
[
- 'tables' => [ 'revision', 'page', 'user', 'text' ],
+ 'tables' => [ 'revision', 'commentstore-table', 'page', 'user', 'text' ],
'fields' => [.
'rev_id',
'rev_page',
@@ -1393,9 +1284,7 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore-field',
'page_namespace',
'page_title',
'page_id',
@@ -1422,17 +1311,17 @@
'INNER JOIN',
[ 'rev_text_id=old_id' ],
],
+ 'commentstore-join',
],
],
];
- yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD, opts none' => [.
+ yield 'wgContentHandlerUseDB true, opts none' => [
[
'wgContentHandlerUseDB' => true,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
],
[],
[
- 'tables' => [ 'revision' ],
+ 'tables' => [ 'revision', 'commentstore-table' ],
'fields' => [.
'rev_id',
'rev_page',
@@ -1445,133 +1334,11 @@
'rev_len',
'rev_parent_id',
'rev_sha1',
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
+ 'commentstore-field',
'rev_content_format',
'rev_content_model',
],
- 'joins' => [],
- ],
- ];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH, opts none' => [.
- [
- 'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
- ],
- [],
- [.
- 'tables' => [.
- 'revision',
- 'temp_rev_comment' => 'revision_comment_temp',
- 'comment_rev_comment' => 'comment',
- ],
- 'fields' => [.
- 'rev_id',
- 'rev_page',
- 'rev_text_id',
- 'rev_timestamp',
- 'rev_user_text',
- 'rev_user',
- 'rev_minor_edit',
- 'rev_deleted',
- 'rev_len',
- 'rev_parent_id',
- 'rev_sha1',
- 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
- 'rev_comment_data' => 'comment_rev_comment.comment_data',
- 'rev_comment_cid' => 'comment_rev_comment.comment_id',
- ],
- 'joins' => [.
- 'temp_rev_comment' => [
- 'LEFT JOIN',
- 'temp_rev_comment.revcomment_rev = rev_id',
- ],
- 'comment_rev_comment' => [
- 'LEFT JOIN',
- 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
- ],
- ],
- ],
- ];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW, opts none' => [.
- [
- 'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
- ],
- [],
- [.
- 'tables' => [.
- 'revision',
- 'temp_rev_comment' => 'revision_comment_temp',
- 'comment_rev_comment' => 'comment',
- ],
- 'fields' => [.
- 'rev_id',
- 'rev_page',
- 'rev_text_id',
- 'rev_timestamp',
- 'rev_user_text',
- 'rev_user',
- 'rev_minor_edit',
- 'rev_deleted',
- 'rev_len',
- 'rev_parent_id',
- 'rev_sha1',
- 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
- 'rev_comment_data' => 'comment_rev_comment.comment_data',
- 'rev_comment_cid' => 'comment_rev_comment.comment_id',
- ],
- 'joins' => [.
- 'temp_rev_comment' => [
- 'LEFT JOIN',
- 'temp_rev_comment.revcomment_rev = rev_id',
- ],
- 'comment_rev_comment' => [
- 'LEFT JOIN',
- 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
- ],
- ],
- ],
- ];
- yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW, opts none' => [.
- [
- 'wgContentHandlerUseDB' => false,
- 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
- ],
- [],
- [.
- 'tables' => [.
- 'revision',
- 'temp_rev_comment' => 'revision_comment_temp',
- 'comment_rev_comment' => 'comment',
- ],
- 'fields' => [.
- 'rev_id',
- 'rev_page',
- 'rev_text_id',
- 'rev_timestamp',
- 'rev_user_text',
- 'rev_user',
- 'rev_minor_edit',
- 'rev_deleted',
- 'rev_len',
- 'rev_parent_id',
- 'rev_sha1',
- 'rev_comment_text' => 'comment_rev_comment.comment_text',
- 'rev_comment_data' => 'comment_rev_comment.comment_data',
- 'rev_comment_cid' => 'comment_rev_comment.comment_id',
- ],
- 'joins' => [.
- 'temp_rev_comment' => [
- 'JOIN',
- 'temp_rev_comment.revcomment_rev = rev_id',
- ],
- 'comment_rev_comment' => [
- 'JOIN',
- 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
- ],
- ],
+ 'joins' => [ 'commentstore-join' ],
],
];
}
@@ -1582,6 +1349,7 @@
*/
public function testGetQueryInfo( $globals, $options, $expected ) {
$this->setMwGlobals( $globals );
+ $this->overrideCommentStoreFactory();

$revisionStore = $this->getRevisionStore();
$revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );

--
To view, visit https://gerrit.wikimedia.org/r/406142
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16b00a5514547d93a2308393098e3b363505374e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorewiki@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits