X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fwatcheditem%2FWatchedItemQueryServiceUnitTest.php;h=5e36e94c87b5d11276fc57f0dbee48e115bfc55b;hp=ef2486d15220ee1907ac8b3da51d3d2322f4b518;hb=d9c25c2f4776832c0fe3d7be091fd7f776991122;hpb=fe4b09380562976aea9f06e59d342fff8d91b026 diff --git a/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php b/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php index ef2486d152..5e36e94c87 100644 --- a/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php +++ b/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php @@ -1,15 +1,46 @@ 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' ], + ] ); + return $mockStore; + } + + /** + * @param PHPUnit_Framework_MockObject_MockObject|Database $mockDb + * @return WatchedItemQueryService + */ + private function newService( $mockDb ) { + return new WatchedItemQueryService( + $this->getMockLoadBalancer( $mockDb ), + $this->getMockCommentStore() + ); + } + /** * @return PHPUnit_Framework_MockObject_MockObject|Database */ @@ -232,7 +263,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ] ), ] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $startFrom = null; @@ -392,7 +423,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { $startFrom = [ '20160203123456', 42 ]; } ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); TestingAccessWrapper::newFromObject( $queryService )->extensions = [ $mockExtension ]; $startFrom = null; @@ -477,58 +508,11 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { [ [ 'includeFields' => [ WatchedItemQueryService::INCLUDE_COMMENT ] ], null, + [ 'commentstore' => 'table' ], + [ 'commentstore' => 'field' ], [], - [ - 'rc_comment_text' => 'rc_comment', - 'rc_comment_data' => 'NULL', - 'rc_comment_cid' => 'NULL', - ], - [], - [], - [], - [ 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD ], - ], - [ - [ 'includeFields' => [ WatchedItemQueryService::INCLUDE_COMMENT ] ], - null, - [ 'comment_rc_comment' => 'comment' ], - [ - 'rc_comment_text' => 'COALESCE( comment_rc_comment.comment_text, rc_comment )', - 'rc_comment_data' => 'comment_rc_comment.comment_data', - 'rc_comment_cid' => 'comment_rc_comment.comment_id', - ], - [], - [], - [ 'comment_rc_comment' => [ 'LEFT JOIN', 'comment_rc_comment.comment_id = rc_comment_id' ] ], - [ 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH ], - ], - [ - [ 'includeFields' => [ WatchedItemQueryService::INCLUDE_COMMENT ] ], - null, - [ 'comment_rc_comment' => 'comment' ], - [ - 'rc_comment_text' => 'COALESCE( comment_rc_comment.comment_text, rc_comment )', - 'rc_comment_data' => 'comment_rc_comment.comment_data', - 'rc_comment_cid' => 'comment_rc_comment.comment_id', - ], - [], - [], - [ 'comment_rc_comment' => [ 'LEFT JOIN', 'comment_rc_comment.comment_id = rc_comment_id' ] ], - [ 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW ], - ], - [ - [ 'includeFields' => [ WatchedItemQueryService::INCLUDE_COMMENT ] ], - null, - [ 'comment_rc_comment' => 'comment' ], - [ - 'rc_comment_text' => 'comment_rc_comment.comment_text', - 'rc_comment_data' => 'comment_rc_comment.comment_data', - 'rc_comment_cid' => 'comment_rc_comment.comment_id', - ], [], - [], - [ 'comment_rc_comment' => [ 'JOIN', 'comment_rc_comment.comment_id = rc_comment_id' ] ], - [ 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW ], + [ 'commentstore' => 'join' ], ], [ [ 'includeFields' => [ WatchedItemQueryService::INCLUDE_PATROL_INFO ] ], @@ -836,23 +820,8 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { array $expectedExtraFields, array $expectedExtraConds, array $expectedDbOptions, - array $expectedExtraJoinConds, - array $globals = [] + array $expectedExtraJoinConds ) { - // Sigh. This test class doesn't extend MediaWikiTestCase, so we have to reinvent setMwGlobals(). - if ( $globals ) { - $resetGlobals = []; - foreach ( $globals as $k => $v ) { - $resetGlobals[$k] = $GLOBALS[$k]; - $GLOBALS[$k] = $v; - } - $reset = new ScopedCallback( function () use ( $resetGlobals ) { - foreach ( $resetGlobals as $k => $v ) { - $GLOBALS[$k] = $v; - } - } ); - } - $expectedTables = array_merge( [ 'recentchanges', 'watchlist', 'page' ], $expectedExtraTables ); $expectedFields = array_merge( [ @@ -904,7 +873,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options, $startFrom ); @@ -941,7 +910,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { $user = $this->getMockNonAnonUserWithIdAndNoPatrolRights( 1 ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, [ 'filters' => [ $filtersOption ] ] @@ -1002,7 +971,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ->method( 'getType' ) ->will( $this->returnValue( $dbType ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options ); @@ -1101,7 +1070,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { $user = $this->getMockNonAnonUserWithIdAndRestrictedPermissions( 1, $notAllowedAction ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, $options ); $this->assertEmpty( $items ); @@ -1141,7 +1110,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( $user, [ 'allRevisions' => true ] ); @@ -1226,7 +1195,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { $mockDb->expects( $this->never() ) ->method( $this->anything() ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $this->setExpectedException( InvalidArgumentException::class, $expectedInExceptionMessage ); @@ -1268,7 +1237,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( @@ -1310,7 +1279,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $items = $queryService->getWatchedItemsWithRecentChangeInfo( @@ -1338,7 +1307,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $otherUser = $this->getMockUnrestrictedNonAnonUserWithId( 2 ); $otherUser->expects( $this->once() ) @@ -1369,7 +1338,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { $mockDb->expects( $this->never() ) ->method( $this->anything() ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockUnrestrictedNonAnonUserWithId( 1 ); $otherUser = $this->getMockUnrestrictedNonAnonUserWithId( 2 ); $otherUser->expects( $this->once() ) @@ -1406,7 +1375,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ] ), ] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $user = $this->getMockNonAnonUserWithId( 1 ); $items = $queryService->getWatchedItemsForUser( $user ); @@ -1506,7 +1475,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $items = $queryService->getWatchedItemsForUser( $user, $options ); $this->assertEmpty( $items ); @@ -1619,7 +1588,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { ) ->will( $this->returnValue( [] ) ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $items = $queryService->getWatchedItemsForUser( $user, $options ); $this->assertEmpty( $items ); @@ -1657,7 +1626,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { array $options, $expectedInExceptionMessage ) { - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $this->getMockDb() ) ); + $queryService = $this->newService( $this->getMockDb() ); $this->setExpectedException( InvalidArgumentException::class, $expectedInExceptionMessage ); $queryService->getWatchedItemsForUser( $this->getMockNonAnonUserWithId( 1 ), $options ); @@ -1669,7 +1638,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { $mockDb->expects( $this->never() ) ->method( $this->anything() ); - $queryService = new WatchedItemQueryService( $this->getMockLoadBalancer( $mockDb ) ); + $queryService = $this->newService( $mockDb ); $items = $queryService->getWatchedItemsForUser( $this->getMockAnonUser() ); $this->assertEmpty( $items );