MediaWiki  1.28.0
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 
32  $user = $this->getUser();
33  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
34  // Cleanup after previous tests
35  WatchedItem::fromUserTitle( $user, $title )->removeWatch();
36 
37  $this->assertFalse(
38  WatchedItem::fromUserTitle( $user, $title )->isWatched(),
39  'Page should not initially be watched'
40  );
41  WatchedItem::fromUserTitle( $user, $title )->addWatch();
42  $this->assertTrue(
43  WatchedItem::fromUserTitle( $user, $title )->isWatched(),
44  'Page should be watched'
45  );
46  WatchedItem::fromUserTitle( $user, $title )->removeWatch();
47  $this->assertFalse(
48  WatchedItem::fromUserTitle( $user, $title )->isWatched(),
49  'Page should be unwatched'
50  );
51  }
52 
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() );
59 
60  EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
61  $this->assertEquals(
62  '20150202010101',
63  WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
64  );
65 
66  MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
67  $user, $title
68  );
69  $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
70  }
71 
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();
81 
82  WatchedItem::duplicateEntries( $titleOld, $titleNew );
83 
84  $this->assertTrue(
85  WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
86  );
87  $this->assertTrue(
88  WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
89  );
90  $this->assertTrue(
91  WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
92  );
93  $this->assertTrue(
94  WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage() )->isWatched()
95  );
96  }
97 
98  public function testIsWatched_falseOnNotAllowed() {
99  $user = $this->getUser();
100  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
101  WatchedItem::fromUserTitle( $user, $title )->addWatch();
102 
103  $this->assertTrue( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
104  $user->mRights = [];
105  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
106  }
107 
109  $user = $this->getUser();
110  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
111  WatchedItem::fromUserTitle( $user, $title )->addWatch();
112  MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
113  $user, $title
114  );
115 
116  $this->assertEquals(
117  null,
118  WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
119  );
120  $user->mRights = [];
121  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
122  }
123 
125  $user = $this->getUser();
126  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
127  WatchedItem::fromUserTitle( $user, $title )->addWatch();
128 
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() );
134  }
135 
137  $user = $this->getUser();
138  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
139 
140  WatchedItem::fromUserTitle( $user, $title )->removeWatch();
141  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
142 
143  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
144  }
145 
146 }
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
static updateWatchlistTimestamp(User $editor, LinkTarget $linkTarget, $timestamp)
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:262
static duplicateEntries(Title $oldTitle, Title $newTitle)
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
hideDeprecated($function)
Don't throw a warning if $function is deprecated and called later.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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 fromUserTitle($user, $title, $checkRights=User::CHECK_USER_RIGHTS)