rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / WatchedItemIntegrationTest.php
blob01e7ecb9d3f22e153bbe1e935608d6dc5f20a7dd
1 <?php
2 use MediaWiki\MediaWikiServices;
4 /**
5 * @author Addshore
7 * @group Database
9 * @covers WatchedItem
11 class WatchedItemIntegrationTest extends MediaWikiTestCase {
13 public function setUp() {
14 parent::setUp();
15 self::$users['WatchedItemIntegrationTestUser']
16 = new TestUser( 'WatchedItemIntegrationTestUser' );
18 $this->hideDeprecated( 'WatchedItem::fromUserTitle' );
19 $this->hideDeprecated( 'WatchedItem::addWatch' );
20 $this->hideDeprecated( 'WatchedItem::removeWatch' );
21 $this->hideDeprecated( 'WatchedItem::isWatched' );
22 $this->hideDeprecated( 'WatchedItem::duplicateEntries' );
23 $this->hideDeprecated( 'WatchedItem::batchAddWatch' );
26 private function getUser() {
27 return self::$users['WatchedItemIntegrationTestUser']->getUser();
30 public function testWatchAndUnWatchItem() {
31 $user = $this->getUser();
32 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
33 // Cleanup after previous tests
34 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
36 $this->assertFalse(
37 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
38 'Page should not initially be watched'
40 WatchedItem::fromUserTitle( $user, $title )->addWatch();
41 $this->assertTrue(
42 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
43 'Page should be watched'
45 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
46 $this->assertFalse(
47 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
48 'Page should be unwatched'
52 public function testUpdateAndResetNotificationTimestamp() {
53 $user = $this->getUser();
54 $otherUser = ( new TestUser( 'WatchedItemIntegrationTestUser_otherUser' ) )->getUser();
55 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
56 WatchedItem::fromUserTitle( $user, $title )->addWatch();
57 $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
59 EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
60 $this->assertEquals(
61 '20150202010101',
62 WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
65 MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
66 $user, $title
68 $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
71 public function testDuplicateAllAssociatedEntries() {
72 $user = $this->getUser();
73 $titleOld = Title::newFromText( 'WatchedItemIntegrationTestPageOld' );
74 $titleNew = Title::newFromText( 'WatchedItemIntegrationTestPageNew' );
75 WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->addWatch();
76 WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->addWatch();
77 // Cleanup after previous tests
78 WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->removeWatch();
79 WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage() )->removeWatch();
81 WatchedItem::duplicateEntries( $titleOld, $titleNew );
83 $this->assertTrue(
84 WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
86 $this->assertTrue(
87 WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
89 $this->assertTrue(
90 WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
92 $this->assertTrue(
93 WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage() )->isWatched()
97 public function testIsWatched_falseOnNotAllowed() {
98 $user = $this->getUser();
99 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
100 WatchedItem::fromUserTitle( $user, $title )->addWatch();
102 $this->assertTrue( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
103 $user->mRights = [];
104 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
107 public function testGetNotificationTimestamp_falseOnNotAllowed() {
108 $user = $this->getUser();
109 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
110 WatchedItem::fromUserTitle( $user, $title )->addWatch();
111 MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
112 $user, $title
115 $this->assertEquals(
116 null,
117 WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
119 $user->mRights = [];
120 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
123 public function testRemoveWatch_falseOnNotAllowed() {
124 $user = $this->getUser();
125 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
126 WatchedItem::fromUserTitle( $user, $title )->addWatch();
128 $previousRights = $user->mRights;
129 $user->mRights = [];
130 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->removeWatch() );
131 $user->mRights = $previousRights;
132 $this->assertTrue( WatchedItem::fromUserTitle( $user, $title )->removeWatch() );
135 public function testGetNotificationTimestamp_falseOnNotWatched() {
136 $user = $this->getUser();
137 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
139 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
140 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
142 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );