/** * @dataProvider pruneUsagesForPageProvider */ public function testPruneUsagesForPage($lastUpdatedBefore, $prunedUsages, $prunedEntityIds, $unused) { $usageTracker = $this->getMock('Wikibase\\Client\\Usage\\UsageTracker'); $usageTracker->expects($this->once())->method('pruneStaleUsages')->with(23, $lastUpdatedBefore)->will($this->returnValue($prunedUsages)); $usageLookup = $this->getMock('Wikibase\\Client\\Usage\\UsageLookup'); $usageLookup->expects($this->never())->method('getUsagesForPage'); $usageLookup->expects($this->once())->method('getUnusedEntities')->with($this->callback(function (array $actualEntities) use($prunedEntityIds) { return UsageUpdaterTest::arraysHaveSameContent($prunedEntityIds, $actualEntities); }))->will($this->returnValue($unused)); $subscriptionManager = $this->getMock('Wikibase\\Client\\Usage\\SubscriptionManager'); $subscriptionManager->expects($this->never())->method('subscribe'); if (empty($prunedUsages)) { // PHPUnit 3.7 doesn't like a with() assertion combined with an exactly( 0 ) assertion. $subscriptionManager->expects($this->never())->method('unsubscribe'); } else { $subscriptionManager->expects($this->once())->method('unsubscribe')->with('testwiki', $this->callback(function ($actualUnsubscribe) use($unused) { return UsageUpdaterTest::arraysHaveSameContent($unused, $actualUnsubscribe); })); } $updater = new UsageUpdater('testwiki', $usageTracker, $usageLookup, $subscriptionManager); // assertions are done by the mock double $updater->pruneUsagesForPage(23, $lastUpdatedBefore); }
/** * Triggered after a page was deleted. * Implemented to prune usage tracking information via UsageUpdater. * * @param int $namespace * @param int $pageId * @param string $timestamp */ public function doArticleDeleteComplete($namespace, $pageId, $timestamp) { $this->usageUpdater->pruneUsagesForPage($pageId, $timestamp); }