6 * @covers NoWriteWatchedItemStore
8 class NoWriteWatchedItemStoreUnitTest
extends MediaWikiTestCase
{
10 public function testAddWatch() {
11 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
12 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
13 $innerService->expects( $this->never() )->method( 'addWatch' );
14 $noWriteService = new NoWriteWatchedItemStore( $innerService );
16 $this->setExpectedException( DBReadOnlyError
::class );
17 $noWriteService->addWatch( $this->getTestSysop()->getUser(), new TitleValue( 0, 'Foo' ) );
20 public function testAddWatchBatchForUser() {
21 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
22 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
23 $innerService->expects( $this->never() )->method( 'addWatchBatchForUser' );
24 $noWriteService = new NoWriteWatchedItemStore( $innerService );
26 $this->setExpectedException( DBReadOnlyError
::class );
27 $noWriteService->addWatchBatchForUser( $this->getTestSysop()->getUser(), [] );
30 public function testRemoveWatch() {
31 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
32 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
33 $innerService->expects( $this->never() )->method( 'removeWatch' );
34 $noWriteService = new NoWriteWatchedItemStore( $innerService );
36 $this->setExpectedException( DBReadOnlyError
::class );
37 $noWriteService->removeWatch( $this->getTestSysop()->getUser(), new TitleValue( 0, 'Foo' ) );
40 public function testSetNotificationTimestampsForUser() {
41 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
42 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
43 $innerService->expects( $this->never() )->method( 'setNotificationTimestampsForUser' );
44 $noWriteService = new NoWriteWatchedItemStore( $innerService );
46 $this->setExpectedException( DBReadOnlyError
::class );
47 $noWriteService->setNotificationTimestampsForUser(
48 $this->getTestSysop()->getUser(),
54 public function testUpdateNotificationTimestamp() {
55 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
56 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
57 $innerService->expects( $this->never() )->method( 'updateNotificationTimestamp' );
58 $noWriteService = new NoWriteWatchedItemStore( $innerService );
60 $this->setExpectedException( DBReadOnlyError
::class );
61 $noWriteService->updateNotificationTimestamp(
62 $this->getTestSysop()->getUser(),
63 new TitleValue( 0, 'Foo' ),
68 public function testResetNotificationTimestamp() {
69 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
70 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
71 $innerService->expects( $this->never() )->method( 'resetNotificationTimestamp' );
72 $noWriteService = new NoWriteWatchedItemStore( $innerService );
74 $this->setExpectedException( DBReadOnlyError
::class );
75 $noWriteService->resetNotificationTimestamp(
76 $this->getTestSysop()->getUser(),
77 Title
::newFromText( 'Foo' )
81 public function testCountWatchedItems() {
82 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
83 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
84 $innerService->expects( $this->once() )->method( 'countWatchedItems' )->willReturn( __METHOD__
);
85 $noWriteService = new NoWriteWatchedItemStore( $innerService );
87 $return = $noWriteService->countWatchedItems(
88 $this->getTestSysop()->getUser()
90 $this->assertEquals( __METHOD__
, $return );
93 public function testCountWatchers() {
94 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
95 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
96 $innerService->expects( $this->once() )->method( 'countWatchers' )->willReturn( __METHOD__
);
97 $noWriteService = new NoWriteWatchedItemStore( $innerService );
99 $return = $noWriteService->countWatchers(
100 new TitleValue( 0, 'Foo' )
102 $this->assertEquals( __METHOD__
, $return );
105 public function testCountVisitingWatchers() {
106 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
107 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
108 $innerService->expects( $this->once() )
109 ->method( 'countVisitingWatchers' )
110 ->willReturn( __METHOD__
);
111 $noWriteService = new NoWriteWatchedItemStore( $innerService );
113 $return = $noWriteService->countVisitingWatchers(
114 new TitleValue( 0, 'Foo' ),
117 $this->assertEquals( __METHOD__
, $return );
120 public function testCountWatchersMultiple() {
121 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
122 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
123 $innerService->expects( $this->once() )
124 ->method( 'countVisitingWatchersMultiple' )
125 ->willReturn( __METHOD__
);
126 $noWriteService = new NoWriteWatchedItemStore( $innerService );
128 $return = $noWriteService->countWatchersMultiple(
129 [ new TitleValue( 0, 'Foo' ) ],
132 $this->assertEquals( __METHOD__
, $return );
135 public function testCountVisitingWatchersMultiple() {
136 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
137 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
138 $innerService->expects( $this->once() )
139 ->method( 'countVisitingWatchersMultiple' )
140 ->willReturn( __METHOD__
);
141 $noWriteService = new NoWriteWatchedItemStore( $innerService );
143 $return = $noWriteService->countVisitingWatchersMultiple(
144 [ [ new TitleValue( 0, 'Foo' ), 99 ] ],
147 $this->assertEquals( __METHOD__
, $return );
150 public function testGetWatchedItem() {
151 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
152 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
153 $innerService->expects( $this->once() )->method( 'getWatchedItem' )->willReturn( __METHOD__
);
154 $noWriteService = new NoWriteWatchedItemStore( $innerService );
156 $return = $noWriteService->getWatchedItem(
157 $this->getTestSysop()->getUser(),
158 new TitleValue( 0, 'Foo' )
160 $this->assertEquals( __METHOD__
, $return );
163 public function testLoadWatchedItem() {
164 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
165 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
166 $innerService->expects( $this->once() )->method( 'loadWatchedItem' )->willReturn( __METHOD__
);
167 $noWriteService = new NoWriteWatchedItemStore( $innerService );
169 $return = $noWriteService->loadWatchedItem(
170 $this->getTestSysop()->getUser(),
171 new TitleValue( 0, 'Foo' )
173 $this->assertEquals( __METHOD__
, $return );
176 public function testGetWatchedItemsForUser() {
177 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
178 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
179 $innerService->expects( $this->once() )
180 ->method( 'getWatchedItemsForUser' )
181 ->willReturn( __METHOD__
);
182 $noWriteService = new NoWriteWatchedItemStore( $innerService );
184 $return = $noWriteService->getWatchedItemsForUser(
185 $this->getTestSysop()->getUser(),
188 $this->assertEquals( __METHOD__
, $return );
191 public function testIsWatched() {
192 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
193 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
194 $innerService->expects( $this->once() )->method( 'isWatched' )->willReturn( __METHOD__
);
195 $noWriteService = new NoWriteWatchedItemStore( $innerService );
197 $return = $noWriteService->isWatched(
198 $this->getTestSysop()->getUser(),
199 new TitleValue( 0, 'Foo' )
201 $this->assertEquals( __METHOD__
, $return );
204 public function testGetNotificationTimestampsBatch() {
205 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
206 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
207 $innerService->expects( $this->once() )
208 ->method( 'getNotificationTimestampsBatch' )
209 ->willReturn( __METHOD__
);
210 $noWriteService = new NoWriteWatchedItemStore( $innerService );
212 $return = $noWriteService->getNotificationTimestampsBatch(
213 $this->getTestSysop()->getUser(),
214 [ new TitleValue( 0, 'Foo' ) ]
216 $this->assertEquals( __METHOD__
, $return );
219 public function testCountUnreadNotifications() {
220 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
221 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
222 $innerService->expects( $this->once() )
223 ->method( 'countUnreadNotifications' )
224 ->willReturn( __METHOD__
);
225 $noWriteService = new NoWriteWatchedItemStore( $innerService );
227 $return = $noWriteService->countUnreadNotifications(
228 $this->getTestSysop()->getUser(),
231 $this->assertEquals( __METHOD__
, $return );
234 public function testDuplicateAllAssociatedEntries() {
235 /** @var WatchedItemStoreInterface|PHPUnit_Framework_MockObject_MockObject $innerService */
236 $innerService = $this->getMockForAbstractClass( WatchedItemStoreInterface
::class );
237 $noWriteService = new NoWriteWatchedItemStore( $innerService );
239 $this->setExpectedException( DBReadOnlyError
::class );
240 $noWriteService->duplicateAllAssociatedEntries(
241 new TitleValue( 0, 'Foo' ),
242 new TitleValue( 0, 'Bar' )