8 * @covers WatchedItemStore
10 class WatchedItemStoreIntegrationTest
extends MediaWikiTestCase
{
12 public function setUp() {
14 self
::$users['WatchedItemStoreIntegrationTestUser']
15 = new TestUser( 'WatchedItemStoreIntegrationTestUser' );
18 private function getUser() {
19 return self
::$users['WatchedItemStoreIntegrationTestUser']->getUser();
22 public function testWatchAndUnWatchItem() {
23 $user = $this->getUser();
24 $title = Title
::newFromText( 'WatchedItemStoreIntegrationTestPage' );
25 $store = WatchedItemStore
::getDefaultInstance();
26 // Cleanup after previous tests
27 $store->removeWatch( $user, $title );
28 $initialWatchers = $store->countWatchers( $title );
29 $initialUserWatchedItems = $store->countWatchedItems( $user );
32 $store->isWatched( $user, $title ),
33 'Page should not initially be watched'
36 $store->addWatch( $user, $title );
38 $store->isWatched( $user, $title ),
39 'Page should be watched'
41 $this->assertEquals( $initialUserWatchedItems +
1, $store->countWatchedItems( $user ) );
42 $this->assertEquals( $initialWatchers +
1, $store->countWatchers( $title ) );
45 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
48 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers +
1 ] ],
49 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
1 ] )
52 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
53 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
2 ] )
56 $store->removeWatch( $user, $title );
58 $store->isWatched( $user, $title ),
59 'Page should be unwatched'
61 $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
62 $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
65 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
69 public function testUpdateAndResetNotificationTimestamp() {
70 $user = $this->getUser();
71 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
72 $title = Title
::newFromText( 'WatchedItemStoreIntegrationTestPage' );
73 $store = WatchedItemStore
::getDefaultInstance();
74 $store->addWatch( $user, $title );
75 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
76 $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
77 $initialUnreadNotifications = $store->countUnreadNotifications( $user );
79 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
82 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
85 $initialVisitingWatchers - 1,
86 $store->countVisitingWatchers( $title, '20150202020202' )
89 $initialUnreadNotifications +
1,
90 $store->countUnreadNotifications( $user )
94 $store->countUnreadNotifications( $user, $initialUnreadNotifications +
1 )
97 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
98 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
100 $initialVisitingWatchers,
101 $store->countVisitingWatchers( $title, '20150202020202' )
105 public function testDuplicateAllAssociatedEntries() {
106 $user = $this->getUser();
107 $titleOld = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
108 $titleNew = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
109 $store = WatchedItemStore
::getDefaultInstance();
110 $store->addWatch( $user, $titleOld->getSubjectPage() );
111 $store->addWatch( $user, $titleOld->getTalkPage() );
112 // Cleanup after previous tests
113 $store->removeWatch( $user, $titleNew->getSubjectPage() );
114 $store->removeWatch( $user, $titleNew->getTalkPage() );
116 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
118 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
119 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
120 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
121 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );