X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FStorage%2FRevisionStoreTest.php;h=727697cfde2a06ae5eb803c92fe21ad4ab8d119c;hb=138298b397b308ad6e4bfc7088884d90e8ac1e37;hp=61d0512542bf86e014cfb54be7fb832df9046560;hpb=1abed55d47e661b5d9f4c1e894bf0cb5ac00fa5e;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/Storage/RevisionStoreTest.php b/tests/phpunit/includes/Storage/RevisionStoreTest.php index 61d0512542..727697cfde 100644 --- a/tests/phpunit/includes/Storage/RevisionStoreTest.php +++ b/tests/phpunit/includes/Storage/RevisionStoreTest.php @@ -2,17 +2,21 @@ namespace MediaWiki\Tests\Storage; +use CommentStore; use HashBagOStuff; +use InvalidArgumentException; use Language; use MediaWiki\MediaWikiServices; use MediaWiki\Storage\RevisionAccessException; use MediaWiki\Storage\RevisionStore; use MediaWiki\Storage\SqlBlobStore; use MediaWikiTestCase; +use MWException; use Title; use WANObjectCache; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\LoadBalancer; +use Wikimedia\TestingAccessWrapper; class RevisionStoreTest extends MediaWikiTestCase { @@ -28,11 +32,18 @@ class RevisionStoreTest extends MediaWikiTestCase { $blobStore = null, $WANObjectCache = null ) { + global $wgMultiContentRevisionSchemaMigrationStage; + // the migration stage should be irrelevant, since all the tests that interact with + // the database are in RevisionStoreDbTest, not here. + return new RevisionStore( $loadBalancer ?: $this->getMockLoadBalancer(), $blobStore ?: $this->getMockSqlBlobStore(), $WANObjectCache ?: $this->getHashWANObjectCache(), MediaWikiServices::getInstance()->getCommentStore(), + MediaWikiServices::getInstance()->getContentModelStore(), + MediaWikiServices::getInstance()->getSlotRoleStore(), + $wgMultiContentRevisionSchemaMigrationStage, MediaWikiServices::getInstance()->getActorMigration() ); } @@ -61,190 +72,53 @@ class RevisionStoreTest extends MediaWikiTestCase { ->disableOriginalConstructor()->getMock(); } - private function getHashWANObjectCache() { - return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] ); - } - /** - * @covers \MediaWiki\Storage\RevisionStore::getContentHandlerUseDB - * @covers \MediaWiki\Storage\RevisionStore::setContentHandlerUseDB + * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore */ - public function testGetSetContentHandlerDb() { - $store = $this->getRevisionStore(); - $this->assertTrue( $store->getContentHandlerUseDB() ); - $store->setContentHandlerUseDB( false ); - $this->assertFalse( $store->getContentHandlerUseDB() ); - $store->setContentHandlerUseDB( true ); - $this->assertTrue( $store->getContentHandlerUseDB() ); - } - - private function getDefaultQueryFields() { - return [ - 'rev_id', - 'rev_page', - 'rev_text_id', - 'rev_timestamp', - 'rev_minor_edit', - 'rev_deleted', - 'rev_len', - 'rev_parent_id', - 'rev_sha1', - ]; - } - - private function getCommentQueryFields() { - return [ - 'rev_comment_text' => 'rev_comment', - 'rev_comment_data' => 'NULL', - 'rev_comment_cid' => 'NULL', - ]; + private function getMockCommentStore() { + return $this->getMockBuilder( CommentStore::class ) + ->disableOriginalConstructor()->getMock(); } - private function getActorQueryFields() { - return [ - 'rev_user' => 'rev_user', - 'rev_user_text' => 'rev_user_text', - 'rev_actor' => 'NULL', - ]; + private function getHashWANObjectCache() { + return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] ); } - private function getContentHandlerQueryFields() { + public function provideSetContentHandlerUseDB() { return [ - 'rev_content_format', - 'rev_content_model', - ]; - } - - public function provideGetQueryInfo() { - yield [ - true, - [], - [ - 'tables' => [ 'revision' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - $this->getContentHandlerQueryFields() - ), - 'joins' => [], - ] - ]; - yield [ - false, - [], - [ - 'tables' => [ 'revision' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields() - ), - 'joins' => [], - ] - ]; - yield [ - false, - [ 'page' ], - [ - 'tables' => [ 'revision', 'page' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - [ - 'page_namespace', - 'page_title', - 'page_id', - 'page_latest', - 'page_is_redirect', - 'page_len', - ] - ), - 'joins' => [ - 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ], - ], - ] - ]; - yield [ - false, - [ 'user' ], - [ - 'tables' => [ 'revision', 'user' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - [ - 'user_name', - ] - ), - 'joins' => [ - 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ], - ], - ] - ]; - yield [ - false, - [ 'text' ], - [ - 'tables' => [ 'revision', 'text' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - [ - 'old_text', - 'old_flags', - ] - ), - 'joins' => [ - 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ], - ], - ] - ]; - yield [ - true, - [ 'page', 'user', 'text' ], - [ - 'tables' => [ 'revision', 'page', 'user', 'text' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - $this->getContentHandlerQueryFields(), - [ - 'page_namespace', - 'page_title', - 'page_id', - 'page_latest', - 'page_is_redirect', - 'page_len', - 'user_name', - 'old_text', - 'old_flags', - ] - ), - 'joins' => [ - 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ], - 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ], - 'text' => [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ], - ], - ] + // ContentHandlerUseDB can be true of false pre migration + [ false, MIGRATION_OLD, false ], + [ true, MIGRATION_OLD, false ], + // During migration it can not be false + [ false, MIGRATION_WRITE_BOTH, true ], + // But it can be true + [ true, MIGRATION_WRITE_BOTH, false ], ]; } /** - * @dataProvider provideGetQueryInfo - * @covers \MediaWiki\Storage\RevisionStore::getQueryInfo + * @dataProvider provideSetContentHandlerUseDB + * @covers \MediaWiki\Storage\RevisionStore::getContentHandlerUseDB + * @covers \MediaWiki\Storage\RevisionStore::setContentHandlerUseDB */ - public function testGetQueryInfo( $contentHandlerUseDb, $options, $expected ) { - $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD ); - $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', MIGRATION_OLD ); - $this->overrideMwServices(); - $store = $this->getRevisionStore(); - $store->setContentHandlerUseDB( $contentHandlerUseDb ); - $this->assertEquals( $expected, $store->getQueryInfo( $options ) ); + public function testSetContentHandlerUseDB( $contentHandlerDb, $migrationMode, $expectedFail ) { + if ( $expectedFail ) { + $this->setExpectedException( MWException::class ); + } + + $store = new RevisionStore( + $this->getMockLoadBalancer(), + $this->getMockSqlBlobStore(), + $this->getHashWANObjectCache(), + $this->getMockCommentStore(), + MediaWikiServices::getInstance()->getContentModelStore(), + MediaWikiServices::getInstance()->getSlotRoleStore(), + $migrationMode, + MediaWikiServices::getInstance()->getActorMigration() + ); + + $store->setContentHandlerUseDB( $contentHandlerDb ); + $this->assertSame( $contentHandlerDb, $store->getContentHandlerUseDB() ); } public function testGetTitle_successFromPageId() { @@ -529,7 +403,6 @@ class RevisionStoreTest extends MediaWikiTestCase { * @dataProvider provideNewRevisionFromRow_legacyEncoding_applied * * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow - * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29 */ public function testNewRevisionFromRow_legacyEncoding_applied( $encoding, $locale, $row, $text ) { $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); @@ -551,7 +424,6 @@ class RevisionStoreTest extends MediaWikiTestCase { /** * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow - * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromRow_1_29 */ public function testNewRevisionFromRow_legacyEncoding_ignored() { $row = [ @@ -608,4 +480,47 @@ class RevisionStoreTest extends MediaWikiTestCase { return (object)$row; } + public function provideMigrationConstruction() { + return [ + [ MIGRATION_OLD, false ], + [ MIGRATION_WRITE_BOTH, false ], + ]; + } + + /** + * @covers \MediaWiki\Storage\RevisionStore::__construct + * @dataProvider provideMigrationConstruction + */ + public function testMigrationConstruction( $migration, $expectException ) { + if ( $expectException ) { + $this->setExpectedException( InvalidArgumentException::class ); + } + $loadBalancer = $this->getMockLoadBalancer(); + $blobStore = $this->getMockSqlBlobStore(); + $cache = $this->getHashWANObjectCache(); + $commentStore = $this->getMockCommentStore(); + $contentModelStore = MediaWikiServices::getInstance()->getContentModelStore(); + $slotRoleStore = MediaWikiServices::getInstance()->getSlotRoleStore(); + $store = new RevisionStore( + $loadBalancer, + $blobStore, + $cache, + $commentStore, + MediaWikiServices::getInstance()->getContentModelStore(), + MediaWikiServices::getInstance()->getSlotRoleStore(), + $migration, + MediaWikiServices::getInstance()->getActorMigration() + ); + if ( !$expectException ) { + $store = TestingAccessWrapper::newFromObject( $store ); + $this->assertSame( $loadBalancer, $store->loadBalancer ); + $this->assertSame( $blobStore, $store->blobStore ); + $this->assertSame( $cache, $store->cache ); + $this->assertSame( $commentStore, $store->commentStore ); + $this->assertSame( $contentModelStore, $store->contentModelStore ); + $this->assertSame( $slotRoleStore, $store->slotRoleStore ); + $this->assertSame( $migration, $store->mcrMigrationStage ); + } + } + }