Merge "Move WatchedItem logic to WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / includes / WatchedItemStoreIntegrationTest.php
1 <?php
2
3 /**
4 * @author Addshore
5 *
6 * @group Database
7 *
8 * @covers WatchedItemStore
9 */
10 class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
11
12 public function setUp() {
13 parent::setUp();
14 self::$users['WatchedItemStoreIntegrationTestUser']
15 = new TestUser( 'WatchedItemStoreIntegrationTestUser' );
16 }
17
18 private function getUser() {
19 return self::$users['WatchedItemStoreIntegrationTestUser']->getUser();
20 }
21
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
29 $this->assertFalse(
30 $store->isWatched( $user, $title ),
31 'Page should not initially be watched'
32 );
33 $store->addWatch( $user, $title );
34 $this->assertTrue(
35 $store->isWatched( $user, $title ),
36 'Page should be watched'
37 );
38 $store->removeWatch( $user, $title );
39 $this->assertFalse(
40 $store->isWatched( $user, $title ),
41 'Page should be unwatched'
42 );
43 }
44
45 public function testResetNotificationTimestamp() {
46 $user = $this->getUser();
47 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
48 $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
49 $store = WatchedItemStore::getDefaultInstance();
50 $store->addWatch( $user, $title );
51 EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
52
53 $this->assertNotNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
54 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
55 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
56 }
57
58 public function testDuplicateAllAssociatedEntries() {
59 $user = $this->getUser();
60 $titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
61 $titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
62 $store = WatchedItemStore::getDefaultInstance();
63 $store->addWatch( $user, $titleOld->getSubjectPage() );
64 $store->addWatch( $user, $titleOld->getTalkPage() );
65 // Cleanup after previous tests
66 $store->removeWatch( $user, $titleNew->getSubjectPage() );
67 $store->removeWatch( $user, $titleNew->getTalkPage() );
68
69 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
70
71 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
72 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
73 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
74 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );
75 }
76
77 }