MediaWiki REL1_32
WatchedItemStoreIntegrationTest.php
Go to the documentation of this file.
1<?php
2
4
13
14 public function setUp() {
15 parent::setUp();
16 self::$users['WatchedItemStoreIntegrationTestUser']
17 = new TestUser( 'WatchedItemStoreIntegrationTestUser' );
18 }
19
20 private function getUser() {
21 return self::$users['WatchedItemStoreIntegrationTestUser']->getUser();
22 }
23
24 public function testWatchAndUnWatchItem() {
25 $user = $this->getUser();
26 $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
27 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
28 // Cleanup after previous tests
29 $store->removeWatch( $user, $title );
30 $initialWatchers = $store->countWatchers( $title );
31 $initialUserWatchedItems = $store->countWatchedItems( $user );
32
33 $this->assertFalse(
34 $store->isWatched( $user, $title ),
35 'Page should not initially be watched'
36 );
37
38 $store->addWatch( $user, $title );
39 $this->assertTrue(
40 $store->isWatched( $user, $title ),
41 'Page should be watched'
42 );
43 $this->assertEquals( $initialUserWatchedItems + 1, $store->countWatchedItems( $user ) );
44 $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
45 $this->assertCount( $initialUserWatchedItems + 1, $watchedItemsForUser );
46 $watchedItemsForUserHasExpectedItem = false;
47 foreach ( $watchedItemsForUser as $watchedItem ) {
48 if (
49 $watchedItem->getUser()->equals( $user ) &&
50 $watchedItem->getLinkTarget() == $title->getTitleValue()
51 ) {
52 $watchedItemsForUserHasExpectedItem = true;
53 }
54 }
55 $this->assertTrue(
56 $watchedItemsForUserHasExpectedItem,
57 'getWatchedItemsForUser should contain the page'
58 );
59 $this->assertEquals( $initialWatchers + 1, $store->countWatchers( $title ) );
60 $this->assertEquals(
61 $initialWatchers + 1,
62 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
63 );
64 $this->assertEquals(
65 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialWatchers + 1 ] ],
66 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 1 ] )
67 );
68 $this->assertEquals(
69 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
70 $store->countWatchersMultiple( [ $title ], [ 'minimumWatchers' => $initialWatchers + 2 ] )
71 );
72 $this->assertEquals(
73 [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
74 $store->getNotificationTimestampsBatch( $user, [ $title ] )
75 );
76
77 $store->removeWatch( $user, $title );
78 $this->assertFalse(
79 $store->isWatched( $user, $title ),
80 'Page should be unwatched'
81 );
82 $this->assertEquals( $initialUserWatchedItems, $store->countWatchedItems( $user ) );
83 $watchedItemsForUser = $store->getWatchedItemsForUser( $user );
84 $this->assertCount( $initialUserWatchedItems, $watchedItemsForUser );
85 $watchedItemsForUserHasExpectedItem = false;
86 foreach ( $watchedItemsForUser as $watchedItem ) {
87 if (
88 $watchedItem->getUser()->equals( $user ) &&
89 $watchedItem->getLinkTarget() == $title->getTitleValue()
90 ) {
91 $watchedItemsForUserHasExpectedItem = true;
92 }
93 }
94 $this->assertFalse(
95 $watchedItemsForUserHasExpectedItem,
96 'getWatchedItemsForUser should not contain the page'
97 );
98 $this->assertEquals( $initialWatchers, $store->countWatchers( $title ) );
99 $this->assertEquals(
100 $initialWatchers,
101 $store->countWatchersMultiple( [ $title ] )[$title->getNamespace()][$title->getDBkey()]
102 );
103 $this->assertEquals(
104 [ $title->getNamespace() => [ $title->getDBkey() => false ] ],
105 $store->getNotificationTimestampsBatch( $user, [ $title ] )
106 );
107 }
108
109 public function testWatchBatchAndClearItems() {
110 $user = $this->getUser();
111 $title1 = Title::newFromText( 'WatchedItemStoreIntegrationTestPage1' );
112 $title2 = Title::newFromText( 'WatchedItemStoreIntegrationTestPage2' );
113 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
114
115 $store->addWatchBatchForUser( $user, [ $title1, $title2 ] );
116
117 $this->assertTrue( $store->isWatched( $user, $title1 ) );
118 $this->assertTrue( $store->isWatched( $user, $title2 ) );
119
120 $store->clearUserWatchedItems( $user );
121
122 $this->assertFalse( $store->isWatched( $user, $title1 ) );
123 $this->assertFalse( $store->isWatched( $user, $title2 ) );
124 }
125
127 $user = $this->getUser();
128 $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
129 $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
130 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
131 $store->addWatch( $user, $title );
132 $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
133 $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
134 $initialUnreadNotifications = $store->countUnreadNotifications( $user );
135
136 $store->updateNotificationTimestamp( $otherUser, $title, '20150202010101' );
137 $this->assertEquals(
138 '20150202010101',
139 $store->loadWatchedItem( $user, $title )->getNotificationTimestamp()
140 );
141 $this->assertEquals(
142 [ $title->getNamespace() => [ $title->getDBkey() => '20150202010101' ] ],
143 $store->getNotificationTimestampsBatch( $user, [ $title ] )
144 );
145 $this->assertEquals(
146 $initialVisitingWatchers - 1,
147 $store->countVisitingWatchers( $title, '20150202020202' )
148 );
149 $this->assertEquals(
150 $initialVisitingWatchers - 1,
151 $store->countVisitingWatchersMultiple(
152 [ [ $title, '20150202020202' ] ]
153 )[$title->getNamespace()][$title->getDBkey()]
154 );
155 $this->assertEquals(
156 $initialUnreadNotifications + 1,
157 $store->countUnreadNotifications( $user )
158 );
159 $this->assertSame(
160 true,
161 $store->countUnreadNotifications( $user, $initialUnreadNotifications + 1 )
162 );
163
164 $this->assertTrue( $store->resetNotificationTimestamp( $user, $title ) );
165 $this->assertNull( $store->getWatchedItem( $user, $title )->getNotificationTimestamp() );
166 $this->assertEquals(
167 [ $title->getNamespace() => [ $title->getDBkey() => null ] ],
168 $store->getNotificationTimestampsBatch( $user, [ $title ] )
169 );
170 $this->assertEquals(
171 $initialVisitingWatchers,
172 $store->countVisitingWatchers( $title, '20150202020202' )
173 );
174 $this->assertEquals(
175 $initialVisitingWatchers,
176 $store->countVisitingWatchersMultiple(
177 [ [ $title, '20150202020202' ] ]
178 )[$title->getNamespace()][$title->getDBkey()]
179 );
180 $this->assertEquals(
181 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => $initialVisitingWatchers ] ],
182 $store->countVisitingWatchersMultiple(
183 [ [ $title, '20150202020202' ] ], $initialVisitingWatchers
184 )
185 );
186 $this->assertEquals(
187 [ 0 => [ 'WatchedItemStoreIntegrationTestPage' => 0 ] ],
188 $store->countVisitingWatchersMultiple(
189 [ [ $title, '20150202020202' ] ], $initialVisitingWatchers + 1
190 )
191 );
192
193 // setNotificationTimestampsForUser specifying a title
194 $this->assertTrue(
195 $store->setNotificationTimestampsForUser( $user, '20200202020202', [ $title ] )
196 );
197 $this->assertEquals(
198 '20200202020202',
199 $store->getWatchedItem( $user, $title )->getNotificationTimestamp()
200 );
201
202 // setNotificationTimestampsForUser not specifying a title
203 $this->assertTrue(
204 $store->setNotificationTimestampsForUser( $user, '20210202020202' )
205 );
206 $this->assertEquals(
207 '20210202020202',
208 $store->getWatchedItem( $user, $title )->getNotificationTimestamp()
209 );
210 }
211
213 $user = $this->getUser();
214 $titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
215 $titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
216 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
217 $store->addWatch( $user, $titleOld->getSubjectPage() );
218 $store->addWatch( $user, $titleOld->getTalkPage() );
219 // Cleanup after previous tests
220 $store->removeWatch( $user, $titleNew->getSubjectPage() );
221 $store->removeWatch( $user, $titleNew->getTalkPage() );
222
223 $store->duplicateAllAssociatedEntries( $titleOld, $titleNew );
224
225 $this->assertTrue( $store->isWatched( $user, $titleOld->getSubjectPage() ) );
226 $this->assertTrue( $store->isWatched( $user, $titleOld->getTalkPage() ) );
227 $this->assertTrue( $store->isWatched( $user, $titleNew->getSubjectPage() ) );
228 $this->assertTrue( $store->isWatched( $user, $titleNew->getTalkPage() ) );
229 }
230
231}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:9
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
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:247
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:37