];
}
- /**
- * @covers NamespaceInfo::getSubject
- */
- public function testGetSubject() {
- // Special namespaces are their own subjects
- $obj = $this->newObj();
- $this->assertEquals( NS_MEDIA, $obj->getSubject( NS_MEDIA ) );
- $this->assertEquals( NS_SPECIAL, $obj->getSubject( NS_SPECIAL ) );
-
- $this->assertEquals( NS_MAIN, $obj->getSubject( NS_TALK ) );
- $this->assertEquals( NS_USER, $obj->getSubject( NS_USER_TALK ) );
- }
-
- /**
- * Regular getTalk() calls
- * Namespaces without a talk page (NS_MEDIA, NS_SPECIAL) are tested in
- * the function testGetTalkExceptions()
- * @covers NamespaceInfo::getTalk
- * @covers NamespaceInfo::isMethodValidFor
- */
- public function testGetTalk() {
- $obj = $this->newObj();
- $this->assertEquals( NS_TALK, $obj->getTalk( NS_MAIN ) );
- $this->assertEquals( NS_TALK, $obj->getTalk( NS_TALK ) );
- $this->assertEquals( NS_USER_TALK, $obj->getTalk( NS_USER ) );
- $this->assertEquals( NS_USER_TALK, $obj->getTalk( NS_USER_TALK ) );
- }
-
- /**
- * Exceptions with getTalk()
- * NS_MEDIA does not have talk pages. MediaWiki raise an exception for them.
- * @expectedException MWException
- * @covers NamespaceInfo::getTalk
- * @covers NamespaceInfo::isMethodValidFor
- */
- public function testGetTalkExceptionsForNsMedia() {
- $this->assertNull( $this->newObj()->getTalk( NS_MEDIA ) );
- }
-
- /**
- * Exceptions with getTalk()
- * NS_SPECIAL does not have talk pages. MediaWiki raise an exception for them.
- * @expectedException MWException
- * @covers NamespaceInfo::getTalk
- */
- public function testGetTalkExceptionsForNsSpecial() {
- $this->assertNull( $this->newObj()->getTalk( NS_SPECIAL ) );
- }
-
- /**
- * Regular getAssociated() calls
- * Namespaces without an associated page (NS_MEDIA, NS_SPECIAL) are tested in
- * the function testGetAssociatedExceptions()
- * @covers NamespaceInfo::getAssociated
- */
- public function testGetAssociated() {
- $this->assertEquals( NS_TALK, $this->newObj()->getAssociated( NS_MAIN ) );
- $this->assertEquals( NS_MAIN, $this->newObj()->getAssociated( NS_TALK ) );
- }
-
- # ## Exceptions with getAssociated()
- # ## NS_MEDIA and NS_SPECIAL do not have talk pages. MediaWiki raises
- # ## an exception for them.
- /**
- * @expectedException MWException
- * @covers NamespaceInfo::getAssociated
- */
- public function testGetAssociatedExceptionsForNsMedia() {
- $this->assertNull( $this->newObj()->getAssociated( NS_MEDIA ) );
- }
-
- /**
- * @expectedException MWException
- * @covers NamespaceInfo::getAssociated
- */
- public function testGetAssociatedExceptionsForNsSpecial() {
- $this->assertNull( $this->newObj()->getAssociated( NS_SPECIAL ) );
- }
-
/**
* @covers NamespaceInfo::exists
* @dataProvider provideExists
// %} End basic methods
+ /**********************************************************************************************
+ * getSubject/Talk/Associated
+ * %{
+ */
+ /**
+ * @dataProvider provideSubjectTalk
+ * @covers NamespaceInfo::getSubject
+ * @covers NamespaceInfo::getSubjectPage
+ * @covers NamespaceInfo::isMethodValidFor
+ * @covers Title::getSubjectPage
+ *
+ * @param int $subject
+ * @param int $talk
+ */
+ public function testGetSubject( $subject, $talk ) {
+ $obj = $this->newObj();
+ $this->assertSame( $subject, $obj->getSubject( $subject ) );
+ $this->assertSame( $subject, $obj->getSubject( $talk ) );
+
+ $subjectTitleVal = new TitleValue( $subject, 'A' );
+ $talkTitleVal = new TitleValue( $talk, 'A' );
+ // Object will be the same one passed in if it's a subject, different but equal object if
+ // it's talk
+ $this->assertSame( $subjectTitleVal, $obj->getSubjectPage( $subjectTitleVal ) );
+ $this->assertEquals( $subjectTitleVal, $obj->getSubjectPage( $talkTitleVal ) );
+
+ $subjectTitle = Title::makeTitle( $subject, 'A' );
+ $talkTitle = Title::makeTitle( $talk, 'A' );
+ $this->assertSame( $subjectTitle, $subjectTitle->getSubjectPage() );
+ $this->assertEquals( $subjectTitle, $talkTitle->getSubjectPage() );
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getSubject
+ * @covers NamespaceInfo::getSubjectPage
+ *
+ * @param int $ns
+ */
+ public function testGetSubject_special( $ns ) {
+ $obj = $this->newObj();
+ $this->assertSame( $ns, $obj->getSubject( $ns ) );
+
+ $title = new TitleValue( $ns, 'A' );
+ $this->assertSame( $title, $obj->getSubjectPage( $title ) );
+ }
+
+ /**
+ * @dataProvider provideSubjectTalk
+ * @covers NamespaceInfo::getTalk
+ * @covers NamespaceInfo::getTalkPage
+ * @covers NamespaceInfo::isMethodValidFor
+ * @covers Title::getTalkPage
+ *
+ * @param int $subject
+ * @param int $talk
+ */
+ public function testGetTalk( $subject, $talk ) {
+ $obj = $this->newObj();
+ $this->assertSame( $talk, $obj->getTalk( $subject ) );
+ $this->assertSame( $talk, $obj->getTalk( $talk ) );
+
+ $subjectTitleVal = new TitleValue( $subject, 'A' );
+ $talkTitleVal = new TitleValue( $talk, 'A' );
+ // Object will be the same one passed in if it's a talk, different but equal object if it's
+ // subject
+ $this->assertEquals( $talkTitleVal, $obj->getTalkPage( $subjectTitleVal ) );
+ $this->assertSame( $talkTitleVal, $obj->getTalkPage( $talkTitleVal ) );
+
+ $subjectTitle = Title::makeTitle( $subject, 'A' );
+ $talkTitle = Title::makeTitle( $talk, 'A' );
+ $this->assertEquals( $talkTitle, $subjectTitle->getTalkPage() );
+ $this->assertSame( $talkTitle, $talkTitle->getTalkPage() );
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getTalk
+ * @covers NamespaceInfo::isMethodValidFor
+ *
+ * @param int $ns
+ */
+ public function testGetTalk_special( $ns ) {
+ $this->setExpectedException( MWException::class,
+ "NamespaceInfo::getTalk does not make any sense for given namespace $ns" );
+ $this->newObj()->getTalk( $ns );
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getTalk
+ * @covers NamespaceInfo::getTalkPage
+ * @covers NamespaceInfo::isMethodValidFor
+ *
+ * @param int $ns
+ */
+ public function testGetTalkPage_special( $ns ) {
+ $this->setExpectedException( MWException::class,
+ "NamespaceInfo::getTalk does not make any sense for given namespace $ns" );
+ $this->newObj()->getTalkPage( new TitleValue( $ns, 'A' ) );
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getTalk
+ * @covers NamespaceInfo::getTalkPage
+ * @covers NamespaceInfo::isMethodValidFor
+ * @covers Title::getTalkPage
+ *
+ * @param int $ns
+ */
+ public function testTitleGetTalkPage_special( $ns ) {
+ $this->setExpectedException( MWException::class,
+ "NamespaceInfo::getTalk does not make any sense for given namespace $ns" );
+ Title::makeTitle( $ns, 'A' )->getTalkPage();
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getAssociated
+ * @covers NamespaceInfo::isMethodValidFor
+ *
+ * @param int $ns
+ */
+ public function testGetAssociated_special( $ns ) {
+ $this->setExpectedException( MWException::class,
+ "NamespaceInfo::getAssociated does not make any sense for given namespace $ns" );
+ $this->newObj()->getAssociated( $ns );
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getAssociated
+ * @covers NamespaceInfo::getAssociatedPage
+ * @covers NamespaceInfo::isMethodValidFor
+ *
+ * @param int $ns
+ */
+ public function testGetAssociatedPage_special( $ns ) {
+ $this->setExpectedException( MWException::class,
+ "NamespaceInfo::getAssociated does not make any sense for given namespace $ns" );
+ $this->newObj()->getAssociatedPage( new TitleValue( $ns, 'A' ) );
+ }
+
+ /**
+ * @dataProvider provideSpecialNamespaces
+ * @covers NamespaceInfo::getAssociated
+ * @covers NamespaceInfo::getAssociatedPage
+ * @covers NamespaceInfo::isMethodValidFor
+ * @covers Title::getOtherPage
+ *
+ * @param int $ns
+ */
+ public function testTitleGetOtherPage_special( $ns ) {
+ $this->setExpectedException( MWException::class,
+ "NamespaceInfo::getAssociated does not make any sense for given namespace $ns" );
+ Title::makeTitle( $ns, 'A' )->getOtherPage();
+ }
+
+ /**
+ * @dataProvider provideSubjectTalk
+ * @covers NamespaceInfo::getAssociated
+ * @covers NamespaceInfo::getAssociatedPage
+ * @covers Title::getOtherPage
+ *
+ * @param int $subject
+ * @param int $talk
+ */
+ public function testGetAssociated( $subject, $talk ) {
+ $obj = $this->newObj();
+ $this->assertSame( $talk, $obj->getAssociated( $subject ) );
+ $this->assertSame( $subject, $obj->getAssociated( $talk ) );
+
+ $subjectTitle = new TitleValue( $subject, 'A' );
+ $talkTitle = new TitleValue( $talk, 'A' );
+ // Object will not be the same
+ $this->assertEquals( $talkTitle, $obj->getAssociatedPage( $subjectTitle ) );
+ $this->assertEquals( $subjectTitle, $obj->getAssociatedPage( $talkTitle ) );
+
+ $subjectTitle = Title::makeTitle( $subject, 'A' );
+ $talkTitle = Title::makeTitle( $talk, 'A' );
+ $this->assertEquals( $talkTitle, $subjectTitle->getOtherPage() );
+ $this->assertEquals( $subjectTitle, $talkTitle->getOtherPage() );
+ }
+
+ public static function provideSubjectTalk() {
+ return [
+ // Format: [ subject, talk ]
+ 'Main/talk' => [ NS_MAIN, NS_TALK ],
+ 'User/user talk' => [ NS_USER, NS_USER_TALK ],
+ 'Unknown namespaces also supported' => [ 106, 107 ],
+ ];
+ }
+
+ public static function provideSpecialNamespaces() {
+ return [
+ 'Special' => [ NS_SPECIAL ],
+ 'Media' => [ NS_MEDIA ],
+ 'Unknown negative index' => [ -613 ],
+ ];
+ }
+
+ // %} End getSubject/Talk/Associated
+
/**********************************************************************************************
* Canonical namespaces
* %{
<?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 );