f424b21b3e97fa080388ab01fb2c92436c845d0b
[lhc/web/wiklou.git] / tests / phpunit / includes / watcheditem / NoWriteWatchedItemStoreUnitTest.php
1 <?php
2
3 use MediaWiki\User\UserIdentityValue;
4
5 /**
6 * @author Addshore
7 *
8 * @covers NoWriteWatchedItemStore
9 */
10 class NoWriteWatchedItemStoreUnitTest extends MediaWikiTestCase {
11
12 public function testAddWatch() {
13 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
14 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
15 $innerService->expects( $this->never() )->method( 'addWatch' );
16 $noWriteService = new NoWriteWatchedItemStore( $innerService );
17
18 $this->setExpectedException( DBReadOnlyError::class );
19 $noWriteService->addWatch(
20 new UserIdentityValue( 1, 'MockUser', 0 ), new TitleValue( 0, 'Foo' ) );
21 }
22
23 public function testAddWatchBatchForUser() {
24 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
25 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
26 $innerService->expects( $this->never() )->method( 'addWatchBatchForUser' );
27 $noWriteService = new NoWriteWatchedItemStore( $innerService );
28
29 $this->setExpectedException( DBReadOnlyError::class );
30 $noWriteService->addWatchBatchForUser( new UserIdentityValue( 1, 'MockUser', 0 ), [] );
31 }
32
33 public function testRemoveWatch() {
34 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
35 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
36 $innerService->expects( $this->never() )->method( 'removeWatch' );
37 $noWriteService = new NoWriteWatchedItemStore( $innerService );
38
39 $this->setExpectedException( DBReadOnlyError::class );
40 $noWriteService->removeWatch(
41 new UserIdentityValue( 1, 'MockUser', 0 ), new TitleValue( 0, 'Foo' ) );
42 }
43
44 public function testSetNotificationTimestampsForUser() {
45 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
46 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
47 $innerService->expects( $this->never() )->method( 'setNotificationTimestampsForUser' );
48 $noWriteService = new NoWriteWatchedItemStore( $innerService );
49
50 $this->setExpectedException( DBReadOnlyError::class );
51 $noWriteService->setNotificationTimestampsForUser(
52 new UserIdentityValue( 1, 'MockUser', 0 ),
53 'timestamp',
54 []
55 );
56 }
57
58 public function testUpdateNotificationTimestamp() {
59 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
60 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
61 $innerService->expects( $this->never() )->method( 'updateNotificationTimestamp' );
62 $noWriteService = new NoWriteWatchedItemStore( $innerService );
63
64 $this->setExpectedException( DBReadOnlyError::class );
65 $noWriteService->updateNotificationTimestamp(
66 new UserIdentityValue( 1, 'MockUser', 0 ),
67 new TitleValue( 0, 'Foo' ),
68 'timestamp'
69 );
70 }
71
72 public function testResetNotificationTimestamp() {
73 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
74 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
75 $innerService->expects( $this->never() )->method( 'resetNotificationTimestamp' );
76 $noWriteService = new NoWriteWatchedItemStore( $innerService );
77
78 $this->setExpectedException( DBReadOnlyError::class );
79 $noWriteService->resetNotificationTimestamp(
80 new UserIdentityValue( 1, 'MockUser', 0 ),
81 new TitleValue( 0, 'Foo' )
82 );
83 }
84
85 public function testCountWatchedItems() {
86 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
87 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
88 $innerService->expects( $this->once() )->method( 'countWatchedItems' )->willReturn( __METHOD__ );
89 $noWriteService = new NoWriteWatchedItemStore( $innerService );
90
91 $return = $noWriteService->countWatchedItems(
92 new UserIdentityValue( 1, 'MockUser', 0 )
93 );
94 $this->assertEquals( __METHOD__, $return );
95 }
96
97 public function testCountWatchers() {
98 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
99 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
100 $innerService->expects( $this->once() )->method( 'countWatchers' )->willReturn( __METHOD__ );
101 $noWriteService = new NoWriteWatchedItemStore( $innerService );
102
103 $return = $noWriteService->countWatchers(
104 new TitleValue( 0, 'Foo' )
105 );
106 $this->assertEquals( __METHOD__, $return );
107 }
108
109 public function testCountVisitingWatchers() {
110 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
111 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
112 $innerService->expects( $this->once() )
113 ->method( 'countVisitingWatchers' )
114 ->willReturn( __METHOD__ );
115 $noWriteService = new NoWriteWatchedItemStore( $innerService );
116
117 $return = $noWriteService->countVisitingWatchers(
118 new TitleValue( 0, 'Foo' ),
119 9
120 );
121 $this->assertEquals( __METHOD__, $return );
122 }
123
124 public function testCountWatchersMultiple() {
125 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
126 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
127 $innerService->expects( $this->once() )
128 ->method( 'countVisitingWatchersMultiple' )
129 ->willReturn( __METHOD__ );
130 $noWriteService = new NoWriteWatchedItemStore( $innerService );
131
132 $return = $noWriteService->countWatchersMultiple(
133 [ new TitleValue( 0, 'Foo' ) ],
134 []
135 );
136 $this->assertEquals( __METHOD__, $return );
137 }
138
139 public function testCountVisitingWatchersMultiple() {
140 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
141 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
142 $innerService->expects( $this->once() )
143 ->method( 'countVisitingWatchersMultiple' )
144 ->willReturn( __METHOD__ );
145 $noWriteService = new NoWriteWatchedItemStore( $innerService );
146
147 $return = $noWriteService->countVisitingWatchersMultiple(
148 [ [ new TitleValue( 0, 'Foo' ), 99 ] ],
149 11
150 );
151 $this->assertEquals( __METHOD__, $return );
152 }
153
154 public function testGetWatchedItem() {
155 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
156 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
157 $innerService->expects( $this->once() )->method( 'getWatchedItem' )->willReturn( __METHOD__ );
158 $noWriteService = new NoWriteWatchedItemStore( $innerService );
159
160 $return = $noWriteService->getWatchedItem(
161 new UserIdentityValue( 1, 'MockUser', 0 ),
162 new TitleValue( 0, 'Foo' )
163 );
164 $this->assertEquals( __METHOD__, $return );
165 }
166
167 public function testLoadWatchedItem() {
168 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
169 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
170 $innerService->expects( $this->once() )->method( 'loadWatchedItem' )->willReturn( __METHOD__ );
171 $noWriteService = new NoWriteWatchedItemStore( $innerService );
172
173 $return = $noWriteService->loadWatchedItem(
174 new UserIdentityValue( 1, 'MockUser', 0 ),
175 new TitleValue( 0, 'Foo' )
176 );
177 $this->assertEquals( __METHOD__, $return );
178 }
179
180 public function testGetWatchedItemsForUser() {
181 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
182 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
183 $innerService->expects( $this->once() )
184 ->method( 'getWatchedItemsForUser' )
185 ->willReturn( __METHOD__ );
186 $noWriteService = new NoWriteWatchedItemStore( $innerService );
187
188 $return = $noWriteService->getWatchedItemsForUser(
189 new UserIdentityValue( 1, 'MockUser', 0 ),
190 []
191 );
192 $this->assertEquals( __METHOD__, $return );
193 }
194
195 public function testIsWatched() {
196 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
197 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
198 $innerService->expects( $this->once() )->method( 'isWatched' )->willReturn( __METHOD__ );
199 $noWriteService = new NoWriteWatchedItemStore( $innerService );
200
201 $return = $noWriteService->isWatched(
202 new UserIdentityValue( 1, 'MockUser', 0 ),
203 new TitleValue( 0, 'Foo' )
204 );
205 $this->assertEquals( __METHOD__, $return );
206 }
207
208 public function testGetNotificationTimestampsBatch() {
209 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
210 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
211 $innerService->expects( $this->once() )
212 ->method( 'getNotificationTimestampsBatch' )
213 ->willReturn( __METHOD__ );
214 $noWriteService = new NoWriteWatchedItemStore( $innerService );
215
216 $return = $noWriteService->getNotificationTimestampsBatch(
217 new UserIdentityValue( 1, 'MockUser', 0 ),
218 [ new TitleValue( 0, 'Foo' ) ]
219 );
220 $this->assertEquals( __METHOD__, $return );
221 }
222
223 public function testCountUnreadNotifications() {
224 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
225 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
226 $innerService->expects( $this->once() )
227 ->method( 'countUnreadNotifications' )
228 ->willReturn( __METHOD__ );
229 $noWriteService = new NoWriteWatchedItemStore( $innerService );
230
231 $return = $noWriteService->countUnreadNotifications(
232 new UserIdentityValue( 1, 'MockUser', 0 ),
233 88
234 );
235 $this->assertEquals( __METHOD__, $return );
236 }
237
238 public function testDuplicateAllAssociatedEntries() {
239 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
240 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface::class );
241 $noWriteService = new NoWriteWatchedItemStore( $innerService );
242
243 $this->setExpectedException( DBReadOnlyError::class );
244 $noWriteService->duplicateAllAssociatedEntries(
245 new TitleValue( 0, 'Foo' ),
246 new TitleValue( 0, 'Bar' )
247 );
248 }
249
250 }