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() {
32 $user = $this->getUser();
33 $title = Title
::newFromText( 'WatchedItemIntegrationTestPage' );
34 // Cleanup after previous tests
35 WatchedItem
::fromUserTitle( $user, $title )->removeWatch();
38 WatchedItem
::fromUserTitle( $user, $title )->isWatched(),
39 'Page should not initially be watched'
41 WatchedItem
::fromUserTitle( $user, $title )->addWatch();
43 WatchedItem
::fromUserTitle( $user, $title )->isWatched(),
44 'Page should be watched'
46 WatchedItem
::fromUserTitle( $user, $title )->removeWatch();
48 WatchedItem
::fromUserTitle( $user, $title )->isWatched(),
49 'Page should be unwatched'
53 public function testUpdateAndResetNotificationTimestamp() {
54 $user = $this->getUser();
55 $otherUser = ( new TestUser( 'WatchedItemIntegrationTestUser_otherUser' ) )->getUser();
56 $title = Title
::newFromText( 'WatchedItemIntegrationTestPage' );
57 WatchedItem
::fromUserTitle( $user, $title )->addWatch();
58 $this->assertNull( WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp() );
60 EmailNotification
::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
63 WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp()
66 MediaWikiServices
::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
69 $this->assertNull( WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp() );
72 public function testDuplicateAllAssociatedEntries() {
73 $user = $this->getUser();
74 $titleOld = Title
::newFromText( 'WatchedItemIntegrationTestPageOld' );
75 $titleNew = Title
::newFromText( 'WatchedItemIntegrationTestPageNew' );
76 WatchedItem
::fromUserTitle( $user, $titleOld->getSubjectPage() )->addWatch();
77 WatchedItem
::fromUserTitle( $user, $titleOld->getTalkPage() )->addWatch();
78 // Cleanup after previous tests
79 WatchedItem
::fromUserTitle( $user, $titleNew->getSubjectPage() )->removeWatch();
80 WatchedItem
::fromUserTitle( $user, $titleNew->getTalkPage() )->removeWatch();
82 WatchedItem
::duplicateEntries( $titleOld, $titleNew );
85 WatchedItem
::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
88 WatchedItem
::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
91 WatchedItem
::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
94 WatchedItem
::fromUserTitle( $user, $titleNew->getTalkPage() )->isWatched()
98 public function testIsWatched_falseOnNotAllowed() {
99 $user = $this->getUser();
100 $title = Title
::newFromText( 'WatchedItemIntegrationTestPage' );
101 WatchedItem
::fromUserTitle( $user, $title )->addWatch();
103 $this->assertTrue( WatchedItem
::fromUserTitle( $user, $title )->isWatched() );
105 $this->assertFalse( WatchedItem
::fromUserTitle( $user, $title )->isWatched() );
108 public function testGetNotificationTimestamp_falseOnNotAllowed() {
109 $user = $this->getUser();
110 $title = Title
::newFromText( 'WatchedItemIntegrationTestPage' );
111 WatchedItem
::fromUserTitle( $user, $title )->addWatch();
112 MediaWikiServices
::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
118 WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp()
121 $this->assertFalse( WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp() );
124 public function testRemoveWatch_falseOnNotAllowed() {
125 $user = $this->getUser();
126 $title = Title
::newFromText( 'WatchedItemIntegrationTestPage' );
127 WatchedItem
::fromUserTitle( $user, $title )->addWatch();
129 $previousRights = $user->mRights
;
131 $this->assertFalse( WatchedItem
::fromUserTitle( $user, $title )->removeWatch() );
132 $user->mRights
= $previousRights;
133 $this->assertTrue( WatchedItem
::fromUserTitle( $user, $title )->removeWatch() );
136 public function testGetNotificationTimestamp_falseOnNotWatched() {
137 $user = $this->getUser();
138 $title = Title
::newFromText( 'WatchedItemIntegrationTestPage' );
140 WatchedItem
::fromUserTitle( $user, $title )->removeWatch();
141 $this->assertFalse( WatchedItem
::fromUserTitle( $user, $title )->isWatched() );
143 $this->assertFalse( WatchedItem
::fromUserTitle( $user, $title )->getNotificationTimestamp() );