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