3 use MediaWiki\User\UserIdentityValue
;
8 * @covers NoWriteWatchedItemStore
10 class NoWriteWatchedItemStoreUnitTest
extends MediaWikiTestCase
{
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 );
18 $this->setExpectedException( DBReadOnlyError
::class );
19 $noWriteService->addWatch(
20 new UserIdentityValue( 1, 'MockUser', 0 ), new TitleValue( 0, 'Foo' ) );
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 );
29 $this->setExpectedException( DBReadOnlyError
::class );
30 $noWriteService->addWatchBatchForUser( new UserIdentityValue( 1, 'MockUser', 0 ), [] );
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 );
39 $this->setExpectedException( DBReadOnlyError
::class );
40 $noWriteService->removeWatch(
41 new UserIdentityValue( 1, 'MockUser', 0 ), new TitleValue( 0, 'Foo' ) );
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 );
50 $this->setExpectedException( DBReadOnlyError
::class );
51 $noWriteService->setNotificationTimestampsForUser(
52 new UserIdentityValue( 1, 'MockUser', 0 ),
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 );
64 $this->setExpectedException( DBReadOnlyError
::class );
65 $noWriteService->updateNotificationTimestamp(
66 new UserIdentityValue( 1, 'MockUser', 0 ),
67 new TitleValue( 0, 'Foo' ),
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 );
78 $this->setExpectedException( DBReadOnlyError
::class );
79 $noWriteService->resetNotificationTimestamp(
80 new UserIdentityValue( 1, 'MockUser', 0 ),
81 Title
::newFromText( 'Foo' )
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 );
91 $return = $noWriteService->countWatchedItems(
92 new UserIdentityValue( 1, 'MockUser', 0 )
94 $this->assertEquals( __METHOD__
, $return );
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 );
103 $return = $noWriteService->countWatchers(
104 new TitleValue( 0, 'Foo' )
106 $this->assertEquals( __METHOD__
, $return );
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 );
117 $return = $noWriteService->countVisitingWatchers(
118 new TitleValue( 0, 'Foo' ),
121 $this->assertEquals( __METHOD__
, $return );
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 );
132 $return = $noWriteService->countWatchersMultiple(
133 [ new TitleValue( 0, 'Foo' ) ],
136 $this->assertEquals( __METHOD__
, $return );
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 );
147 $return = $noWriteService->countVisitingWatchersMultiple(
148 [ [ new TitleValue( 0, 'Foo' ), 99 ] ],
151 $this->assertEquals( __METHOD__
, $return );
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 );
160 $return = $noWriteService->getWatchedItem(
161 new UserIdentityValue( 1, 'MockUser', 0 ),
162 new TitleValue( 0, 'Foo' )
164 $this->assertEquals( __METHOD__
, $return );
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 );
173 $return = $noWriteService->loadWatchedItem(
174 new UserIdentityValue( 1, 'MockUser', 0 ),
175 new TitleValue( 0, 'Foo' )
177 $this->assertEquals( __METHOD__
, $return );
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 );
188 $return = $noWriteService->getWatchedItemsForUser(
189 new UserIdentityValue( 1, 'MockUser', 0 ),
192 $this->assertEquals( __METHOD__
, $return );
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 );
201 $return = $noWriteService->isWatched(
202 new UserIdentityValue( 1, 'MockUser', 0 ),
203 new TitleValue( 0, 'Foo' )
205 $this->assertEquals( __METHOD__
, $return );
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 );
216 $return = $noWriteService->getNotificationTimestampsBatch(
217 new UserIdentityValue( 1, 'MockUser', 0 ),
218 [ new TitleValue( 0, 'Foo' ) ]
220 $this->assertEquals( __METHOD__
, $return );
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 );
231 $return = $noWriteService->countUnreadNotifications(
232 new UserIdentityValue( 1, 'MockUser', 0 ),
235 $this->assertEquals( __METHOD__
, $return );
238 public function testDuplicateAllAssociatedEntries() {
239 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
240 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
241 $noWriteService = new NoWriteWatchedItemStore( $innerService );
243 $this->setExpectedException( DBReadOnlyError
::class );
244 $noWriteService->duplicateAllAssociatedEntries(
245 new TitleValue( 0, 'Foo' ),
246 new TitleValue( 0, 'Bar' )