<?php
use MediaWiki\Linker\LinkTarget;
+use MediaWiki\Revision\RevisionLookup;
+use MediaWiki\Revision\RevisionRecord;
use MediaWiki\User\UserIdentityValue;
use Wikimedia\Rdbms\LBFactory;
use Wikimedia\Rdbms\LoadBalancer;
-use Wikimedia\ScopedCallback;
use Wikimedia\TestingAccessWrapper;
/**
return $mock;
}
+ /**
+ * Assumes that only getSubjectPage and getTalkPage will ever be called, and everything passed
+ * to them will have namespace 0.
+ */
+ private function getMockNsInfo() : NamespaceInfo {
+ $mock = $this->createMock( NamespaceInfo::class );
+ $mock->method( 'getSubjectPage' )->will( $this->returnArgument( 0 ) );
+ $mock->method( 'getTalkPage' )->will( $this->returnCallback(
+ function ( $target ) {
+ return new TitleValue( 1, $target->getDbKey() );
+ }
+ ) );
+ $mock->expects( $this->never() )
+ ->method( $this->anythingBut( 'getSubjectPage', 'getTalkPage' ) );
+ return $mock;
+ }
+
+ /**
+ * No methods may be called except provided callbacks, if any.
+ *
+ * @param array $callbacks Keys are method names, values are callbacks
+ * @param array $counts Keys are method names, values are expected number of times to be called
+ * (default is any number is okay)
+ */
+ private function getMockRevisionLookup(
+ array $callbacks = [], array $counts = []
+ ) : RevisionLookup {
+ $mock = $this->createMock( RevisionLookup::class );
+ foreach ( $callbacks as $method => $callback ) {
+ $count = isset( $counts[$method] ) ? $this->exactly( $counts[$method] ) : $this->any();
+ $mock->expects( $count )
+ ->method( $method )
+ ->will( $this->returnCallback( $callbacks[$method] ) );
+ }
+ $mock->expects( $this->never() )
+ ->method( $this->anythingBut( ...array_keys( $callbacks ) ) );
+ return $mock;
+ }
+
private function getFakeRow( array $rowValues ) {
$fakeRow = new stdClass();
foreach ( $rowValues as $valueName => $value ) {
return $fakeRow;
}
- private function newWatchedItemStore(
- LBFactory $lbFactory,
- JobQueueGroup $queueGroup,
- HashBagOStuff $cache,
- ReadOnlyMode $readOnlyMode
- ) {
+ /**
+ * @param array $mocks Associative array providing mocks to use when constructing the
+ * WatchedItemStore. Anything not provided will fall back to a default. Valid keys:
+ * * lbFactory
+ * * db
+ * * queueGroup
+ * * cache
+ * * readOnlyMode
+ * * nsInfo
+ * * revisionLookup
+ */
+ private function newWatchedItemStore( array $mocks = [] ) : WatchedItemStore {
return new WatchedItemStore(
- $lbFactory,
- $queueGroup,
+ $mocks['lbFactory'] ??
+ $this->getMockLBFactory( $mocks['db'] ?? $this->getMockDb() ),
+ $mocks['queueGroup'] ?? $this->getMockJobQueueGroup(),
new HashBagOStuff(),
- $cache,
- $readOnlyMode,
- 1000
+ $mocks['cache'] ?? $this->getMockCache(),
+ $mocks['readOnlyMode'] ?? $this->getMockReadOnlyMode(),
+ 1000,
+ $mocks['nsInfo'] ?? $this->getMockNsInfo(),
+ $mocks['revisionLookup'] ?? $this->getMockRevisionLookup()
);
}
->method( 'delete' )
->with( 'RM-KEY' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
TestingAccessWrapper::newFromObject( $store )
->cacheIndex = [ 0 => [ 'F' => [ 7 => 'RM-KEY', 9 => 'KEEP-KEY' ] ] ];
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse( $store->clearUserWatchedItems( $user ) );
}
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals( 12, $store->countWatchedItems( $user ) );
}
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals( 7, $store->countWatchers( $titleValue ) );
}
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$expected = [
0 => [ 'SomeDbKey' => 100, 'OtherDbKey' => 300 ],
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$expected = [
0 => [ 'SomeDbKey' => 100, 'OtherDbKey' => 300 ],
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals( 7, $store->countVisitingWatchers( $titleValue, '111' ) );
}
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$expected = [
0 => [ 'SomeDbKey' => 100, 'OtherDbKey' => 300 ],
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$expected = [
0 => [
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$expected = [
0 => [ 'SomeDbKey' => 0, 'OtherDbKey' => 0 ],
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals( 9, $store->countUnreadNotifications( $user ) );
}
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertSame(
true,
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
9,
)
->will( $this->returnValue( new FakeResultWrapper( [] ) ) );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb ] );
$store->duplicateEntry(
new TitleValue( 0, 'Old_Title' ),
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store->duplicateEntry(
new TitleValue( 0, 'Old_Title' ),
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store->duplicateAllAssociatedEntries(
new TitleValue( 0, 'Old_Title' ),
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store->duplicateAllAssociatedEntries(
$oldTarget,
->method( 'delete' )
->with( '0:Some_Page:1' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store->addWatch(
new UserIdentityValue( 1, 'MockUser', 0 ),
$mockCache->expects( $this->never() )
->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store->addWatch(
new UserIdentityValue( 0, 'AnonUser', 0 ),
public function testAddWatchBatchForUser_readOnlyDBReturnsFalse() {
$store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $this->getMockDb() ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode( true )
- );
+ [ 'readOnlyMode' => $this->getMockReadOnlyMode( true ) ] );
$this->assertFalse(
$store->addWatchBatchForUser(
->method( 'delete' )
->with( '1:Some_Page:1' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$mockUser = new UserIdentityValue( 1, 'MockUser', 0 );
$mockCache->expects( $this->never() )
->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->addWatchBatchForUser(
$mockCache->expects( $this->never() )
->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertTrue(
$store->addWatchBatchForUser( $user, [] )
'0:SomeDbKey:1'
);
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$watchedItem = $store->loadWatchedItem(
new UserIdentityValue( 1, 'MockUser', 0 ),
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->loadWatchedItem(
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->loadWatchedItem(
[ '1:SomeDbKey:1' ]
);
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertTrue(
$store->removeWatch(
[ '1:SomeDbKey:1' ]
);
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->removeWatch(
$mockCache->expects( $this->never() )
->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->removeWatch(
'0:SomeDbKey:1'
);
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$watchedItem = $store->getWatchedItem(
new UserIdentityValue( 1, 'MockUser', 0 ),
)
->will( $this->returnValue( $cachedItem ) );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
$cachedItem,
->with( '0:SomeDbKey:1' )
->will( $this->returnValue( false ) );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->getWatchedItem(
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->getWatchedItem(
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'set' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$watchedItems = $store->getWatchedItemsForUser( $user );
->will( $this->returnValue( [] ) );
$store = $this->newWatchedItemStore(
- $mockLoadBalancer,
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ [ 'lbFactory' => $mockLoadBalancer, 'cache' => $mockCache ] );
$watchedItems = $store->getWatchedItemsForUser(
$user,
}
public function testGetWatchedItemsForUser_badSortOptionThrowsException() {
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $this->getMockDb() ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore();
$this->setExpectedException( InvalidArgumentException::class );
$store->getWatchedItemsForUser(
'0:SomeDbKey:1'
);
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertTrue(
$store->isWatched(
->with( '0:SomeDbKey:1' )
->will( $this->returnValue( false ) );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->isWatched(
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->isWatched(
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
[
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
[
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
[
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
[
$mockCache = $this->getMockCache();
$mockCache->expects( $this->never() )->method( $this->anything() );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
[
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->resetNotificationTimestamp(
new UserIdentityValue( 0, 'AnonUser', 0 ),
- Title::newFromText( 'SomeDbKey' )
+ new TitleValue( 0, 'SomeDbKey' )
)
);
}
$mockCache->expects( $this->never() )->method( 'set' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertFalse(
$store->resetNotificationTimestamp(
new UserIdentityValue( 1, 'MockUser', 0 ),
- Title::newFromText( 'SomeDbKey' )
+ new TitleValue( 0, 'SomeDbKey' )
)
);
}
public function testResetNotificationTimestamp_item() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
- $title = Title::newFromText( 'SomeDbKey' );
+ $title = new TitleValue( 0, 'SomeDbKey' );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
// don't run
} );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ // We don't care if these methods actually do anything here
+ $mockRevisionLookup = $this->getMockRevisionLookup( [
+ 'getRevisionByTitle' => function () {
+ return null;
+ },
+ 'getTimestampFromId' => function () {
+ return '00000000000000';
+ },
+ ] );
+
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
$this->assertTrue(
$store->resetNotificationTimestamp(
public function testResetNotificationTimestamp_noItemForced() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
- $title = Title::newFromText( 'SomeDbKey' );
+ $title = new TitleValue( 0, 'SomeDbKey' );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->never() )
->with( '0:SomeDbKey:1' );
$mockQueueGroup = $this->getMockJobQueueGroup();
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+
+ // We don't care if these methods actually do anything here
+ $mockRevisionLookup = $this->getMockRevisionLookup( [
+ 'getRevisionByTitle' => function () {
+ return null;
+ },
+ 'getTimestampFromId' => function () {
+ return '00000000000000';
+ },
+ ] );
+
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
$mockQueueGroup->expects( $this->any() )
->method( 'lazyPush' )
);
}
- /**
- * @param string $text
- * @param int $ns
- *
- * @return PHPUnit_Framework_MockObject_MockObject|Title
- */
- private function getMockTitle( $text, $ns = 0 ) {
- $title = $this->createMock( Title::class );
- $title->expects( $this->any() )
- ->method( 'getText' )
- ->will( $this->returnValue( str_replace( '_', ' ', $text ) ) );
- $title->expects( $this->any() )
- ->method( 'getDbKey' )
- ->will( $this->returnValue( str_replace( '_', ' ', $text ) ) );
- $title->expects( $this->any() )
- ->method( 'getNamespace' )
- ->will( $this->returnValue( $ns ) );
- return $title;
- }
-
private function verifyCallbackJob(
ActivityUpdateJob $job,
LinkTarget $expectedTitle,
public function testResetNotificationTimestamp_oldidSpecifiedLatestRevisionForced() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$oldid = 22;
- $title = $this->getMockTitle( 'SomeTitle' );
- $title->expects( $this->once() )
- ->method( 'getNextRevisionID' )
- ->with( $oldid )
- ->will( $this->returnValue( false ) );
+ $title = new TitleValue( 0, 'SomeTitle' );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->never() )
->with( '0:SomeTitle:1' );
$mockQueueGroup = $this->getMockJobQueueGroup();
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+
+ $mockRevisionRecord = $this->createMock( RevisionRecord::class );
+ $mockRevisionRecord->expects( $this->never() )->method( $this->anything() );
+
+ $mockRevisionLookup = $this->getMockRevisionLookup( [
+ 'getTimestampFromId' => function () {
+ return '00000000000000';
+ },
+ 'getRevisionById' => function ( $id, $flags ) use ( $oldid, $mockRevisionRecord ) {
+ $this->assertSame( $oldid, $id );
+ $this->assertSame( 0, $flags );
+ return $mockRevisionRecord;
+ },
+ 'getNextRevision' =>
+ function ( $oldRev, $titleArg ) use ( $mockRevisionRecord, $title ) {
+ $this->assertSame( $mockRevisionRecord, $oldRev );
+ $this->assertSame( $title, $titleArg );
+ return false;
+ },
+ ], [
+ 'getNextRevision' => 1,
+ ] );
+
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
$mockQueueGroup->expects( $this->any() )
->method( 'lazyPush' )
public function testResetNotificationTimestamp_oldidSpecifiedNotLatestRevisionForced() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$oldid = 22;
- $title = $this->getMockTitle( 'SomeDbKey' );
- $title->expects( $this->once() )
- ->method( 'getNextRevisionID' )
- ->with( $oldid )
- ->will( $this->returnValue( 33 ) );
+ $title = new TitleValue( 0, 'SomeDbKey' );
+
+ $mockRevision = $this->createMock( RevisionRecord::class );
+ $mockRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockNextRevision = $this->createMock( RevisionRecord::class );
+ $mockNextRevision->expects( $this->never() )->method( $this->anything() );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
->with( '0:SomeDbKey:1' );
$mockQueueGroup = $this->getMockJobQueueGroup();
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+
+ $mockRevisionLookup = $this->getMockRevisionLookup(
+ [
+ 'getTimestampFromId' => function ( $oldidParam ) use ( $oldid ) {
+ $this->assertSame( $oldid, $oldidParam );
+ },
+ 'getRevisionById' => function ( $id ) use ( $oldid, $mockRevision ) {
+ $this->assertSame( $oldid, $id );
+ return $mockRevision;
+ },
+ 'getNextRevision' =>
+ function ( RevisionRecord $rev ) use ( $mockRevision, $mockNextRevision ) {
+ $this->assertSame( $mockRevision, $rev );
+ return $mockNextRevision;
+ },
+ ],
+ [
+ 'getTimestampFromId' => 2,
+ 'getRevisionById' => 1,
+ 'getNextRevision' => 1,
+ ]
+ );
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
$mockQueueGroup->expects( $this->any() )
->method( 'lazyPush' )
}
) );
- $getTimestampCallCounter = 0;
- $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
- $getTimestampCallCounter++;
- $this->assertEquals( $title, $titleParam );
- $this->assertEquals( $oldid, $oldidParam );
- }
- );
-
$this->assertTrue(
$store->resetNotificationTimestamp(
$user,
$oldid
)
);
- $this->assertEquals( 2, $getTimestampCallCounter );
-
- ScopedCallback::consume( $scopedOverrideRevision );
}
public function testResetNotificationTimestamp_notWatchedPageForced() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$oldid = 22;
- $title = $this->getMockTitle( 'SomeDbKey' );
- $title->expects( $this->once() )
- ->method( 'getNextRevisionID' )
- ->with( $oldid )
- ->will( $this->returnValue( 33 ) );
+ $title = new TitleValue( 0, 'SomeDbKey' );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
->with( '0:SomeDbKey:1' );
$mockQueueGroup = $this->getMockJobQueueGroup();
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
+
+ $mockRevision = $this->createMock( RevisionRecord::class );
+ $mockRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockNextRevision = $this->createMock( RevisionRecord::class );
+ $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockRevisionLookup = $this->getMockRevisionLookup(
+ [
+ 'getTimestampFromId' => function ( $oldidParam ) use ( $oldid ) {
+ $this->assertSame( $oldid, $oldidParam );
+ },
+ 'getRevisionById' => function ( $id ) use ( $oldid, $mockRevision ) {
+ $this->assertSame( $oldid, $id );
+ return $mockRevision;
+ },
+ 'getNextRevision' =>
+ function ( RevisionRecord $rev ) use ( $mockRevision, $mockNextRevision ) {
+ $this->assertSame( $mockRevision, $rev );
+ return $mockNextRevision;
+ },
+ ],
+ [
+ 'getTimestampFromId' => 1,
+ 'getRevisionById' => 1,
+ 'getNextRevision' => 1,
+ ]
);
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
+
$mockQueueGroup->expects( $this->any() )
->method( 'lazyPush' )
->will( $this->returnCallback(
public function testResetNotificationTimestamp_futureNotificationTimestampForced() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$oldid = 22;
- $title = $this->getMockTitle( 'SomeDbKey' );
- $title->expects( $this->once() )
- ->method( 'getNextRevisionID' )
- ->with( $oldid )
- ->will( $this->returnValue( 33 ) );
+ $title = new TitleValue( 0, 'SomeDbKey' );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
->with( '0:SomeDbKey:1' );
$mockQueueGroup = $this->getMockJobQueueGroup();
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
+
+ $mockRevision = $this->createMock( RevisionRecord::class );
+ $mockRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockNextRevision = $this->createMock( RevisionRecord::class );
+ $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockRevisionLookup = $this->getMockRevisionLookup(
+ [
+ 'getTimestampFromId' => function ( $oldidParam ) use ( $oldid ) {
+ $this->assertEquals( $oldid, $oldidParam );
+ },
+ 'getRevisionById' => function ( $id ) use ( $oldid, $mockRevision ) {
+ $this->assertSame( $oldid, $id );
+ return $mockRevision;
+ },
+ 'getNextRevision' =>
+ function ( RevisionRecord $rev ) use ( $mockRevision, $mockNextRevision ) {
+ $this->assertSame( $mockRevision, $rev );
+ return $mockNextRevision;
+ },
+ ],
+ [
+ 'getTimestampFromId' => 2,
+ 'getRevisionById' => 1,
+ 'getNextRevision' => 1,
+ ]
);
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
+
$mockQueueGroup->expects( $this->any() )
->method( 'lazyPush' )
->will( $this->returnCallback(
}
) );
- $getTimestampCallCounter = 0;
- $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
- $getTimestampCallCounter++;
- $this->assertEquals( $title, $titleParam );
- $this->assertEquals( $oldid, $oldidParam );
- }
- );
-
$this->assertTrue(
$store->resetNotificationTimestamp(
$user,
$oldid
)
);
- $this->assertEquals( 2, $getTimestampCallCounter );
-
- ScopedCallback::consume( $scopedOverrideRevision );
}
public function testResetNotificationTimestamp_futureNotificationTimestampNotForced() {
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$oldid = 22;
- $title = $this->getMockTitle( 'SomeDbKey' );
- $title->expects( $this->once() )
- ->method( 'getNextRevisionID' )
- ->with( $oldid )
- ->will( $this->returnValue( 33 ) );
+ $title = new TitleValue( 0, 'SomeDbKey' );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
->with( '0:SomeDbKey:1' );
$mockQueueGroup = $this->getMockJobQueueGroup();
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $mockQueueGroup,
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+
+ $mockRevision = $this->createMock( RevisionRecord::class );
+ $mockRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockNextRevision = $this->createMock( RevisionRecord::class );
+ $mockNextRevision->expects( $this->never() )->method( $this->anything() );
+
+ $mockRevisionLookup = $this->getMockRevisionLookup(
+ [
+ 'getTimestampFromId' => function ( $oldidParam ) use ( $oldid ) {
+ $this->assertEquals( $oldid, $oldidParam );
+ },
+ 'getRevisionById' => function ( $id ) use ( $oldid, $mockRevision ) {
+ $this->assertSame( $oldid, $id );
+ return $mockRevision;
+ },
+ 'getNextRevision' =>
+ function ( RevisionRecord $rev ) use ( $mockRevision, $mockNextRevision ) {
+ $this->assertSame( $mockRevision, $rev );
+ return $mockNextRevision;
+ },
+ ],
+ [
+ 'getTimestampFromId' => 2,
+ 'getRevisionById' => 1,
+ 'getNextRevision' => 1,
+ ]
+ );
+ $store = $this->newWatchedItemStore( [
+ 'db' => $mockDb,
+ 'queueGroup' => $mockQueueGroup,
+ 'cache' => $mockCache,
+ 'revisionLookup' => $mockRevisionLookup,
+ ] );
$mockQueueGroup->expects( $this->any() )
->method( 'lazyPush' )
}
) );
- $getTimestampCallCounter = 0;
- $scopedOverrideRevision = $store->overrideRevisionGetTimestampFromIdCallback(
- function ( $titleParam, $oldidParam ) use ( &$getTimestampCallCounter, $title, $oldid ) {
- $getTimestampCallCounter++;
- $this->assertEquals( $title, $titleParam );
- $this->assertEquals( $oldid, $oldidParam );
- }
- );
-
$this->assertTrue(
$store->resetNotificationTimestamp(
$user,
$oldid
)
);
- $this->assertEquals( 2, $getTimestampCallCounter );
-
- ScopedCallback::consume( $scopedOverrideRevision );
}
public function testSetNotificationTimestampsForUser_anonUser() {
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $this->getMockDb() ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore();
$this->assertFalse( $store->setNotificationTimestampsForUser(
new UserIdentityValue( 0, 'AnonUser', 0 ), '' ) );
}
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$timestamp = '20100101010101';
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $this->getMockDb() ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore();
// Note: This does not actually assert the job is correct
$callableCallCounter = 0;
$user = new UserIdentityValue( 1, 'MockUser', 0 );
$timestamp = null;
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $this->getMockDb() ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore();
// Note: This does not actually assert the job is correct
$callableCallCounter = 0;
->method( 'affectedRows' )
->will( $this->returnValue( 2 ) );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $this->getMockCache(),
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb ] );
$this->assertTrue(
$store->setNotificationTimestampsForUser( $user, $timestamp, $targets )
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$this->assertEquals(
[ 2, 3 ],
$mockCache->expects( $this->never() )->method( 'get' );
$mockCache->expects( $this->never() )->method( 'delete' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$watchers = $store->updateNotificationTimestamp(
new UserIdentityValue( 1, 'MockUser', 0 ),
->method( 'delete' )
->with( '0:SomeDbKey:1' );
- $store = $this->newWatchedItemStore(
- $this->getMockLBFactory( $mockDb ),
- $this->getMockJobQueueGroup(),
- $mockCache,
- $this->getMockReadOnlyMode()
- );
+ $store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
// This will add the item to the cache
$store->getWatchedItem( $user, $titleValue );