* @return PHPUnit_Framework_MockObject_MockObject|IDatabase
*/
private function getMockDb() {
- return $this->getMock( IDatabase::class );
+ return $this->createMock( IDatabase::class );
}
/**
*/
private function getMockLoadBalancer(
$mockDb,
- $expectedConnectionType = null,
- $readOnlyReason = false
+ $expectedConnectionType = null
) {
$mock = $this->getMockBuilder( LoadBalancer::class )
->disableOriginalConstructor()
->method( 'getConnectionRef' )
->will( $this->returnValue( $mockDb ) );
}
- $mock->expects( $this->any() )
- ->method( 'getReadOnlyReason' )
- ->will( $this->returnValue( $readOnlyReason ) );
return $mock;
}
return $mock;
}
+ /**
+ * @return PHPUnit_Framework_MockObject_MockObject|ReadOnlyMode
+ */
+ private function getMockReadOnlyMode( $readOnly = false ) {
+ $mock = $this->getMockBuilder( ReadOnlyMode::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'isReadOnly' )
+ ->will( $this->returnValue( $readOnly ) );
+ return $mock;
+ }
+
/**
* @param int $id
* @return PHPUnit_Framework_MockObject_MockObject|User
*/
private function getMockNonAnonUserWithId( $id ) {
- $mock = $this->getMock( User::class );
+ $mock = $this->createMock( User::class );
$mock->expects( $this->any() )
->method( 'isAnon' )
->will( $this->returnValue( false ) );
return $fakeRow;
}
- private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache ) {
+ private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache,
+ ReadOnlyMode $readOnlyMode
+ ) {
return new WatchedItemStore(
$loadBalancer,
- $cache
+ $cache,
+ $readOnlyMode
);
}
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 12, $store->countWatchedItems( $user ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 7, $store->countWatchers( $titleValue ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 7, $store->countVisitingWatchers( $titleValue, '111' ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$expected = [
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals( 9, $store->countUnreadNotifications( $user ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertSame(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$store->duplicateEntry(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->duplicateEntry(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->duplicateAllAssociatedEntries(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->duplicateAllAssociatedEntries(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->addWatch(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$store->addWatch(
public function testAddWatchBatchForUser_readOnlyDBReturnsFalse() {
$store = $this->newWatchedItemStore(
- $this->getMockLoadBalancer( $this->getMockDb(), null, 'Some Reason' ),
- $this->getMockCache()
+ $this->getMockLoadBalancer( $this->getMockDb() ),
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode( true )
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$mockUser = $this->getMockNonAnonUserWithId( 1 );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchedItem = $store->loadWatchedItem(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchedItem = $store->getWatchedItem(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$user = $this->getMockNonAnonUserWithId( 1 );
$store = $this->newWatchedItemStore(
$mockLoadBalancer,
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchedItems = $store->getWatchedItemsForUser(
public function testGetWatchedItemsForUser_badSortOptionThrowsException() {
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $this->getMockDb() ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->setExpectedException( 'InvalidArgumentException' );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertFalse(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
// Note: This does not actually assert the job is correct
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
// Note: This does not actually assert the job is correct
* @return PHPUnit_Framework_MockObject_MockObject|Title
*/
private function getMockTitle( $text, $ns = 0 ) {
- $title = $this->getMock( Title::class );
+ $title = $this->createMock( Title::class );
$title->expects( $this->any() )
->method( 'getText' )
->will( $this->returnValue( str_replace( '_', ' ', $text ) ) );
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$callableCallCounter = 0;
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$addUpdateCallCounter = 0;
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$callableCallCounter = 0;
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$addUpdateCallCounter = 0;
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$addUpdateCallCounter = 0;
public function testSetNotificationTimestampsForUser_anonUser() {
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $this->getMockDb() ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertFalse( $store->setNotificationTimestampsForUser( $this->getAnonUser(), '' ) );
}
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
+ );
+
+ $this->assertTrue(
+ $store->setNotificationTimestampsForUser( $user, $timestamp )
+ );
+ }
+
+ public function testSetNotificationTimestampsForUser_nullTimestamp() {
+ $user = $this->getMockNonAnonUserWithId( 1 );
+ $timestamp = null;
+
+ $mockDb = $this->getMockDb();
+ $mockDb->expects( $this->once() )
+ ->method( 'update' )
+ ->with(
+ 'watchlist',
+ [ 'wl_notificationtimestamp' => null ],
+ [ 'wl_user' => 1 ]
+ )
+ ->will( $this->returnValue( true ) );
+ $mockDb->expects( $this->exactly( 0 ) )
+ ->method( 'timestamp' )
+ ->will( $this->returnCallback( function( $value ) {
+ return 'TS' . $value . 'TS';
+ } ) );
+
+ $store = $this->newWatchedItemStore(
+ $this->getMockLoadBalancer( $mockDb ),
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $this->getMockCache()
+ $this->getMockCache(),
+ $this->getMockReadOnlyMode()
);
$this->assertTrue(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$this->assertEquals(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
$watchers = $store->updateNotificationTimestamp(
$store = $this->newWatchedItemStore(
$this->getMockLoadBalancer( $mockDb ),
- $mockCache
+ $mockCache,
+ $this->getMockReadOnlyMode()
);
// This will add the item to the cache