2 use MediaWiki\MediaWikiServices
;
11 class WatchedItemIntegrationTest
extends MediaWikiTestCase
{
13 public function 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();
37 WatchedItem
::fromUserTitle( $user, $title )->isWatched(),
38 'Page should not initially be watched'
40 WatchedItem
::fromUserTitle( $user, $title )->addWatch();
42 WatchedItem
::fromUserTitle( $user, $title )->isWatched(),
43 'Page should be watched'
45 WatchedItem
::fromUserTitle( $user, $title )->removeWatch();
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' );
62 WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp()
65 MediaWikiServices
::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
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 );
84 WatchedItem
::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
87 WatchedItem
::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
90 WatchedItem
::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
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() );
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(
117 WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp()
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
;
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() );