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 $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
43 $this->assertCount( $initialUserWatchedItems +
1, $watchedItemsForUser );
44 $watchedItemsForUserHasExpectedItem = false;
45 foreach ( $watchedItemsForUser as $watchedItem ) {
47 $watchedItem->getUser()->equals( $user ) &&
48 $watchedItem->getLinkTarget() == $title->getTitleValue()
50 $watchedItemsForUserHasExpectedItem = true;
54 $watchedItemsForUserHasExpectedItem,
55 'getWatchedItemsForUser should contain the page'
57 $this->assertEquals( $initialWatchers +
1, $store->countWatchers( $title ) );
60 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
63 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers +
1 ] ],
64 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
1 ] )
67 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
68 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
2 ] )
71 $store->removeWatch( $user, $title );
73 $store->isWatched( $user, $title ),
74 'Page should be unwatched'
76 $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
77 $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
78 $this->assertCount( $initialUserWatchedItems, $watchedItemsForUser );
79 $watchedItemsForUserHasExpectedItem = false;
80 foreach ( $watchedItemsForUser as $watchedItem ) {
82 $watchedItem->getUser()->equals( $user ) &&
83 $watchedItem->getLinkTarget() == $title->getTitleValue()
85 $watchedItemsForUserHasExpectedItem = true;
89 $watchedItemsForUserHasExpectedItem,
90 'getWatchedItemsForUser should not contain the page'
92 $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
95 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
99 public function testUpdateAndResetNotificationTimestamp() {
100 $user = $this->getUser();
101 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
102 $title = Title
::newFromText( 'WatchedItemStoreIntegrationTestPage' );
103 $store = WatchedItemStore
::getDefaultInstance();
104 $store->addWatch( $user, $title );
105 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
106 $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
107 $initialUnreadNotifications = $store->countUnreadNotifications( $user );
109 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
112 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
115 $initialVisitingWatchers - 1,
116 $store->countVisitingWatchers( $title, '20150202020202' )
119 $initialUnreadNotifications +
1,
120 $store->countUnreadNotifications( $user )
124 $store->countUnreadNotifications( $user, $initialUnreadNotifications +
1 )
127 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
128 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
130 $initialVisitingWatchers,
131 $store->countVisitingWatchers( $title, '20150202020202' )
135 public function testDuplicateAllAssociatedEntries() {
136 $user = $this->getUser();
137 $titleOld = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
138 $titleNew = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
139 $store = WatchedItemStore
::getDefaultInstance();
140 $store->addWatch( $user, $titleOld->getSubjectPage() );
141 $store->addWatch( $user, $titleOld->getTalkPage() );
142 // Cleanup after previous tests
143 $store->removeWatch( $user, $titleNew->getSubjectPage() );
144 $store->removeWatch( $user, $titleNew->getTalkPage() );
146 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
148 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
149 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
150 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
151 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );