MediaWiki REL1_32
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
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
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
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}
static getTestSysop()
Convenience method for getting an immutable admin test user.
Represents a page (or page fragment) title within MediaWiki.