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 );
31 $store->isWatched( $user, $title ),
32 'Page should not initially be watched'
35 $store->addWatch( $user, $title );
37 $store->isWatched( $user, $title ),
38 'Page should be watched'
40 $this->assertEquals( $initialWatchers +
1, $store->countWatchers( $title ) );
43 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
46 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers +
1 ] ],
47 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
1 ] )
50 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
51 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers +
2 ] )
54 $store->removeWatch( $user, $title );
56 $store->isWatched( $user, $title ),
57 'Page should be unwatched'
59 $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
62 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
66 public function testUpdateAndResetNotificationTimestamp() {
67 $user = $this->getUser();
68 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
69 $title = Title
::newFromText( 'WatchedItemStoreIntegrationTestPage' );
70 $store = WatchedItemStore
::getDefaultInstance();
71 $store->addWatch( $user, $title );
72 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
73 $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
74 $initialUnreadNotifications = $store->countUnreadNotifications( $user );
76 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
79 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
82 $initialVisitingWatchers - 1,
83 $store->countVisitingWatchers( $title, '20150202020202' )
86 $initialUnreadNotifications +
1,
87 $store->countUnreadNotifications( $user )
91 $store->countUnreadNotifications( $user, $initialUnreadNotifications +
1 )
94 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
95 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
97 $initialVisitingWatchers,
98 $store->countVisitingWatchers( $title, '20150202020202' )
102 public function testDuplicateAllAssociatedEntries() {
103 $user = $this->getUser();
104 $titleOld = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
105 $titleNew = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
106 $store = WatchedItemStore
::getDefaultInstance();
107 $store->addWatch( $user, $titleOld->getSubjectPage() );
108 $store->addWatch( $user, $titleOld->getTalkPage() );
109 // Cleanup after previous tests
110 $store->removeWatch( $user, $titleNew->getSubjectPage() );
111 $store->removeWatch( $user, $titleNew->getTalkPage() );
113 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
115 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
116 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
117 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
118 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );