MediaWiki REL1_30
WatchedItemIntegrationTest.php
Go to the documentation of this file.
1<?php
3
12
13 public function setUp() {
14 parent::setUp();
15 self::$users['WatchedItemIntegrationTestUser']
16 = new TestUser( 'WatchedItemIntegrationTestUser' );
17
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' );
24 }
25
26 private function getUser() {
27 return self::$users['WatchedItemIntegrationTestUser']->getUser();
28 }
29
30 public function testWatchAndUnWatchItem() {
31 $user = $this->getUser();
32 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
33 // Cleanup after previous tests
34 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
35
36 $this->assertFalse(
37 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
38 'Page should not initially be watched'
39 );
40 WatchedItem::fromUserTitle( $user, $title )->addWatch();
41 $this->assertTrue(
42 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
43 'Page should be watched'
44 );
45 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
46 $this->assertFalse(
47 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
48 'Page should be unwatched'
49 );
50 }
51
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() );
58
59 EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
60 $this->assertEquals(
61 '20150202010101',
62 WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
63 );
64
65 MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
66 $user, $title
67 );
68 $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
69 }
70
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();
80
81 WatchedItem::duplicateEntries( $titleOld, $titleNew );
82
83 $this->assertTrue(
84 WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
85 );
86 $this->assertTrue(
87 WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
88 );
89 $this->assertTrue(
90 WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
91 );
92 $this->assertTrue(
93 WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage() )->isWatched()
94 );
95 }
96
98 $user = $this->getUser();
99 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
100 WatchedItem::fromUserTitle( $user, $title )->addWatch();
101
102 $this->assertTrue( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
103 $user->mRights = [];
104 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
105 }
106
108 $user = $this->getUser();
109 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
110 WatchedItem::fromUserTitle( $user, $title )->addWatch();
111 MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
112 $user, $title
113 );
114
115 $this->assertEquals(
116 null,
117 WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
118 );
119 $user->mRights = [];
120 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
121 }
122
124 $user = $this->getUser();
125 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
126 WatchedItem::fromUserTitle( $user, $title )->addWatch();
127
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() );
133 }
134
136 $user = $this->getUser();
137 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
138
139 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
140 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
141
142 $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
143 }
144
145}
static updateWatchlistTimestamp(User $editor, LinkTarget $linkTarget, $timestamp)
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition TestUser.php:7
static duplicateEntries(Title $oldTitle, Title $newTitle)
static fromUserTitle( $user, $title, $checkRights=User::CHECK_USER_RIGHTS)