->getMock();
if ( $expectedConnectionType !== null ) {
$mock->expects( $this->any() )
- ->method( 'getConnection' )
+ ->method( 'getConnectionRef' )
->with( $expectedConnectionType )
->will( $this->returnValue( $mockDb ) );
} else {
$mock->expects( $this->any() )
- ->method( 'getConnection' )
+ ->method( 'getConnectionRef' )
->will( $this->returnValue( $mockDb ) );
}
$mock->expects( $this->any() )
ScopedCallback::consume( $scopedOverrideRevision );
}
+ public function testSetNotificationTimestampsForUser_anonUser() {
+ $store = $this->newWatchedItemStore(
+ $this->getMockLoadBalancer( $this->getMockDb() ),
+ $this->getMockCache()
+ );
+ $this->assertFalse( $store->setNotificationTimestampsForUser( $this->getAnonUser(), '' ) );
+ }
+
+ public function testSetNotificationTimestampsForUser_allRows() {
+ $user = $this->getMockNonAnonUserWithId( 1 );
+ $timestamp = '20100101010101';
+
+ $mockDb = $this->getMockDb();
+ $mockDb->expects( $this->once() )
+ ->method( 'update' )
+ ->with(
+ 'watchlist',
+ [ 'wl_notificationtimestamp' => 'TS' . $timestamp . 'TS' ],
+ [ 'wl_user' => 1 ]
+ )
+ ->will( $this->returnValue( true ) );
+ $mockDb->expects( $this->exactly( 1 ) )
+ ->method( 'timestamp' )
+ ->will( $this->returnCallback( function( $value ) {
+ return 'TS' . $value . 'TS';
+ } ) );
+
+ $store = $this->newWatchedItemStore(
+ $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockCache()
+ );
+
+ $this->assertTrue(
+ $store->setNotificationTimestampsForUser( $user, $timestamp )
+ );
+ }
+
+ public function testSetNotificationTimestampsForUser_specificTargets() {
+ $user = $this->getMockNonAnonUserWithId( 1 );
+ $timestamp = '20100101010101';
+ $targets = [ new TitleValue( 0, 'Foo' ), new TitleValue( 0, 'Bar' ) ];
+
+ $mockDb = $this->getMockDb();
+ $mockDb->expects( $this->once() )
+ ->method( 'update' )
+ ->with(
+ 'watchlist',
+ [ 'wl_notificationtimestamp' => 'TS' . $timestamp . 'TS' ],
+ [ 'wl_user' => 1, 0 => 'makeWhereFrom2d return value' ]
+ )
+ ->will( $this->returnValue( true ) );
+ $mockDb->expects( $this->exactly( 1 ) )
+ ->method( 'timestamp' )
+ ->will( $this->returnCallback( function( $value ) {
+ return 'TS' . $value . 'TS';
+ } ) );
+ $mockDb->expects( $this->once() )
+ ->method( 'makeWhereFrom2d' )
+ ->with(
+ [ [ 'Foo' => 1, 'Bar' => 1 ] ],
+ $this->isType( 'string' ),
+ $this->isType( 'string' )
+ )
+ ->will( $this->returnValue( 'makeWhereFrom2d return value' ) );
+
+ $store = $this->newWatchedItemStore(
+ $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockCache()
+ );
+
+ $this->assertTrue(
+ $store->setNotificationTimestampsForUser( $user, $timestamp, $targets )
+ );
+ }
+
public function testUpdateNotificationTimestamp_watchersExist() {
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
- ->method( 'select' )
+ ->method( 'selectFieldValues' )
->with(
- [ 'watchlist' ],
- [ 'wl_user' ],
+ 'watchlist',
+ 'wl_user',
[
'wl_user != 1',
'wl_namespace' => 0,
'wl_notificationtimestamp IS NULL'
]
)
- ->will(
- $this->returnValue( [
- $this->getFakeRow( [ 'wl_user' => '2' ] ),
- $this->getFakeRow( [ 'wl_user' => '3' ] )
- ] )
- );
- $mockDb->expects( $this->once() )
- ->method( 'onTransactionIdle' )
- ->with( $this->isType( 'callable' ) )
- ->will( $this->returnCallback( function( $callable ) {
- $callable();
- } ) );
+ ->will( $this->returnValue( [ '2', '3' ] ) );
$mockDb->expects( $this->once() )
->method( 'update' )
->with(
public function testUpdateNotificationTimestamp_noWatchers() {
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
- ->method( 'select' )
+ ->method( 'selectFieldValues' )
->with(
- [ 'watchlist' ],
- [ 'wl_user' ],
+ 'watchlist',
+ 'wl_user',
[
'wl_user != 1',
'wl_namespace' => 0,
->will(
$this->returnValue( [] )
);
- $mockDb->expects( $this->never() )
- ->method( 'onTransactionIdle' );
$mockDb->expects( $this->never() )
->method( 'update' );
$this->getFakeRow( [ 'wl_notificationtimestamp' => '20151212010101' ] )
) );
$mockDb->expects( $this->once() )
- ->method( 'select' )
+ ->method( 'selectFieldValues' )
->will(
- $this->returnValue( [
- $this->getFakeRow( [ 'wl_user' => '2' ] ),
- $this->getFakeRow( [ 'wl_user' => '3' ] )
- ] )
+ $this->returnValue( [ '2', '3' ] )
);
- $mockDb->expects( $this->once() )
- ->method( 'onTransactionIdle' )
- ->with( $this->isType( 'callable' ) )
- ->will( $this->returnCallback( function( $callable ) {
- $callable();
- } ) );
$mockDb->expects( $this->once() )
->method( 'update' );