Merge "Remove use of "successful" in strings"
[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 testUpdateAndResetNotificationTimestamp() {
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 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
52
53 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
54 $this->assertEquals(
55 '20150202010101',
56 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
57 );
58
59 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
60 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
61 }
62
63 public function testDuplicateAllAssociatedEntries() {
64 $user = $this->getUser();
65 $titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
66 $titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
67 $store = WatchedItemStore::getDefaultInstance();
68 $store->addWatch( $user, $titleOld->getSubjectPage() );
69 $store->addWatch( $user, $titleOld->getTalkPage() );
70 // Cleanup after previous tests
71 $store->removeWatch( $user, $titleNew->getSubjectPage() );
72 $store->removeWatch( $user, $titleNew->getTalkPage() );
73
74 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
75
76 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
77 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
78 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
79 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );
80 }
81
82 }