Update docs/hooks.txt for ShowSearchHitTitle
[mediawiki.git] / tests / phpunit / includes / WatchedItemIntegrationTest.php
blob65a8c86bb732bd76d4d98be51abdfbbc3fd96af3
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() {
32 $user = $this->getUser();
33 $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
34 // Cleanup after previous tests
35 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
37 $this->assertFalse(
38 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
39 'Page should not initially be watched'
41 WatchedItem::fromUserTitle( $user, $title )->addWatch();
42 $this->assertTrue(
43 WatchedItem::fromUserTitle( $user, $title )->isWatched(),
44 'Page should be watched'
46 WatchedItem::fromUserTitle( $user, $title )->removeWatch();
47 $this->assertFalse(
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' );
61 $this->assertEquals(
62 '20150202010101',
63 WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
66 MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
67 $user, $title
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 );
84 $this->assertTrue(
85 WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
87 $this->assertTrue(
88 WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
90 $this->assertTrue(
91 WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
93 $this->assertTrue(
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() );
104 $user->mRights = [];
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(
113 $user, $title
116 $this->assertEquals(
117 null,
118 WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
120 $user->mRights = [];
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;
130 $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() );