MediaWiki  1.30.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  $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 
97  public function testIsWatched_falseOnNotAllowed() {
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 }
$user
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 account $user
Definition: hooks.txt:244
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:268
WatchedItemIntegrationTest\testWatchAndUnWatchItem
testWatchAndUnWatchItem()
Definition: WatchedItemIntegrationTest.php:30
WatchedItemIntegrationTest\testGetNotificationTimestamp_falseOnNotAllowed
testGetNotificationTimestamp_falseOnNotAllowed()
Definition: WatchedItemIntegrationTest.php:107
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
EmailNotification\updateWatchlistTimestamp
static updateWatchlistTimestamp(User $editor, LinkTarget $linkTarget, $timestamp)
Definition: EmailNotification.php:88
WatchedItemIntegrationTest\testIsWatched_falseOnNotAllowed
testIsWatched_falseOnNotAllowed()
Definition: WatchedItemIntegrationTest.php:97
WatchedItemIntegrationTest
Definition: WatchedItemIntegrationTest.php:11
php
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
TestUser
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition: TestUser.php:7
WatchedItemIntegrationTest\testRemoveWatch_falseOnNotAllowed
testRemoveWatch_falseOnNotAllowed()
Definition: WatchedItemIntegrationTest.php:123
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
WatchedItemIntegrationTest\testDuplicateAllAssociatedEntries
testDuplicateAllAssociatedEntries()
Definition: WatchedItemIntegrationTest.php:71
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:1467
WatchedItem\duplicateEntries
static duplicateEntries(Title $oldTitle, Title $newTitle)
Definition: WatchedItem.php:194
WatchedItemIntegrationTest\getUser
getUser()
Definition: WatchedItemIntegrationTest.php:26
WatchedItemIntegrationTest\testUpdateAndResetNotificationTimestamp
testUpdateAndResetNotificationTimestamp()
Definition: WatchedItemIntegrationTest.php:52
WatchedItem\fromUserTitle
static fromUserTitle( $user, $title, $checkRights=User::CHECK_USER_RIGHTS)
Definition: WatchedItem.php:154
WatchedItemIntegrationTest\testGetNotificationTimestamp_falseOnNotWatched
testGetNotificationTimestamp_falseOnNotWatched()
Definition: WatchedItemIntegrationTest.php:135
MediaWikiServices
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
WatchedItemIntegrationTest\setUp
setUp()
Definition: WatchedItemIntegrationTest.php:13