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() );
74 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
77 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
80 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
81 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
84 public function testDuplicateAllAssociatedEntries() {
85 $user = $this->getUser();
86 $titleOld = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
87 $titleNew = Title
::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
88 $store = WatchedItemStore
::getDefaultInstance();
89 $store->addWatch( $user, $titleOld->getSubjectPage() );
90 $store->addWatch( $user, $titleOld->getTalkPage() );
91 // Cleanup after previous tests
92 $store->removeWatch( $user, $titleNew->getSubjectPage() );
93 $store->removeWatch( $user, $titleNew->getTalkPage() );
95 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
97 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
98 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
99 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
100 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );