MediaWiki  1.32.5
NoWriteWatchedItemStoreUnitTest.php
Go to the documentation of this file.
1 <?php
2 
9 
10  public function testAddWatch() {
12  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
13  $innerService->expects( $this->never() )->method( 'addWatch' );
14  $noWriteService = new NoWriteWatchedItemStore( $innerService );
15 
16  $this->setExpectedException( DBReadOnlyError::class );
17  $noWriteService->addWatch( $this->getTestSysop()->getUser(), new TitleValue( 0, 'Foo' ) );
18  }
19 
20  public function testAddWatchBatchForUser() {
22  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
23  $innerService->expects( $this->never() )->method( 'addWatchBatchForUser' );
24  $noWriteService = new NoWriteWatchedItemStore( $innerService );
25 
26  $this->setExpectedException( DBReadOnlyError::class );
27  $noWriteService->addWatchBatchForUser( $this->getTestSysop()->getUser(), [] );
28  }
29 
30  public function testRemoveWatch() {
32  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
33  $innerService->expects( $this->never() )->method( 'removeWatch' );
34  $noWriteService = new NoWriteWatchedItemStore( $innerService );
35 
36  $this->setExpectedException( DBReadOnlyError::class );
37  $noWriteService->removeWatch( $this->getTestSysop()->getUser(), new TitleValue( 0, 'Foo' ) );
38  }
39 
42  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
43  $innerService->expects( $this->never() )->method( 'setNotificationTimestampsForUser' );
44  $noWriteService = new NoWriteWatchedItemStore( $innerService );
45 
46  $this->setExpectedException( DBReadOnlyError::class );
47  $noWriteService->setNotificationTimestampsForUser(
48  $this->getTestSysop()->getUser(),
49  'timestamp',
50  []
51  );
52  }
53 
54  public function testUpdateNotificationTimestamp() {
56  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
57  $innerService->expects( $this->never() )->method( 'updateNotificationTimestamp' );
58  $noWriteService = new NoWriteWatchedItemStore( $innerService );
59 
60  $this->setExpectedException( DBReadOnlyError::class );
61  $noWriteService->updateNotificationTimestamp(
62  $this->getTestSysop()->getUser(),
63  new TitleValue( 0, 'Foo' ),
64  'timestamp'
65  );
66  }
67 
68  public function testResetNotificationTimestamp() {
70  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
71  $innerService->expects( $this->never() )->method( 'resetNotificationTimestamp' );
72  $noWriteService = new NoWriteWatchedItemStore( $innerService );
73 
74  $this->setExpectedException( DBReadOnlyError::class );
75  $noWriteService->resetNotificationTimestamp(
76  $this->getTestSysop()->getUser(),
77  Title::newFromText( 'Foo' )
78  );
79  }
80 
81  public function testCountWatchedItems() {
83  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
84  $innerService->expects( $this->once() )->method( 'countWatchedItems' )->willReturn( __METHOD__ );
85  $noWriteService = new NoWriteWatchedItemStore( $innerService );
86 
87  $return = $noWriteService->countWatchedItems(
88  $this->getTestSysop()->getUser()
89  );
90  $this->assertEquals( __METHOD__, $return );
91  }
92 
93  public function testCountWatchers() {
95  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
96  $innerService->expects( $this->once() )->method( 'countWatchers' )->willReturn( __METHOD__ );
97  $noWriteService = new NoWriteWatchedItemStore( $innerService );
98 
99  $return = $noWriteService->countWatchers(
100  new TitleValue( 0, 'Foo' )
101  );
102  $this->assertEquals( __METHOD__, $return );
103  }
104 
105  public function testCountVisitingWatchers() {
107  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
108  $innerService->expects( $this->once() )
109  ->method( 'countVisitingWatchers' )
110  ->willReturn( __METHOD__ );
111  $noWriteService = new NoWriteWatchedItemStore( $innerService );
112 
113  $return = $noWriteService->countVisitingWatchers(
114  new TitleValue( 0, 'Foo' ),
115  9
116  );
117  $this->assertEquals( __METHOD__, $return );
118  }
119 
120  public function testCountWatchersMultiple() {
122  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
123  $innerService->expects( $this->once() )
124  ->method( 'countVisitingWatchersMultiple' )
125  ->willReturn( __METHOD__ );
126  $noWriteService = new NoWriteWatchedItemStore( $innerService );
127 
128  $return = $noWriteService->countWatchersMultiple(
129  [ new TitleValue( 0, 'Foo' ) ],
130  []
131  );
132  $this->assertEquals( __METHOD__, $return );
133  }
134 
137  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
138  $innerService->expects( $this->once() )
139  ->method( 'countVisitingWatchersMultiple' )
140  ->willReturn( __METHOD__ );
141  $noWriteService = new NoWriteWatchedItemStore( $innerService );
142 
143  $return = $noWriteService->countVisitingWatchersMultiple(
144  [ [ new TitleValue( 0, 'Foo' ), 99 ] ],
145  11
146  );
147  $this->assertEquals( __METHOD__, $return );
148  }
149 
150  public function testGetWatchedItem() {
152  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
153  $innerService->expects( $this->once() )->method( 'getWatchedItem' )->willReturn( __METHOD__ );
154  $noWriteService = new NoWriteWatchedItemStore( $innerService );
155 
156  $return = $noWriteService->getWatchedItem(
157  $this->getTestSysop()->getUser(),
158  new TitleValue( 0, 'Foo' )
159  );
160  $this->assertEquals( __METHOD__, $return );
161  }
162 
163  public function testLoadWatchedItem() {
165  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
166  $innerService->expects( $this->once() )->method( 'loadWatchedItem' )->willReturn( __METHOD__ );
167  $noWriteService = new NoWriteWatchedItemStore( $innerService );
168 
169  $return = $noWriteService->loadWatchedItem(
170  $this->getTestSysop()->getUser(),
171  new TitleValue( 0, 'Foo' )
172  );
173  $this->assertEquals( __METHOD__, $return );
174  }
175 
176  public function testGetWatchedItemsForUser() {
178  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
179  $innerService->expects( $this->once() )
180  ->method( 'getWatchedItemsForUser' )
181  ->willReturn( __METHOD__ );
182  $noWriteService = new NoWriteWatchedItemStore( $innerService );
183 
184  $return = $noWriteService->getWatchedItemsForUser(
185  $this->getTestSysop()->getUser(),
186  []
187  );
188  $this->assertEquals( __METHOD__, $return );
189  }
190 
191  public function testIsWatched() {
193  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
194  $innerService->expects( $this->once() )->method( 'isWatched' )->willReturn( __METHOD__ );
195  $noWriteService = new NoWriteWatchedItemStore( $innerService );
196 
197  $return = $noWriteService->isWatched(
198  $this->getTestSysop()->getUser(),
199  new TitleValue( 0, 'Foo' )
200  );
201  $this->assertEquals( __METHOD__, $return );
202  }
203 
206  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
207  $innerService->expects( $this->once() )
208  ->method( 'getNotificationTimestampsBatch' )
209  ->willReturn( __METHOD__ );
210  $noWriteService = new NoWriteWatchedItemStore( $innerService );
211 
212  $return = $noWriteService->getNotificationTimestampsBatch(
213  $this->getTestSysop()->getUser(),
214  [ new TitleValue( 0, 'Foo' ) ]
215  );
216  $this->assertEquals( __METHOD__, $return );
217  }
218 
219  public function testCountUnreadNotifications() {
221  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
222  $innerService->expects( $this->once() )
223  ->method( 'countUnreadNotifications' )
224  ->willReturn( __METHOD__ );
225  $noWriteService = new NoWriteWatchedItemStore( $innerService );
226 
227  $return = $noWriteService->countUnreadNotifications(
228  $this->getTestSysop()->getUser(),
229  88
230  );
231  $this->assertEquals( __METHOD__, $return );
232  }
233 
236  $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
237  $noWriteService = new NoWriteWatchedItemStore( $innerService );
238 
239  $this->setExpectedException( DBReadOnlyError::class );
240  $noWriteService->duplicateAllAssociatedEntries(
241  new TitleValue( 0, 'Foo' ),
242  new TitleValue( 0, 'Bar' )
243  );
244  }
245 
246 }
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:280
NoWriteWatchedItemStoreUnitTest\testCountVisitingWatchers
testCountVisitingWatchers()
Definition: NoWriteWatchedItemStoreUnitTest.php:105
NoWriteWatchedItemStoreUnitTest\testSetNotificationTimestampsForUser
testSetNotificationTimestampsForUser()
Definition: NoWriteWatchedItemStoreUnitTest.php:40
NoWriteWatchedItemStoreUnitTest
Definition: NoWriteWatchedItemStoreUnitTest.php:8
NoWriteWatchedItemStoreUnitTest\testCountWatchers
testCountWatchers()
Definition: NoWriteWatchedItemStoreUnitTest.php:93
NoWriteWatchedItemStoreUnitTest\testGetNotificationTimestampsBatch
testGetNotificationTimestampsBatch()
Definition: NoWriteWatchedItemStoreUnitTest.php:204
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
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
NoWriteWatchedItemStoreUnitTest\testUpdateNotificationTimestamp
testUpdateNotificationTimestamp()
Definition: NoWriteWatchedItemStoreUnitTest.php:54
NoWriteWatchedItemStoreUnitTest\testDuplicateAllAssociatedEntries
testDuplicateAllAssociatedEntries()
Definition: NoWriteWatchedItemStoreUnitTest.php:234
NoWriteWatchedItemStoreUnitTest\testIsWatched
testIsWatched()
Definition: NoWriteWatchedItemStoreUnitTest.php:191
NoWriteWatchedItemStoreUnitTest\testLoadWatchedItem
testLoadWatchedItem()
Definition: NoWriteWatchedItemStoreUnitTest.php:163
NoWriteWatchedItemStoreUnitTest\testGetWatchedItem
testGetWatchedItem()
Definition: NoWriteWatchedItemStoreUnitTest.php:150
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition: MediaWikiTestCase.php:203
NoWriteWatchedItemStoreUnitTest\testRemoveWatch
testRemoveWatch()
Definition: NoWriteWatchedItemStoreUnitTest.php:30
NoWriteWatchedItemStoreUnitTest\testCountUnreadNotifications
testCountUnreadNotifications()
Definition: NoWriteWatchedItemStoreUnitTest.php:219
NoWriteWatchedItemStoreUnitTest\testCountVisitingWatchersMultiple
testCountVisitingWatchersMultiple()
Definition: NoWriteWatchedItemStoreUnitTest.php:135
NoWriteWatchedItemStoreUnitTest\testAddWatch
testAddWatch()
Definition: NoWriteWatchedItemStoreUnitTest.php:10
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
NoWriteWatchedItemStoreUnitTest\testCountWatchersMultiple
testCountWatchersMultiple()
Definition: NoWriteWatchedItemStoreUnitTest.php:120
NoWriteWatchedItemStoreUnitTest\testGetWatchedItemsForUser
testGetWatchedItemsForUser()
Definition: NoWriteWatchedItemStoreUnitTest.php:176
NoWriteWatchedItemStoreUnitTest\testCountWatchedItems
testCountWatchedItems()
Definition: NoWriteWatchedItemStoreUnitTest.php:81
NoWriteWatchedItemStoreUnitTest\testResetNotificationTimestamp
testResetNotificationTimestamp()
Definition: NoWriteWatchedItemStoreUnitTest.php:68
NoWriteWatchedItemStoreUnitTest\testAddWatchBatchForUser
testAddWatchBatchForUser()
Definition: NoWriteWatchedItemStoreUnitTest.php:20
NoWriteWatchedItemStore
Definition: NoWriteWatchedItemStore.php:28
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36