<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @author Addshore
*
public function testWatchAndUnWatchItem() {
$user = $this->getUser();
$title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
- $store = WatchedItemStore::getDefaultInstance();
+ $store = MediaWikiServices::getInstance()->getWatchedItemStore();
// Cleanup after previous tests
$store->removeWatch( $user, $title );
$initialWatchers = $store->countWatchers( $title );
'Page should be watched'
);
$this->assertEquals( $initialUserWatchedItems + 1, $store->countWatchedItems( $user ) );
+ $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
+ $this->assertCount( $initialUserWatchedItems + 1, $watchedItemsForUser );
+ $watchedItemsForUserHasExpectedItem = false;
+ foreach ( $watchedItemsForUser as $watchedItem ) {
+ if (
+ $watchedItem->getUser()->equals( $user ) &&
+ $watchedItem->getLinkTarget() == $title->getTitleValue()
+ ) {
+ $watchedItemsForUserHasExpectedItem = true;
+ }
+ }
+ $this->assertTrue(
+ $watchedItemsForUserHasExpectedItem,
+ 'getWatchedItemsForUser should contain the page'
+ );
$this->assertEquals( $initialWatchers + 1, $store->countWatchers( $title ) );
$this->assertEquals(
$initialWatchers + 1,
[ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
$store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 2 ] )
);
+ $this->assertEquals(
+ [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
+ $store->getNotificationTimestampsBatch( $user, [ $title ] )
+ );
$store->removeWatch( $user, $title );
$this->assertFalse(
'Page should be unwatched'
);
$this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
+ $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
+ $this->assertCount( $initialUserWatchedItems, $watchedItemsForUser );
+ $watchedItemsForUserHasExpectedItem = false;
+ foreach ( $watchedItemsForUser as $watchedItem ) {
+ if (
+ $watchedItem->getUser()->equals( $user ) &&
+ $watchedItem->getLinkTarget() == $title->getTitleValue()
+ ) {
+ $watchedItemsForUserHasExpectedItem = true;
+ }
+ }
+ $this->assertFalse(
+ $watchedItemsForUserHasExpectedItem,
+ 'getWatchedItemsForUser should not contain the page'
+ );
$this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
$this->assertEquals(
$initialWatchers,
$store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
);
+ $this->assertEquals(
+ [ $title->getNamespace() => [ $title->getDBkey() => false ] ],
+ $store->getNotificationTimestampsBatch( $user, [ $title ] )
+ );
}
public function testUpdateAndResetNotificationTimestamp() {
$user = $this->getUser();
$otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
$title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
- $store = WatchedItemStore::getDefaultInstance();
+ $store = MediaWikiServices::getInstance()->getWatchedItemStore();
$store->addWatch( $user, $title );
$this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
$initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
'20150202010101',
$store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
);
+ $this->assertEquals(
+ [ $title->getNamespace() => [ $title->getDBkey() => '20150202010101' ] ],
+ $store->getNotificationTimestampsBatch( $user, [ $title ] )
+ );
$this->assertEquals(
$initialVisitingWatchers - 1,
$store->countVisitingWatchers( $title, '20150202020202' )
$this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
$this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
+ $this->assertEquals(
+ [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
+ $store->getNotificationTimestampsBatch( $user, [ $title ] )
+ );
$this->assertEquals(
$initialVisitingWatchers,
$store->countVisitingWatchers( $title, '20150202020202' )
$user = $this->getUser();
$titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
$titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
- $store = WatchedItemStore::getDefaultInstance();
+ $store = MediaWikiServices::getInstance()->getWatchedItemStore();
$store->addWatch( $user, $titleOld->getSubjectPage() );
$store->addWatch( $user, $titleOld->getTalkPage() );
// Cleanup after previous tests