diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2021-01-02 17:57:17 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-02-13 13:22:57 +0100 |
commit | b4fa772bc5f23f84fc292f5d6bf884543d2bfe51 (patch) | |
tree | 8576ad3ea145f3644804e2fd93de462cfc2c2578 /tests | |
parent | ceba81060303e49b2617397397f2804516052ec9 (diff) |
Remove V1 item API
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Command/FolderDeleteTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedApiControllerTest.php | 46 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedControllerTest.php | 73 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderApiControllerTest.php | 50 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderControllerTest.php | 74 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 288 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemControllerTest.php | 246 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 22 | ||||
-rw-r--r-- | tests/Unit/Db/FeedMapperTest.php | 92 | ||||
-rw-r--r-- | tests/Unit/Db/FolderMapperTest.php | 90 | ||||
-rw-r--r-- | tests/Unit/Db/ItemMapperTest.php | 2360 | ||||
-rw-r--r-- | tests/Unit/Db/MapperFactoryTest.php | 59 | ||||
-rw-r--r-- | tests/Unit/Db/MapperTestUtility.php | 2 | ||||
-rw-r--r-- | tests/Unit/Service/FeedServiceTest.php | 21 | ||||
-rw-r--r-- | tests/Unit/Service/FolderServiceTest.php | 17 | ||||
-rw-r--r-- | tests/Unit/Service/ItemServiceTest.php | 640 | ||||
-rw-r--r-- | tests/Unit/Service/ServiceTest.php | 4 | ||||
-rw-r--r-- | tests/psalm-baseline.xml | 42 |
18 files changed, 3534 insertions, 594 deletions
diff --git a/tests/Unit/Command/FolderDeleteTest.php b/tests/Unit/Command/FolderDeleteTest.php index c87b05acd..e9076d9ba 100644 --- a/tests/Unit/Command/FolderDeleteTest.php +++ b/tests/Unit/Command/FolderDeleteTest.php @@ -82,7 +82,7 @@ class FolderDeleteTest extends TestCase */ public function testInValid() { - $this->expectException('OCA\News\Service\Exceptions\ServiceException'); + $this->expectException('OCA\News\Service\Exceptions\ServiceValidationException'); $this->expectExceptionMessage('Can not remove root folder!'); $this->consoleInput->expects($this->exactly(2)) diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index a6a1db548..4e6f5f1f3 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -18,7 +18,7 @@ namespace OCA\News\Tests\Unit\Controller; use Exception; use OCA\News\Controller\FeedApiController; use OCA\News\Service\FeedServiceV2; -use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Http; use \OCA\News\Service\Exceptions\ServiceNotFoundException; @@ -40,7 +40,7 @@ class FeedApiControllerTest extends TestCase private $feedService; /** - * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + * @var \PHPUnit\Framework\MockObject\MockObject|ItemServiceV2 */ private $itemService; @@ -80,7 +80,7 @@ class FeedApiControllerTest extends TestCase $this->feedService = $this->getMockBuilder(FeedServiceV2::class) ->disableOriginalConstructor() ->getMock(); - $this->itemService = $this->getMockBuilder(ItemService::class) + $this->itemService = $this->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->class = new FeedApiController( @@ -96,18 +96,17 @@ class FeedApiControllerTest extends TestCase public function testIndex() { - $feeds = [new Feed()]; - $starredCount = 3; - $newestItemId = 2; + $feed = Feed::fromParams(['id' => 5]); + $feeds = [$feed]; $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->equalTo($this->userID)) - ->will($this->returnValue($starredCount)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->equalTo($this->userID)) - ->will($this->returnValue($newestItemId)); + ->will($this->returnValue($feeds[0])); $this->feedService->expects($this->once()) ->method('findAllForUser') ->with($this->equalTo($this->userID)) @@ -118,8 +117,8 @@ class FeedApiControllerTest extends TestCase $this->assertEquals( [ 'feeds' => [$feeds[0]->toAPI()], - 'starredCount' => $starredCount, - 'newestItemId' => $newestItemId + 'starredCount' => 3, + 'newestItemId' => 5 ], $response ); @@ -129,14 +128,13 @@ class FeedApiControllerTest extends TestCase public function testIndexNoNewestItemId() { $feeds = [new Feed()]; - $starredCount = 3; $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->equalTo($this->userID)) - ->will($this->returnValue($starredCount)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->equalTo($this->userID)) ->will($this->throwException(new ServiceNotFoundException(''))); $this->feedService->expects($this->once()) @@ -149,7 +147,7 @@ class FeedApiControllerTest extends TestCase $this->assertEquals( [ 'feeds' => [$feeds[0]->toAPI()], - 'starredCount' => $starredCount, + 'starredCount' => 3, ], $response ); @@ -203,8 +201,8 @@ class FeedApiControllerTest extends TestCase ->method('fetch') ->with($feeds[0]); $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue(3)); + ->method('newest') + ->will($this->returnValue(Feed::fromParams(['id' => 3]))); $response = $this->class->create('url', 3); @@ -234,7 +232,7 @@ class FeedApiControllerTest extends TestCase ->method('fetch') ->with($feeds[0]); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->will($this->throwException(new ServiceNotFoundException(''))); $response = $this->class->create('ho', 3); @@ -287,12 +285,8 @@ class FeedApiControllerTest extends TestCase public function testRead() { $this->itemService->expects($this->once()) - ->method('readFeed') - ->with( - $this->equalTo(3), - $this->equalTo(30), - $this->equalTo($this->userID) - ); + ->method('read') + ->with($this->userID,3,30); $this->class->read(3, 30); } diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 871b781e0..b8929d373 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -18,7 +18,7 @@ use OCA\News\Db\Folder; use OCA\News\Service\FeedServiceV2; use OCA\News\Service\FolderServiceV2; use OCA\News\Service\ImportService; -use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use OCP\AppFramework\Http; use OCA\News\Db\Feed; @@ -55,8 +55,7 @@ class FeedControllerTest extends TestCase */ private $importService; /** - * TODO: Remove - * @var MockObject|ItemService + * @var MockObject|ItemServiceV2 */ private $itemService; @@ -87,7 +86,7 @@ class FeedControllerTest extends TestCase ->disableOriginalConstructor() ->getMock(); $this->itemService = $this - ->getMockBuilder(ItemService::class) + ->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this @@ -138,20 +137,20 @@ class FeedControllerTest extends TestCase 'feeds' => [ ['a feed'], ], - 'starred' => 13 + 'starred' => 4 ]; $this->feedService->expects($this->once()) ->method('findAllForUser') ->with($this->uid) ->will($this->returnValue($result['feeds'])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->uid) ->will($this->throwException(new ServiceNotFoundException(''))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue($result['starred'])); + ->will($this->returnValue([1, 2, 3, 4])); $response = $this->class->index(); @@ -165,7 +164,7 @@ class FeedControllerTest extends TestCase 'feeds' => [ ['a feed'], ], - 'starred' => 13, + 'starred' => 2, 'newestItemId' => 5 ]; $this->feedService->expects($this->once()) @@ -173,13 +172,13 @@ class FeedControllerTest extends TestCase ->with($this->uid) ->will($this->returnValue($result['feeds'])); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with($this->uid) - ->will($this->returnValue($result['newestItemId'])); + ->will($this->returnValue(Feed::fromParams(['id' => 5]))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue($result['starred'])); + ->will($this->returnValue([1, 2])); $response = $this->class->index(); @@ -224,6 +223,30 @@ class FeedControllerTest extends TestCase } + public function testActiveFeed() + { + $id = 3; + $type = FeedType::FEED; + $result = [ + 'activeFeed' => [ + 'id' => $id, + 'type' => $type + ] + ]; + + $this->feedService->expects($this->once()) + ->method('find') + ->with($this->uid, $id) + ->will($this->returnValue(new Feed())); + + $this->activeInitMocks($id, $type); + + $response = $this->class->active(); + + $this->assertEquals($result, $response); + } + + public function testActiveFeedDoesNotExist() { $id = 3; @@ -313,8 +336,8 @@ class FeedControllerTest extends TestCase ]; $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue($result['newestItemId'])); + ->method('newest') + ->will($this->returnValue(Feed::fromParams(['id' => 3]))); $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->uid, false); @@ -341,8 +364,8 @@ class FeedControllerTest extends TestCase ]; $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue($result['newestItemId'])); + ->method('newest') + ->will($this->returnValue(Feed::fromParams(['id' => 3]))); $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->uid, false); @@ -370,7 +393,7 @@ class FeedControllerTest extends TestCase ->with($this->uid, false); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->will($this->throwException(new ServiceNotFoundException(''))); $this->feedService->expects($this->once()) @@ -522,9 +545,9 @@ class FeedControllerTest extends TestCase ->will($this->returnValue($feed)); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue(3)); + ->will($this->returnValue([1, 2, 3])); $response = $this->class->import(['json']); @@ -540,9 +563,9 @@ class FeedControllerTest extends TestCase ->will($this->returnValue(null)); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with($this->uid) - ->will($this->returnValue(3)); + ->will($this->returnValue([1, 2, 3])); $response = $this->class->import(['json']); @@ -561,9 +584,9 @@ class FeedControllerTest extends TestCase ] ]; - $this->itemService->expects($this->once()) - ->method('readFeed') - ->with(4, 5, $this->uid); + $this->feedService->expects($this->once()) + ->method('read') + ->with($this->uid, 4, 5); $response = $this->class->read(4, 5); $this->assertEquals($expected, $response); diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index 858e7ff9e..1964f7b47 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -37,7 +37,7 @@ class FolderApiControllerTest extends TestCase private $folderService; private $itemService; - private $folderAPI; + private $class; private $user; private $msg; @@ -65,7 +65,7 @@ class FolderApiControllerTest extends TestCase $this->itemService = $this->getMockBuilder(ItemService::class) ->disableOriginalConstructor() ->getMock(); - $this->folderAPI = new FolderApiController( + $this->class = new FolderApiController( $request, $userSession, $this->folderService, @@ -84,7 +84,7 @@ class FolderApiControllerTest extends TestCase ->with($this->equalTo($this->user->getUID())) ->will($this->returnValue($folders)); - $response = $this->folderAPI->index(); + $response = $this->class->index(); $this->assertEquals( [ @@ -108,7 +108,7 @@ class FolderApiControllerTest extends TestCase ->with($this->user->getUID(), $folderName) ->will($this->returnValue($folder)); - $response = $this->folderAPI->create($folderName); + $response = $this->class->create($folderName); $this->assertEquals( [ @@ -129,7 +129,7 @@ class FolderApiControllerTest extends TestCase ->method('create') ->will($this->throwException(new ServiceConflictException($msg))); - $response = $this->folderAPI->create('hi'); + $response = $this->class->create('hi'); $data = $response->getData(); $this->assertEquals($msg, $data['message']); @@ -148,7 +148,7 @@ class FolderApiControllerTest extends TestCase ->method('create') ->will($this->throwException(new ServiceValidationException($msg))); - $response = $this->folderAPI->create('hi'); + $response = $this->class->create('hi'); $data = $response->getData(); $this->assertEquals($msg, $data['message']); @@ -164,7 +164,7 @@ class FolderApiControllerTest extends TestCase ->method('delete') ->with($this->user->getUID(), 23); - $this->folderAPI->delete(23); + $this->class->delete(23); } @@ -180,7 +180,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->delete($folderId); + $response = $this->class->delete($folderId); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -197,7 +197,7 @@ class FolderApiControllerTest extends TestCase ->method('rename') ->with($this->user->getUID(), $folderId, $folderName); - $this->folderAPI->update($folderId, $folderName); + $this->class->update($folderId, $folderName); } public function testUpdateDoesNotExist() @@ -213,7 +213,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->update($folderId, $folderName); + $response = $this->class->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -234,7 +234,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->update($folderId, $folderName); + $response = $this->class->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -255,7 +255,7 @@ class FolderApiControllerTest extends TestCase ) ); - $response = $this->folderAPI->update($folderId, $folderName); + $response = $this->class->update($folderId, $folderName); $data = $response->getData(); $this->assertEquals($this->msg, $data['message']); @@ -267,15 +267,25 @@ class FolderApiControllerTest extends TestCase public function testRead() { - $this->itemService->expects($this->once()) - ->method('readFolder') - ->with( - $this->equalTo(3), - $this->equalTo(30), - $this->equalTo($this->user->getUID()) - ); + $this->folderService->expects($this->once()) + ->method('read') + ->with($this->user->getUID(), 3, 30); + + $this->class->read(3, 30); + } + + public function testUpdateRoot() + { + $response = $this->class->update(null, ''); + $this->assertSame(400, $response->getStatus()); + + } + + public function testDeleteRoot() + { + $response = $this->class->delete(null); + $this->assertSame(400, $response->getStatus()); - $this->folderAPI->read(3, 30); } diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php index 18f4114b6..4f46e1211 100644 --- a/tests/Unit/Controller/FolderControllerTest.php +++ b/tests/Unit/Controller/FolderControllerTest.php @@ -84,8 +84,6 @@ class FolderControllerTest extends TestCase $this->class = new FolderController( $request, $this->folderService, - $this->feedService, - $this->itemService, $this->userSession ); $this->msg = 'ron'; @@ -162,6 +160,16 @@ class FolderControllerTest extends TestCase $this->class->delete(5); } + public function testDeleteRoot() + { + $this->folderService->expects($this->never()) + ->method('markDelete') + ->with('jack', 5, true); + + $response = $this->class->delete(null); + $this->assertEquals(400, $response->getStatus()); + } + public function testDeleteDoesNotExist() { $this->folderService->expects($this->once()) @@ -176,6 +184,20 @@ class FolderControllerTest extends TestCase $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } + public function testDeleteConflict() + { + $this->folderService->expects($this->once()) + ->method('markDelete') + ->will($this->throwException(new ServiceConflictException($this->msg))); + + $response = $this->class->delete(5); + + $params = json_decode($response->render(), true); + + $this->assertEquals($this->msg, $params['message']); + $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); + } + public function testRename() { $folder = new Folder(); @@ -186,11 +208,21 @@ class FolderControllerTest extends TestCase ->with('jack', 4, 'tech') ->will($this->returnValue($folder)); - $response = $this->class->rename('tech', 4); + $response = $this->class->rename(4, 'tech'); $this->assertEquals($result, $response); } + public function testRenameRoot() + { + $this->folderService->expects($this->never()) + ->method('rename'); + + $response = $this->class->rename(null, 'tech'); + + $this->assertEquals(400, $response->getStatus()); + } + public function testRenameDoesNotExist() { $msg = 'except'; @@ -199,7 +231,7 @@ class FolderControllerTest extends TestCase ->method('rename') ->will($this->throwException($ex)); - $response = $this->class->rename('tech', 5); + $response = $this->class->rename(5, 'tech'); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); @@ -215,7 +247,7 @@ class FolderControllerTest extends TestCase ->method('rename') ->will($this->throwException($ex)); - $response = $this->class->rename('tech', 1); + $response = $this->class->rename(1, 'tech'); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); @@ -226,19 +258,11 @@ class FolderControllerTest extends TestCase public function testRead() { - $feed = new Feed(); - $expected = ['feeds' => [$feed->toAPI()]]; - - $this->itemService->expects($this->once()) - ->method('readFolder') - ->with(4, 5, 'jack'); - $this->feedService->expects($this->once()) - ->method('findAllForUser') - ->with('jack') - ->will($this->returnValue([$feed])); + $this->folderService->expects($this->once()) + ->method('read') + ->with('jack', 4, 5); - $response = $this->class->read(4, 5); - $this->assertEquals($expected, $response); + $this->class->read(4, 5); } @@ -267,4 +291,20 @@ class FolderControllerTest extends TestCase $this->assertEquals($this->msg, $params['message']); } + + public function testRestoreConflict() + { + $this->folderService->expects($this->once()) + ->method('markDelete') + ->with('jack', 5, false) + ->will($this->throwException(new ServiceConflictException($this->msg))); + + $response = $this->class->restore(5); + + $params = json_decode($response->render(), true); + + $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus()); + $this->assertEquals($this->msg, $params['message']); + } + }
\ No newline at end of file diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 91181333a..85e359705 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -16,7 +16,6 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\ItemApiController; -use OCA\News\Service\ItemService; use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Http; @@ -31,18 +30,28 @@ use PHPUnit\Framework\TestCase; class ItemApiControllerTest extends TestCase { - + /** + * @var ItemServiceV2|\PHPUnit\Framework\MockObject\MockObject + */ private $itemService; - private $oldItemService; - private $class; + /** + * @var IUserSession|\PHPUnit\Framework\MockObject\MockObject + */ private $userSession; + /** + * @var IUser|\PHPUnit\Framework\MockObject\MockObject + */ private $user; + /** + * @var IRequest|\PHPUnit\Framework\MockObject\MockObject + */ private $request; private $msg; + private $uid = 'tom'; + private $class; protected function setUp(): void { - $this->user = 'tom'; $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() @@ -58,24 +67,20 @@ class ItemApiControllerTest extends TestCase ->will($this->returnValue($this->user)); $this->user->expects($this->any()) ->method('getUID') - ->will($this->returnValue('123')); - $this->oldItemService = $this->getMockBuilder(ItemService::class) - ->disableOriginalConstructor() - ->getMock(); + ->will($this->returnValue($this->uid)); $this->itemService = $this->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->class = new ItemApiController( $this->request, $this->userSession, - $this->oldItemService, $this->itemService ); $this->msg = 'hi'; } - public function testIndex() + public function testIndexForFeed() { $item = new Item(); $item->setId(5); @@ -83,26 +88,52 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->oldItemService->expects($this->once()) - ->method('findAllItems') - ->with( - $this->equalTo(2), - $this->equalTo(1), - $this->equalTo(30), - $this->equalTo(20), - $this->equalTo(true), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ) + $this->itemService->expects($this->once()) + ->method('findAllInFeedWithFilters') + ->with($this->uid, 2, 30, 20, false, true) + ->will($this->returnValue([$item])); + + $response = $this->class->index(0, 2, true, 30, 20, true); + + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testIndexForFolder() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllInFolderWithFilters') + ->with($this->uid, 2, 30, 20, false, true) ->will($this->returnValue([$item])); $response = $this->class->index(1, 2, true, 30, 20, true); - $this->assertEquals( - [ - 'items' => [$item->toApi()] - ], $response - ); + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testIndexForItems() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllWithFilters') + ->with($this->uid, 3, 30, 20, true) + ->will($this->returnValue([$item])); + + $response = $this->class->index(3, 2, true, 30, 20, true); + + $this->assertEquals(['items' => [$item->toApi()]], $response); } @@ -114,30 +145,18 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->oldItemService->expects($this->once()) - ->method('findAllItems') - ->with( - $this->equalTo(2), - $this->equalTo(1), - $this->equalTo(-1), - $this->equalTo(0), - $this->equalTo(false), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) - ) + $this->itemService->expects($this->once()) + ->method('findAllInFolderWithFilters') + ->with($this->uid, 2, -1, 0, true, false) ->will($this->returnValue([$item])); $response = $this->class->index(1, 2, false); - $this->assertEquals( - [ - 'items' => [$item->toApi()] - ], $response - ); + $this->assertEquals(['items' => [$item->toApi()]], $response); } - public function testUpdated() + public function testUpdatedFeed() { $item = new Item(); $item->setId(5); @@ -145,36 +164,78 @@ class ItemApiControllerTest extends TestCase $item->setGuidHash('guidhash'); $item->setFeedId(123); - $this->oldItemService->expects($this->once()) - ->method('findAllNew') - ->with( - $this->equalTo(2), - $this->equalTo(1), - $this->equalTo(30000000), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ) + $this->itemService->expects($this->once()) + ->method('findAllInFeedAfter') + ->with($this->uid, 2, 30000000, false) + ->will($this->returnValue([$item])); + + $response = $this->class->updated(0, 2, 30); + + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testUpdatedFolder() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllInFolderAfter') + ->with($this->uid, 2, 30000000, false) ->will($this->returnValue([$item])); $response = $this->class->updated(1, 2, 30); - $this->assertEquals( - [ - 'items' => [$item->toApi()] - ], $response - ); + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + + public function testUpdatedItems() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllAfter') + ->with($this->uid, 3, 30000000) + ->will($this->returnValue([$item])); + + $response = $this->class->updated(3, 2, 30); + + $this->assertEquals(['items' => [$item->toApi()]], $response); + } + + public function testUpdatedFeedFullTimestamp() + { + $item = new Item(); + $item->setId(5); + $item->setGuid('guid'); + $item->setGuidHash('guidhash'); + $item->setFeedId(123); + + $this->itemService->expects($this->once()) + ->method('findAllInFeedAfter') + ->with($this->uid, 2, 1609598359000000, false) + ->will($this->returnValue([$item])); + + $response = $this->class->updated(0, 2, '1609598359000000'); + + $this->assertEquals(['items' => [$item->toApi()]], $response); } public function testRead() { - $this->oldItemService->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') - ->with( - $this->equalTo(2), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ); + ->with($this->user->getUID(), 2, true); $this->class->read(2); } @@ -182,7 +243,7 @@ class ItemApiControllerTest extends TestCase public function testReadDoesNotExist() { - $this->oldItemService->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->will( $this->throwException( @@ -200,12 +261,12 @@ class ItemApiControllerTest extends TestCase public function testUnread() { - $this->oldItemService->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->with( + $this->equalTo($this->user->getUID()), $this->equalTo(2), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) + $this->equalTo(false) ); $this->class->unread(2); @@ -214,7 +275,7 @@ class ItemApiControllerTest extends TestCase public function testUnreadDoesNotExist() { - $this->oldItemService->expects($this->once()) + $this->itemService->expects($this->once()) ->method('read') ->will( $this->throwException( @@ -232,14 +293,9 @@ class ItemApiControllerTest extends TestCase public function testStar() { - $this->oldItemService->expects($this->once()) - ->method('star') - ->with( - $this->equalTo(2), - $this->equalTo('hash'), - $this->equalTo(true), - $this->equalTo($this->user->getUID()) - ); + $this->itemService->expects($this->once()) + ->method('starByGuid') + ->with('tom', 2, 'hash', true); $this->class->star(2, 'hash'); } @@ -247,13 +303,9 @@ class ItemApiControllerTest extends TestCase public function testStarDoesNotExist() { - $this->oldItemService->expects($this->once()) - ->method('star') - ->will( - $this->throwException( - new ServiceNotFoundException($this->msg) - ) - ); + $this->itemService->expects($this->once()) + ->method('starByGuid') + ->will($this->throwException(new ServiceNotFoundException($this->msg))); $response = $this->class->star(2, 'test'); @@ -265,14 +317,9 @@ class ItemApiControllerTest extends TestCase public function testUnstar() { - $this->oldItemService->expects($this->once()) - ->method('star') - ->with( - $this->equalTo(2), - $this->equalTo('hash'), - $this->equalTo(false), - $this->equalTo($this->user->getUID()) - ); + $this->itemService->expects($this->once()) + ->method('starByGuid') + ->with($this->uid, 2, 'hash', false); $this->class->unstar(2, 'hash'); } @@ -280,8 +327,8 @@ class ItemApiControllerTest extends TestCase public function testUnstarDoesNotExist() { - $this->oldItemService->expects($this->once()) - ->method('star') + $this->itemService->expects($this->once()) + ->method('starByGuid') ->will( $this->throwException( new ServiceNotFoundException($this->msg) @@ -298,12 +345,9 @@ class ItemApiControllerTest extends TestCase public function testReadAll() { - $this->oldItemService->expects($this->once()) + $this->itemService->expects($this->once()) ->method('readAll') - ->with( - $this->equalTo(30), - $this->equalTo($this->user->getUID()) - ); + ->with($this->user->getUID(), 30); $this->class->readAll(30); } @@ -312,11 +356,11 @@ class ItemApiControllerTest extends TestCase public function testReadMultiple() { - $this->oldItemService->expects($this->exactly(2)) + $this->itemService->expects($this->exactly(2)) ->method('read') ->withConsecutive( - [2, true, $this->user->getUID()], - [4, true, $this->user->getUID()] + [$this->user->getUID(), 2, true], + [$this->user->getUID(), 4, true] ); $this->class->readMultiple([2, 4]); } @@ -324,24 +368,24 @@ class ItemApiControllerTest extends TestCase public function testReadMultipleDoesntCareAboutException() { - $this->oldItemService->expects($this->exactly(2)) + $this->itemService->expects($this->exactly(2)) ->method('read') ->withConsecutive( - [2, true, $this->user->getUID()], - [4, true, $this->user->getUID()] + [$this->user->getUID(), 2, true], + [$this->user->getUID(), 4, true] ) - ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), null); + ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), new Item()); $this->class->readMultiple([2, 4]); } public function testUnreadMultiple() { - $this->oldItemService->expects($this->exactly(2)) + $this->itemService->expects($this->exactly(2)) ->method('read') ->withConsecutive( - [2, false, $this->user->getUID()], - [4, false, $this->user->getUID()] + [$this->user->getUID(), 2, false], + [$this->user->getUID(), 4, false] ); $this->class->unreadMultiple([2, 4]); } @@ -360,11 +404,11 @@ class ItemApiControllerTest extends TestCase ] ]; - $this->oldItemService->expects($this->exactly(2)) - ->method('star') + $this->itemService->expects($this->exactly(2)) + ->method('starByGuid') ->withConsecutive( - [2, 'a', true, $this->user->getUID()], - [4, 'b', true, $this->user->getUID()] + [$this->user->getUID(), 2, 'a', true], + [$this->user->getUID(), 4, 'b', true] ); $this->class->starMultiple($ids); } @@ -383,13 +427,13 @@ class ItemApiControllerTest extends TestCase ] ]; - $this->oldItemService->expects($this->exactly(2)) - ->method('star') + $this->itemService->expects($this->exactly(2)) + ->method('starByGuid') ->withConsecutive( - [2, 'a', true, $this->user->getUID()], - [4, 'b', true, $this->user->getUID()] + [$this->user->getUID(), 2, 'a', true], + [$this->user->getUID(), 4, 'b', true] ) - ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), null); + ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('')), new Item()); $this->class->starMultiple($ids); } @@ -408,11 +452,11 @@ class ItemApiControllerTest extends TestCase ] ]; - $this->oldItemService->expects($this->exactly(2)) - ->method('star') + $this->itemService->expects($this->exactly(2)) + ->method('starByGuid') ->withConsecutive( - [2, 'a', false, $this->user->getUID()], - [4, 'b', false, $this->user->getUID()] + [$this->user->getUID(), 2, 'a', false], + [$this->user->getUID(), 4, 'b', false] ); $this->class->unstarMultiple($ids); diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index 3048f62f9..546b39278 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -15,7 +15,7 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\ItemController; use OCA\News\Service\FeedServiceV2; -use OCA\News\Service\ItemService; +use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Http; use \OCA\News\Db\Item; @@ -39,7 +39,7 @@ class ItemControllerTest extends TestCase */ private $settings; /** - * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + * @var \PHPUnit\Framework\MockObject\MockObject|ItemServiceV2 */ private $itemService; /** @@ -72,7 +72,7 @@ class ItemControllerTest extends TestCase ->disableOriginalConstructor() ->getMock(); $this->itemService = - $this->getMockBuilder(ItemService::class) + $this->getMockBuilder(ItemServiceV2::class) ->disableOriginalConstructor() ->getMock(); $this->feedService = @@ -106,7 +106,7 @@ class ItemControllerTest extends TestCase { $this->itemService->expects($this->once()) ->method('read') - ->with(4, true, 'user'); + ->with('user', 4, true); $this->controller->read(4, true); } @@ -133,8 +133,8 @@ class ItemControllerTest extends TestCase $this->itemService->expects($this->exactly(2)) ->method('read') ->withConsecutive( - [2, true, 'user'], - [4, true, 'user'] + ['user', 2, true], + ['user', 4, true] ); $this->controller->readMultiple([2, 4]); @@ -147,10 +147,10 @@ class ItemControllerTest extends TestCase $this->itemService->expects($this->exactly(2)) ->method('read') ->withConsecutive( - [2, true, 'user'], - [4, true, 'user'] + ['user', 2, true], + ['user', 4, true] ) - ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('yo')), null); + ->willReturnOnConsecutiveCalls($this->throwException(new ServiceNotFoundException('yo')), new Item()); $this->controller->readMultiple([2, 4]); } @@ -158,8 +158,8 @@ class ItemControllerTest extends TestCase public function testStar() { $this->itemService->expects($this->once()) - ->method('star') - ->with(4, 'test', true, 'user'); + ->method('starByGuid') + ->with('user', 4, 'test', true); $this->controller->star(4, 'test', true); } @@ -170,7 +170,7 @@ class ItemControllerTest extends TestCase $msg = 'ho'; $this->itemService->expects($this->once()) - ->method('star') + ->method('starByGuid') ->will($this->throwException(new ServiceNotFoundException($msg))); $response = $this->controller->star(4, 'test', false); @@ -189,7 +189,7 @@ class ItemControllerTest extends TestCase $this->itemService->expects($this->once()) ->method('readAll') - ->with(5, 'user'); + ->with('user', 5); $this->feedService->expects($this->once()) ->method('findAllForUser') ->with('user') @@ -199,8 +199,14 @@ class ItemControllerTest extends TestCase $this->assertEquals($expected, $response); } - - private function itemsApiExpects($id, $type, $oldestFirst = '1') + /** + * Setup expectations for settings + * + * @param $id + * @param $type + * @param string $oldestFirst + */ + private function itemsApiExpects($id, $type, $oldestFirst = '1'): void { $this->settings->expects($this->exactly(2)) ->method('getUserValue') @@ -218,14 +224,14 @@ class ItemControllerTest extends TestCase } - public function testIndex() + public function testIndexForFeed() { $feeds = [new Feed()]; $result = [ 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3111 + 'starred' => 3 ]; $this->itemsApiExpects(2, FeedType::FEED, '0'); @@ -236,18 +242,18 @@ class ItemControllerTest extends TestCase ->will($this->returnValue($feeds)); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with('user') - ->will($this->returnValue($this->newestItemId)); + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with('user') - ->will($this->returnValue(3111)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('findAllItems') - ->with(2, FeedType::FEED, 3, 0, true, false, 'user', []) + ->method('findAllInFeedWithFilters') + ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); $response = $this->controller->index(FeedType::FEED, 2, 3); @@ -255,14 +261,88 @@ class ItemControllerTest extends TestCase } - public function testIndexSearch() + public function testIndexForFolder() + { + $feeds = [new Feed()]; + $result = [ + 'items' => [new Item()], + 'feeds' => $feeds, + 'newestItemId' => $this->newestItemId, + 'starred' => 3 + ]; + + $this->itemsApiExpects(2, FeedType::FOLDER, '0'); + + $this->feedService->expects($this->once()) + ->method('findAllForUser') + ->with('user') + ->will($this->returnValue($feeds)); + + $this->itemService->expects($this->once()) + ->method('newest') + ->with('user') + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); + + $this->itemService->expects($this->once()) + ->method('starred') + ->with('user') + ->will($this->returnValue([1, 2, 3])); + + $this->itemService->expects($this->once()) + ->method('findAllInFolderWithFilters') + ->with('user', 2, 3, 0, false, false, []) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->index(FeedType::FOLDER, 2, 3); + $this->assertEquals($result, $response); + } + + + public function testIndexForOther() { $feeds = [new Feed()]; $result = [ 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3111 + 'starred' => 3 + ]; + + $this->itemsApiExpects(2, FeedType::STARRED, '0'); + + $this->feedService->expects($this->once()) + ->method('findAllForUser') + ->with('user') + ->will($this->returnValue($feeds)); + + $this->itemService->expects($this->once()) + ->method('newest') + ->with('user') + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); + + $this->itemService->expects($this->once()) + ->method('starred') + ->with('user') + ->will($this->returnValue([1, 2, 3])); + + $this->itemService->expects($this->once()) + ->method('findAllWithFilters') + ->with('user', 2, 3, 0, false, []) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->index(FeedType::STARRED, 2, 3); + $this->assertEquals($result, $response); + } + + + public function testIndexSearchFeed() + { + $feeds = [new Feed()]; + $result = [ + 'items' => [new Item()], + 'feeds' => $feeds, + 'newestItemId' => $this->newestItemId, + 'starred' => 3 ]; $this->itemsApiExpects(2, FeedType::FEED, '0'); @@ -273,18 +353,18 @@ class ItemControllerTest extends TestCase ->will($this->returnValue($feeds)); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with('user') - ->will($this->returnValue($this->newestItemId)); + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with('user') - ->will($this->returnValue(3111)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('findAllItems') - ->with(2, FeedType::FEED, 3, 0, true, false, 'user', ['test', 'search']) + ->method('findAllInFeedWithFilters') + ->with('user', 2, 3, 0, false, false, ['test', 'search']) ->will($this->returnValue($result['items'])); $response = $this->controller->index(FeedType::FEED, 2, 3, 0, null, null, 'test%20%20search%20'); @@ -299,8 +379,8 @@ class ItemControllerTest extends TestCase $this->itemsApiExpects(2, FeedType::FEED); $this->itemService->expects($this->once()) - ->method('findAllItems') - ->with(2, FeedType::FEED, 3, 10, true, true, 'user') + ->method('findAllInFeedWithFilters') + ->with('user', 2, 3, 10, false, true) ->will($this->returnValue($result['items'])); $this->feedService->expects($this->never()) @@ -316,7 +396,7 @@ class ItemControllerTest extends TestCase $this->itemsApiExpects(2, FeedType::FEED); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with('user') ->will($this->throwException(new ServiceNotFoundException(''))); @@ -325,14 +405,14 @@ class ItemControllerTest extends TestCase } - public function testNewItems() + public function testNewItemsFeed() { $feeds = [new Feed()]; $result = [ 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3111 + 'starred' => 3 ]; $this->settings->expects($this->once()) @@ -346,18 +426,18 @@ class ItemControllerTest extends TestCase ->will($this->returnValue($feeds)); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with('user') - ->will($this->returnValue($this->newestItemId)); + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); $this->itemService->expects($this->once()) - ->method('starredCount') + ->method('starred') ->with('user') - ->will($this->returnValue(3111)); + ->will($this->returnValue([1, 2, 3])); $this->itemService->expects($this->once()) - ->method('findAllNew') - ->with(2, FeedType::FEED, 3, true, 'user') + ->method('findAllInFeedAfter') + ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); $response = $this->controller->newItems(FeedType::FEED, 2, 3); @@ -365,6 +445,86 @@ class ItemControllerTest extends TestCase } + public function testNewItemsFolder() + { + $feeds = [new Feed()]; + $result = [ + 'items' => [new Item()], + 'feeds' => $feeds, + 'newestItemId' => $this->newestItemId, + 'starred' => 3 + ]; + + $this->settings->expects($this->once()) + ->method('getUserValue') + ->with('user', $this->appName, 'showAll') + ->will($this->returnValue('1')); + + $this->feedService->expects($this->once()) + ->method('findAllForUser') + ->with('user') + ->will($this->returnValue($feeds)); + + $this->itemService->expects($this->once()) + ->method('newest') + ->with('user') + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); + + $this->itemService->expects($this->once()) + ->method('starred') + ->with('user') + ->will($this->returnValue([1, 2, 3])); + + $this->itemService->expects($this->once()) + ->method('findAllInFolderAfter') + ->with('user', 2, 3, false) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->newItems(FeedType::FOLDER, 2, 3); + $this->assertEquals($result, $response); + } + + + public function testNewItemsOther() + { + $feeds = [new Feed()]; + $result = [ + 'items' => [new Item()], + 'feeds' => $feeds, + 'newestItemId' => $this->newestItemId, + 'starred' => 3 + ]; + + $this->settings->expects($this->once()) + ->method('getUserValue') + ->with('user', $this->appName, 'showAll') + ->will($this->returnValue('1')); + + $this->feedService->expects($this->once()) + ->method('findAllForUser') + ->with('user') + ->will($this->returnValue($feeds)); + + $this->itemService->expects($this->once()) + ->method('newest') + ->with('user') + ->will($this->returnValue(Item::fromParams(['id' => $this->newestItemId]))); + + $this->itemService->expects($this->once()) + ->method('starred') + ->with('user') + ->will($this->returnValue([1, 2, 3])); + + $this->itemService->expects($this->once()) + ->method('findAllAfter') + ->with('user', 6, 3) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->newItems(FeedType::UNREAD, 2, 3); + $this->assertEquals($result, $response); + } + + public function testGetNewItemsNoNewestItemsId() { $this->settings->expects($this->once()) @@ -373,7 +533,7 @@ class ItemControllerTest extends TestCase ->will($this->returnValue('1')); $this->itemService->expects($this->once()) - ->method('getNewestItemId') + ->method('newest') ->with('user') ->will($this->throwException(new ServiceNotFoundException(''))); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 2f259b316..5f62bfe9f 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -16,6 +16,7 @@ namespace OCA\News\Tests\Unit\Controller; use OC\L10N\L10N; use OCA\News\Controller\PageController; use \OCA\News\Db\FeedType; +use OCA\News\Explore\Exceptions\RecommendedSiteNotFoundException; use OCA\News\Explore\RecommendedSites; use OCA\News\Service\StatusService; use OCP\IConfig; @@ -26,7 +27,6 @@ use OCP\IUser; use OCP\IUserSession; use PHPUnit\Framework\TestCase; - class PageControllerTest extends TestCase { @@ -278,4 +278,24 @@ class PageControllerTest extends TestCase } + public function testExploreError() + { + $this->settings->expects($this->exactly(2)) + ->method('setUserValue') + ->withConsecutive( + ['becka', 'news', 'lastViewedFeedId', 0], + ['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE] + ); + + $this->recommended->expects($this->once()) + ->method('forLanguage') + ->with('nl') + ->will($this->throwException(new RecommendedSiteNotFoundException('error'))); + + $out = $this->controller->explore('nl'); + + $this->assertEquals(404, $out->getStatus()); + + } + } diff --git a/tests/Unit/Db/FeedMapperTest.php b/tests/Unit/Db/FeedMapperTest.php index c14b8995f..780bfbc38 100644 --- a/tests/Unit/Db/FeedMapperTest.php +++ b/tests/Unit/Db/FeedMapperTest.php @@ -69,7 +69,7 @@ class FeedMapperTest extends MapperTestUtility ->getMock(); $func = $this->getMockBuilder(IQueryFunction::class) - ->getMock(); + ->getMock(); $funcbuilder->expects($this->once()) ->method('count') @@ -451,4 +451,94 @@ class FeedMapperTest extends MapperTestUtility $result = $this->class->findAllFromFolder(null); $this->assertEquals($this->feeds, $result); } + + /** + * @covers \OCA\News\Db\FeedMapperV2::read + */ + public function testRead() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('update') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('setValue') + ->with('unread', 0) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['feeds.user_id = :userId'], ['feeds.id = :feedId']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['userId', 'admin'], ['feedId', 1]) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('getSQL') + ->will($this->returnValue('QUERY')); + + $this->db->expects($this->exactly(1)) + ->method('executeUpdate') + ->with('QUERY'); + + $this->class->read('admin', 1); + } + + /** + * @covers \OCA\News\Db\FeedMapperV2::read + */ + public function testReadWithMaxId() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('update') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('setValue') + ->with('unread', 0) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive(['feeds.user_id = :userId'], ['feeds.id = :feedId'], ['items.id =< :maxItemId']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive(['userId', 'admin'], ['feedId', 1], ['maxItemId', 4]) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('getSQL') + ->will($this->returnValue('QUERY')); + + $this->db->expects($this->exactly(1)) + ->method('executeUpdate') + ->with('QUERY'); + + $this->class->read('admin', 1, 4); + } }
\ No newline at end of file diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index dd87b22b5..026c16bc6 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.php @@ -279,4 +279,94 @@ class FolderMapperTest extends MapperTestUtility $result = $this->class->findAll(); $this->assertEquals($this->folders, $result); } + + /** + * @covers \OCA\News\Db\FolderMapperV2::read + */ + public function testRead() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('update') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('setValue') + ->with('unread', 0) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['feeds.user_id = :userId'], ['feeds.folder_id = :folderId']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['userId', 'admin'], ['folderId', 1]) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('getSQL') + ->will($this->returnValue('QUERY')); + + $this->db->expects($this->exactly(1)) + ->method('executeUpdate') + ->with('QUERY'); + + $this->class->read('admin', 1); + } + + /** + * @covers \OCA\News\Db\FolderMapperV2::read + */ + public function testReadWithMaxId() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('update') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('setValue') + ->with('unread', 0) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive(['feeds.user_id = :userId'], ['feeds.folder_id = :folderId'], ['items.id =< :maxItemId']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive(['userId', 'admin'], ['folderId', 1], ['maxItemId', 4]) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('getSQL') + ->will($this->returnValue('QUERY')); + + $this->db->expects($this->exactly(1)) + ->method('executeUpdate') + ->with('QUERY'); + + $this->class->read('admin', 1, 4); + } }
\ No newline at end of file diff --git a/tests/Unit/Db/ItemMapperTest.php b/tests/Unit/Db/ItemMapperTest.php new file mode 100644 index 000000000..220805061 --- /dev/null +++ b/tests/Unit/Db/ItemMapperTest.php @@ -0,0 +1,2360 @@ +<?php +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt + */ + +namespace OCA\News\Tests\Unit\Db; + +use OCA\News\Db\Feed; +use OCA\News\Db\FeedMapperV2; +use OCA\News\Db\Folder; +use OCA\News\Db\Item; +use OCA\News\Db\ItemMapperV2; +use OCA\News\Db\NewsMapperV2; +use OCA\News\Service\Exceptions\ServiceValidationException; +use OCA\News\Utility\Time; +use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Db\MultipleObjectsReturnedException; +use OCP\DB\IResult; +use OCP\DB\QueryBuilder\IExpressionBuilder; +use OCP\DB\QueryBuilder\IFunctionBuilder; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\DB\QueryBuilder\IQueryFunction; +use OCP\IDBConnection; +use Test\TestCase; + +/** + * Class ItemMapperTest + * + * @package OCA\News\Tests\Unit\Db + */ +class ItemMapperTest extends MapperTestUtility +{ + + /** @var Time */ + private $time; + /** @var ItemMapperV2 */ + private $class; + + /** + * @covers \OCA\News\Db\ItemMapperV2::__construct + */ + protected function setUp(): void + { + parent::setUp(); + $this->time = $this->getMockBuilder(Time::class) + ->getMock(); + + $this->class = new ItemMapperV2($this->db, $this->time); + } + + /** + * @covers \OCA\News\Db\ItemMapperV2::__construct + */ + public function testSetUpSuccess(): void + { + $this->assertEquals('news_items', $this->class->getTableName()); + } + + /** + * @covers \OCA\News\Db\ItemMapperV2::findAllFromUser + */ + public function testFindAllFromUser() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('where') + ->with('feeds.user_id = :user_id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('andWhere') + ->with('feeds.deleted_at = 0') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->withConsecutive(['user_id', 'jack']) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + ['id' => 5], + null + ); + + $result = $this->class->findAllFromUser('jack', []); + $this->assertEquals([Item::fromRow(['id' => 4]), Item::fromRow(['id' => 5])], $result); + } + + /** + * @covers \OCA\News\Db\ItemMapperV2::findAllFromUser + */ + public function testFindAllFromUserWithParams() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('createNamedParameter') + ->with('val') + ->will($this->returnValue(':val')); + + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('where') + ->with('feeds.user_id = :user_id') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['feeds.deleted_at = 0'], ['key = :val']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->withConsecutive(['user_id', 'jack']) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + ['id' => 5], + null + ); + + $result = $this->class->findAllFromUser('jack', ['key' => 'val']); + $this->assertEquals([Item::fromRow(['id' => 4]), Item::fromRow(['id' => 5])], $result); + } + + /** + * @covers \OCA\News\Db\ItemMapperV2::findAll + */ + public function testFindAll() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('andWhere') + ->with('feeds.deleted_at = 0') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + ['id' => 5], + null + ); + + $result = $this->class->findAll(); + $this->assertEquals([Item::fromRow(['id' => 4]), Item::fromRow(['id' => 5])], $result); + } + + /** + * @covers \OCA\News\Db\ItemMapperV2::findAllForFeed + */ + public function testFindAllForFeed() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('where') + ->with('feed_id = :feed_identifier') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('setParameter') + ->with('feed_identifier', 4) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(3)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + ['id' => 5], + null + ); + + $result = $this->class->findAllForFeed(4); + $this->assertEquals([Item::fromRow(['id' => 4]), Item::fromRow(['id' => 5])], $result); + } + + public function testFindFromUser() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('where') + ->with('feeds.user_id = :user_id') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['items.id = :item_id'], ['feeds.deleted_at = 0']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['user_id', 'jack'], ['item_id', 4]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findFromUser('jack', 4); + $this->assertEquals(Item::fromRow(['id' => 4]), $result); + } + + public function testFindByGUIDHash() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['feed_id = :feed_id'], ['guid_hash = :guid_hash']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['feed_id', 4], ['guid_hash', 'hash']) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findByGuidHash(4, 'hash'); + $this->assertEquals(Item::fromRow(['id' => 4]), $result); + } + + public function testFindForUserByGUIDHash() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive(['feeds.user_id = :user_id'], ['feeds.id = :feed_id'], ['items.guid_hash = :guid_hash']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive(['user_id', 'jack'], ['feed_id', 4], ['guid_hash', 'hash']) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findForUserByGuidHash('jack', 4, 'hash'); + $this->assertEquals(Item::fromRow(['id' => 4]), $result); + } + + public function testNewest() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('where') + ->withConsecutive(['feeds.user_id = :userId']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(1) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->newest('jack'); + $this->assertEquals(Item::fromRow(['id' => 4]), $result); + } + + public function testFindAllInFeedAfter() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'], + ['feeds.id = :feedId'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'feedId' => 4, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllInFeedAfter('jack', 4, 1610903351, false); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllInFeedAfterHideRead() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'], + ['feeds.id = :feedId'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'feedId' => 4, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllInFeedAfter('jack', 4, 1610903351, true); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllInFolderAfter() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('innerJoin') + ->withConsecutive( + ['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'], + ['feeds', 'news_folders', 'folders', 'feeds.folder_id = folders.id'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'], + ['folders.id = :folderId'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'folderId' => 4, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllInFolderAfter('jack', 4, 1610903351, false); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllInFolderAfterHideRead() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('innerJoin') + ->withConsecutive( + ['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'], + ['feeds', 'news_folders', 'folders', 'feeds.folder_id = folders.id'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'], + ['folders.id = :folderId'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'folderId' => 4, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllInFolderAfter('jack', 4, 1610903351, true); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllAfterUnread() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllAfter('jack', 6, 1610903351); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllAfterStarred() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'], + ['items.starred = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->once()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllAfter('jack', 2, 1610903351); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllAfterInvalid() + { + $this->expectException(ServiceValidationException::class); + $this->expectExceptionMessage('Unexpected Feed type in call'); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive( + ['items.updated_date >= :updatedSince'], + ['feeds.user_id = :userId'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'userId' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->never()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->never()) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllAfter('jack', 232, 1610903351); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllItemsInvalid() + { + $this->expectException(ServiceValidationException::class); + $this->expectExceptionMessage('Unexpected Feed type in call'); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->with('userId', 'jack') + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->never()) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->never()) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $this->class->findAllItems('jack', 232, 10, 10, false, []); + } + + public function testFindAllItemsUnread() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->with('userId', 'jack') + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllItems('jack', 6, 10, 10, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllItemsStarred() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['items.starred = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->with('userId', 'jack') + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllItems('jack', 2, 10, 10, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllItemsStarredSearch() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + $this->db->expects($this->exactly(2)) + ->method('escapeLikeParameter') + ->will($this->returnArgument(0)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['items.search_index LIKE :term0'], + ['items.search_index LIKE :term1'], + ['items.starred = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['term0', '%key%'], ['term1', '%word%']) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllItems('jack', 2, 10, 10, false, ['key', 'word']); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFeed() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['items.feed_id = :feedId'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['feedId', 2]) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFeed('jack', 2, 10, 10, false, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFeedHideRead() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['items.feed_id = :feedId'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['feedId', 2]) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFeed('jack', 2, 10, 10, true, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFeedSearch() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + $this->db->expects($this->exactly(2)) + ->method('escapeLikeParameter') + ->will($this->returnArgument(0)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['items.feed_id = :feedId'], + ['items.search_index LIKE :term0'], + ['items.search_index LIKE :term1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['feedId', 2], ['term0', '%key%'], ['term1', '%word%']) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFeed('jack', 2, 10, 10, false, false, ['key', 'word']); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFolderIdNull() + { + $expr = $this->getMockBuilder(IExpressionBuilder::class) + ->getMock(); + + $expr->expects($this->once()) + ->method('isNull') + ->with('feeds.folder_id') + ->will($this->returnValue('x IS NULL')); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->exactly(1)) + ->method('expr') + ->will($this->returnValue($expr)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['x IS NULL'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack']) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFolder('jack', null, 10, 10, false, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFolderHideRead() + { + $expr = $this->getMockBuilder(IExpressionBuilder::class) + ->getMock(); + + $expr->expects($this->once()) + ->method('isNull') + ->with('feeds.folder_id') + ->will($this->returnValue('x IS NULL')); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->exactly(1)) + ->method('expr') + ->will($this->returnValue($expr)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['x IS NULL'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack']) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFolder('jack', null, 10, 10, true, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFolderHideReadInvertOrder() + { + $expr = $this->getMockBuilder(IExpressionBuilder::class) + ->getMock(); + + $expr->expects($this->once()) + ->method('isNull') + ->with('feeds.folder_id') + ->will($this->returnValue('x IS NULL')); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->exactly(1)) + ->method('expr') + ->will($this->returnValue($expr)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['x IS NULL'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack']) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'ASC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'ASC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFolder('jack', null, 10, 10, true, true, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllFolderSearchId() + { + $expr = $this->getMockBuilder(IExpressionBuilder::class) + ->getMock(); + + $expr->expects($this->once()) + ->method('eq') + ->with('feeds.folder_id', 2) + ->will($this->returnValue('x = y')); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + $this->db->expects($this->exactly(2)) + ->method('escapeLikeParameter') + ->will($this->returnArgument(0)); + + $this->builder->expects($this->exactly(1)) + ->method('expr') + ->will($this->returnValue($expr)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['x = y'], + ['items.search_index LIKE :term0'], + ['items.search_index LIKE :term1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['term0', '%key%'], ['term1', '%word%']) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setMaxResults') + ->with(10) + ->will($this->returnSelf()); + + + $this->builder->expects($this->exactly(1)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.updated_date', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFolder('jack', 2, 10, 10, false, false, ['key', 'word']); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testReadAll() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('update') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('setValue') + ->with('unread', 0) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['items.id =< :maxItemId'], ['feeds.user_id = :userId']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['maxItemId', 4], ['userId', 'jack']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('getSQL') + ->will($this->returnValue('QUERY')); + + $this->db->expects($this->once()) + ->method('executeUpdate') + ->with('QUERY'); + + $this->class->readAll('jack', 4); + } + + public function testPurgeDeletedEmpty() + { + $this->db->expects($this->never()) + ->method('getQueryBuilder'); + + $this->class->purgeDeleted('jack', 4); + } + + public function testDeleteOverThresholdEmptyFeeds() + { + $builder1 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $func_builder = $this->getMockBuilder(IFunctionBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $func = $this->getMockBuilder(IQueryFunction::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->db->expects($this->exactly(1)) + ->method('getQueryBuilder') + ->willReturnOnConsecutiveCalls($builder1); + + $builder1->expects($this->exactly(2)) + ->method('func') + ->willReturn($func_builder); + + $func_builder->expects($this->exactly(1)) + ->method('count') + ->with('*', 'itemCount') + ->willReturn($func); + + $func_builder->expects($this->exactly(1)) + ->method('max') + ->with('feeds.articles_per_update') + ->willReturn($func); + + $builder1->expects($this->once()) + ->method('select') + ->with('feed_id', $func) + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('selectAlias') + ->with($func, 'articlesPerUpdate') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('groupBy') + ->with('feed_id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('getSQL') + ->willReturn('FEED_SQL'); + + $this->class->deleteOverThreshold(1, true); + } + + public function testDeleteOverThresholdSuccess() + { + $builder1 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $builder2 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $builder3 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $result1 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $result2 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $result3 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $func_builder = $this->getMockBuilder(IFunctionBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $func = $this->getMockBuilder(IQueryFunction::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->db->expects($this->exactly(3)) + ->method('getQueryBuilder') + ->willReturnOnConsecutiveCalls($builder1, $builder2, $builder3); + + $builder1->expects($this->exactly(2)) + ->method('func') + ->willReturn($func_builder); + + $func_builder->expects($this->exactly(1)) + ->method('count') + ->with('*', 'itemCount') + ->willReturn($func); + + $func_builder->expects($this->exactly(1)) + ->method('max') + ->with('feeds.articles_per_update') + ->willReturn($func); + + $builder1->expects($this->once()) + ->method('select') + ->with('feed_id', $func) + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('selectAlias') + ->with($func, 'articlesPerUpdate') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('groupBy') + ->with('feed_id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('getSQL') + ->willReturn('FEED_SQL'); + + $this->db->expects($this->exactly(3)) + ->method('executeQuery') + ->withConsecutive( + ['FEED_SQL'], + ['RANGE_SQL', ['feedId' => 5], []], + ['RANGE_SQL', ['feedId' => 1], []] + ) + ->willReturnOnConsecutiveCalls($result1, $result2, $result3); + + $result1->expects($this->once()) + ->method('fetchAll') + ->with(2) + ->willReturn([ + ['itemCount' => 5, 'articlesPerUpdate' => 5, 'feed_id' => 5], + ['itemCount' => 1, 'articlesPerUpdate' => 1, 'feed_id' => 1], + ]); + + $builder2->expects($this->once()) + ->method('select') + ->with('id') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('from') + ->with('news_items') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('where') + ->with('feed_id = :feedId') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('andWhere') + ->with('starred = false') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('orderBy') + ->with('last_modified', 'DESC') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('addOrderBy') + ->with('id', 'DESC') + ->willReturnSelf(); + + $builder2->expects($this->exactly(2)) + ->method('getSQL') + ->willReturn('RANGE_SQL'); + + $result2->expects($this->once()) + ->method('fetchAll') + ->with(7) + ->willReturn([4, 6, 8]); + + $result3->expects($this->once()) + ->method('fetchAll') + ->with(7) + ->willReturn([3, 5, 7]); + + $builder3->expects($this->once()) + ->method('delete') + ->with('news_items') + ->willReturnSelf(); + + $builder3->expects($this->once()) + ->method('where') + ->with('id IN (?)') + ->willReturnSelf(); + + $builder3->expects($this->exactly(1)) + ->method('getSQL') + ->willReturn('DELETE_SQL'); + + $this->db->expects($this->once()) + ->method('executeUpdate') + ->with('DELETE_SQL', [[4, 6, 8, 3, 5, 7]], [101]) + ->will($this->returnValue(10)); + + $res = $this->class->deleteOverThreshold(1, true); + $this->assertSame(10, $res); + } + + public function testDeleteOverThresholdSuccessUnread() + { + $builder1 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $builder2 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $builder3 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $result1 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $result2 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $result3 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $func_builder = $this->getMockBuilder(IFunctionBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $func = $this->getMockBuilder(IQueryFunction::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->db->expects($this->exactly(3)) + ->method('getQueryBuilder') + ->willReturnOnConsecutiveCalls($builder1, $builder2, $builder3); + + $builder1->expects($this->exactly(2)) + ->method('func') + ->willReturn($func_builder); + + $func_builder->expects($this->exactly(1)) + ->method('count') + ->with('*', 'itemCount') + ->willReturn($func); + + $func_builder->expects($this->exactly(1)) + ->method('max') + ->with('feeds.articles_per_update') + ->willReturn($func); + + $builder1->expects($this->once()) + ->method('select') + ->with('feed_id', $func) + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('selectAlias') + ->with($func, 'articlesPerUpdate') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('groupBy') + ->with('feed_id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('getSQL') + ->willReturn('FEED_SQL'); + + $this->db->expects($this->exactly(3)) + ->method('executeQuery') + ->withConsecutive( + ['FEED_SQL'], + ['RANGE_SQL', ['feedId' => 5], []], + ['RANGE_SQL', ['feedId' => 1], []] + ) + ->willReturnOnConsecutiveCalls($result1, $result2, $result3); + + $result1->expects($this->once()) + ->method('fetchAll') + ->with(2) + ->willReturn([ + ['itemCount' => 5, 'articlesPerUpdate' => 5, 'feed_id' => 5], + ['itemCount' => 1, 'articlesPerUpdate' => 1, 'feed_id' => 1], + ]); + + $builder2->expects($this->once()) + ->method('select') + ->with('id') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('from') + ->with('news_items') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('where') + ->with('feed_id = :feedId') + ->willReturnSelf(); + + $builder2->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['starred = false'], ['unread = false']) + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('orderBy') + ->with('last_modified', 'DESC') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('addOrderBy') + ->with('id', 'DESC') + ->willReturnSelf(); + + $builder2->expects($this->exactly(2)) + ->method('getSQL') + ->willReturn('RANGE_SQL'); + + $result2->expects($this->once()) + ->method('fetchAll') + ->with(7) + ->willReturn([4, 6, 8]); + + $result3->expects($this->once()) + ->method('fetchAll') + ->with(7) + ->willReturn([3, 5, 7]); + + $builder3->expects($this->once()) + ->method('delete') + ->with('news_items') + ->willReturnSelf(); + + $builder3->expects($this->once()) + ->method('where') + ->with('id IN (?)') + ->willReturnSelf(); + + $builder3->expects($this->exactly(1)) + ->method('getSQL') + ->willReturn('DELETE_SQL'); + + $this->db->expects($this->once()) + ->method('executeUpdate') + ->with('DELETE_SQL', [[4, 6, 8, 3, 5, 7]], [101]) + ->will($this->returnValue(10)); + + $res = $this->class->deleteOverThreshold(1, false); + $this->assertSame(10, $res); + } + + public function testDeleteOverThresholdSuccessUnreadSkipsIfUnderThreshold() + { + $builder1 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $builder2 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $builder3 = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $result1 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $result2 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $result3 = $this->getMockBuilder(IResult::class) + ->disableOriginalConstructor() + ->getMock(); + $func_builder = $this->getMockBuilder(IFunctionBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $func = $this->getMockBuilder(IQueryFunction::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->db->expects($this->exactly(3)) + ->method('getQueryBuilder') + ->willReturnOnConsecutiveCalls($builder1, $builder2, $builder3); + + $builder1->expects($this->exactly(2)) + ->method('func') + ->willReturn($func_builder); + + $func_builder->expects($this->exactly(1)) + ->method('count') + ->with('*', 'itemCount') + ->willReturn($func); + + $func_builder->expects($this->exactly(1)) + ->method('max') + ->with('feeds.articles_per_update') + ->willReturn($func); + + $builder1->expects($this->once()) + ->method('select') + ->with('feed_id', $func) + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('selectAlias') + ->with($func, 'articlesPerUpdate') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('innerJoin') + ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('groupBy') + ->with('feed_id') + ->willReturnSelf(); + + $builder1->expects($this->once()) + ->method('getSQL') + ->willReturn('FEED_SQL'); + + $this->db->expects($this->exactly(2)) + ->method('executeQuery') + ->withConsecutive( + ['FEED_SQL'], + ['RANGE_SQL', ['feedId' => 5], []] + ) + ->willReturnOnConsecutiveCalls($result1, $result2, $result3); + + $result1->expects($this->once()) + ->method('fetchAll') + ->with(2) + ->willReturn([ + ['itemCount' => 5, 'articlesPerUpdate' => 5, 'feed_id' => 5], + ['itemCount' => 1, 'articlesPerUpdate' => 1, 'feed_id' => 1], + ]); + + $builder2->expects($this->once()) + ->method('select') + ->with('id') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('from') + ->with('news_items') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('where') + ->with('feed_id = :feedId') + ->willReturnSelf(); + + $builder2->expects($this->exactly(2)) + ->method('andWhere') + ->withConsecutive(['starred = false'], ['unread = false']) + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('orderBy') + ->with('last_modified', 'DESC') + ->willReturnSelf(); + + $builder2->expects($this->once()) + ->method('addOrderBy') + ->with('id', 'DESC') + ->willReturnSelf(); + + $builder2->expects($this->exactly(1)) + ->method('getSQL') + ->willReturn('RANGE_SQL'); + + $result2->expects($this->once()) + ->method('fetchAll') + ->with(7) + ->willReturn([4, 6, 8]); + + $result3->expects($this->never()) + ->method('fetchAll') + ->with(7) + ->willReturn([3, 5, 7]); + + $builder3->expects($this->once()) + ->method('delete') + ->with('news_items') + ->willReturnSelf(); + + $builder3->expects($this->once()) + ->method('where') + ->with('id IN (?)') + ->willReturnSelf(); + + $builder3->expects($this->exactly(1)) + ->method('getSQL') + ->willReturn('DELETE_SQL'); + + $this->db->expects($this->once()) + ->method('executeUpdate') + ->with('DELETE_SQL', [[4, 6, 8]], [101]) + ->will($this->returnValue(10)); + + $res = $this->class->deleteOverThreshold(3, false); + $this->assertSame(10, $res); + } + +}
\ No newline at end of file diff --git a/tests/Unit/Db/MapperFactoryTest.php b/tests/Unit/Db/MapperFactoryTest.php deleted file mode 100644 index 1c4e2f4b6..000000000 --- a/tests/Unit/Db/MapperFactoryTest.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -/** - * Nextcloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - */ - -namespace OCA\News\Tests\Unit\Db; - -use OCA\News\Db\ItemMapper; -use OCA\News\Db\MapperFactory; -use OCA\News\Utility\Time; -use PHPUnit\Framework\TestCase; - -use OCP\IDBConnection; - -use OCA\News\Db\Mysql\ItemMapper as MysqlMapper; - - -class MapperFactoryTest extends TestCase -{ - - /** - * @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection - */ - private $db; - - public function setUp(): void - { - $this->db = $this->getMockBuilder(IDBConnection::class) - ->disableOriginalConstructor() - ->getMock(); - } - - public function testGetItemMapperSqlite() - { - $factory = new MapperFactory($this->db, 'sqlite', new Time()); - $this->assertTrue($factory->build() instanceof ItemMapper); - } - - public function testGetItemMapperPostgres() - { - $factory = new MapperFactory($this->db, 'pgsql', new Time()); - $this->assertTrue($factory->build() instanceof ItemMapper); - } - - public function testGetItemMapperMysql() - { - $factory = new MapperFactory($this->db, 'mysql', new Time()); - $this->assertTrue($factory->build() instanceof MysqlMapper); - } - -} diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php index 3aa1d8aed..4a875fde5 100644 --- a/tests/Unit/Db/MapperTestUtility.php +++ b/tests/Unit/Db/MapperTestUtility.php @@ -24,6 +24,7 @@ namespace OCA\News\Tests\Unit\Db; use Doctrine\DBAL\Driver\Statement; +use OC\DB\QueryBuilder\QueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -74,6 +75,7 @@ abstract class MapperTestUtility extends TestCase ->getMock(); $this->builder = $this->getMockBuilder(IQueryBuilder::class) + ->disableOriginalConstructor() ->getMock(); $this->cursor = $this->getMockBuilder(Statement::class) diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index f869a3ef7..9f4743777 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.php @@ -815,8 +815,8 @@ class FeedServiceTest extends TestCase ->will($this->returnValue([$feed1, $feed2])); $this->itemService->expects($this->exactly(2)) - ->method('findAllForFeed') - ->withConsecutive([1], [2]) + ->method('findAllInFeed') + ->withConsecutive(['jack', 1], ['jack', 2]) ->willReturn(['a']); $feeds = $this->class->findAllForUserRecursive($this->uid); @@ -824,4 +824,21 @@ class FeedServiceTest extends TestCase $this->assertEquals(['a'], $feeds[1]->items); } + public function testRead() + { + $feed1 = new Feed(); + $feed1->setId(1); + + $this->mapper->expects($this->once()) + ->method('findFromUser') + ->with($this->uid, 1) + ->will($this->returnValue($feed1)); + + $this->mapper->expects($this->exactly(1)) + ->method('read') + ->withConsecutive(['jack', 1, null]); + + $this->class->read($this->uid, 1); + } + } diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 2b55ee01a..3e7e98041 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -262,4 +262,21 @@ class FolderServiceTest extends TestCase } + public function testRead() + { + $folder = new Folder(); + $folder->setId(1); + + $this->mapper->expects($this->once()) + ->method('findFromUser') + ->with('jack', 1) + ->will($this->returnValue($folder)); + + $this->mapper->expects($this->exactly(1)) + ->method('read') + ->withConsecutive(['jack', 1, null]); + + $this->class->read('jack', 1); + } + } diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 96d22235a..e82d5eda7 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -13,84 +13,63 @@ namespace OCA\News\Tests\Unit\Service; -use OC\Log; -use OCA\News\Db\ItemMapper; use OCA\News\Db\ItemMapperV2; -use OCA\News\Service\ItemService; +use OCA\News\Service\Exceptions\ServiceConflictException; +use OCA\News\Service\Exceptions\ServiceValidationException; use OCA\News\Service\Exceptions\ServiceNotFoundException; -use OCA\News\Utility\PsrLogger; -use OCA\News\Utility\Time; +use OCA\News\Service\ItemServiceV2; use \OCP\AppFramework\Db\DoesNotExistException; use \OCA\News\Db\Item; use \OCA\News\Db\FeedType; +use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; - +/** + * Class ItemServiceTest + * + * @package OCA\News\Tests\Unit\Service + */ class ItemServiceTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper - */ - private $oldItemMapper; - - /** - * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapperV2 + * @var MockObject|ItemMapperV2 */ private $mapper; /** - * @var ItemService + * @var ItemServiceV2 */ - private $itemService; + private $class; /** - * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + * @var MockObject|IConfig */ private $config; /** - * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface + * @var MockObject|LoggerInterface */ private $logger; - - /** - * @var \PHPUnit\Framework\MockObject\MockObject|Time - */ - private $timeFactory; - /** * @var int */ private $newestItemId; - /** * @var string */ - private $time; + private $user; protected function setUp(): void { - $this->time = '222'; - $this->timeFactory = $this->getMockBuilder(Time::class) - ->disableOriginalConstructor() - ->getMock(); - $this->timeFactory->expects($this->any()) - ->method('getTime') - ->will($this->returnValue($this->time)); - $this->timeFactory->expects($this->any()) - ->method('getMicroTime') - ->will($this->returnValue($this->time)); $this->mapper = $this->getMockBuilder(ItemMapperV2::class) ->disableOriginalConstructor() ->getMock(); - $this->oldItemMapper = $this->getMockBuilder(ItemMapper::class) - ->disableOriginalConstructor() - ->getMock(); $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); @@ -99,10 +78,8 @@ class ItemServiceTest extends TestCase ->disableOriginalConstructor() ->getMock(); - $this->itemService = new ItemService( + $this->class = new ItemServiceV2( $this->mapper, - $this->oldItemMapper, - $this->timeFactory, $this->config, $this->logger ); @@ -115,164 +92,126 @@ class ItemServiceTest extends TestCase $this->newestItemId = 4; } - public function testFindAllNewFeed() { - $type = FeedType::FEED; - $this->oldItemMapper->expects($this->once()) - ->method('findAllNewFeed') - ->with( - $this->equalTo(3), - $this->equalTo(20333), - $this->equalTo(true), - $this->equalTo('jack') - ) + $this->mapper->expects($this->once()) + ->method('findAllInFeedAfter') + ->with('jack', 2, 20333, true) ->will($this->returnValue([])); - $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack'); + $result = $this->class->findAllInFeedAfter($this->user, 2, 20333, true); $this->assertEquals([], $result); } - public function testFindAllNewFolder() { - $type = FeedType::FOLDER; - $this->oldItemMapper->expects($this->once()) - ->method('findAllNewFolder') - ->with( - $this->equalTo(3), - $this->equalTo(20333), - $this->equalTo(true), - $this->equalTo('jack') - ) - ->will($this->returnValue(['val'])); + $this->mapper->expects($this->once()) + ->method('findAllInFolderAfter') + ->with('jack', 2, 20333, true) + ->will($this->returnValue([])); - $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack'); - $this->assertEquals(['val'], $result); + $result = $this->class->findAllInFolderAfter($this->user, 2, 20333, true); + $this->assertEquals([], $result); } - - public function testFindAllNew() + public function testFindAllNewItem() { - $type = FeedType::STARRED; - $this->oldItemMapper->expects($this->once()) - ->method('findAllNew') - ->with( - $this->equalTo(20333), - $this->equalTo($type), - $this->equalTo(true), - $this->equalTo('jack') - ) - ->will($this->returnValue(['val'])); + $this->mapper->expects($this->once()) + ->method('findAllAfter') + ->with('jack', 2, 20333) + ->will($this->returnValue([])); - $result = $this->itemService->findAllNew( - 3, $type, 20333, true, - 'jack' - ); - $this->assertEquals(['val'], $result); + $result = $this->class->findAllAfter($this->user, 2, 20333); + $this->assertEquals([], $result); } + public function testFindAllNewItemWrongType() + { + $this->expectException(ServiceValidationException::class); + $this->expectExceptionMessage('Trying to find in unknown type'); + + $this->mapper->expects($this->never()) + ->method('findAllAfter'); + + $result = $this->class->findAllAfter($this->user, 3, 20333); + $this->assertEquals([], $result); + } public function testFindAllFeed() { - $type = FeedType::FEED; - $this->oldItemMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('findAllFeed') - ->with( - $this->equalTo(3), - $this->equalTo(20), - $this->equalTo(5), - $this->equalTo(true), - $this->equalTo(false), - $this->equalTo('jack'), - $this->equalTo([]) - ) + ->with('jack', 3, 20, 5, true, false, []) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAllItems( - 3, $type, 20, 5, - true, false, 'jack' + $result = $this->class->findAllInFeedWithFilters( + 'jack', + 3, + 20, + 5, + true, + false ); $this->assertEquals(['val'], $result); } - public function testFindAllFolder() { - $type = FeedType::FOLDER; - $this->oldItemMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('findAllFolder') - ->with( - $this->equalTo(3), - $this->equalTo(20), - $this->equalTo(5), - $this->equalTo(true), - $this->equalTo(true), - $this->equalTo('jack'), - $this->equalTo([]) - ) + ->with('jack', 3, 20, 5, true, true, []) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAllItems( - 3, $type, 20, 5, - true, true, 'jack' + $result = $this->class->findAllInFolderWithFilters( + 'jack', + 3, + 20, + 5, + true, + true, + [] ); $this->assertEquals(['val'], $result); } - - public function testFindAll() + public function testFindAllItems() { $type = FeedType::STARRED; - $this->oldItemMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('findAllItems') - ->with( - $this->equalTo(20), - $this->equalTo(5), - $this->equalTo($type), - $this->equalTo(true), - $this->equalTo(true), - $this->equalTo('jack'), - $this->equalTo([]) - ) + ->with('jack', $type, 20, 5, true, []) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAllItems( - 3, $type, 20, 5, - true, true, 'jack' - ); + $result = $this->class->findAllWithFilters('jack', $type, 20, 5, true); $this->assertEquals(['val'], $result); } - public function testFindAllSearch() { $type = FeedType::STARRED; $search = ['test']; - $this->oldItemMapper->expects($this->once()) + + $this->mapper->expects($this->once()) ->method('findAllItems') - ->with( - $this->equalTo(20), - $this->equalTo(5), - $this->equalTo($type), - $this->equalTo(true), - $this->equalTo(true), - $this->equalTo('jack'), - $this->equalTo($search) - ) + ->with('jack', $type, 20, 5, true, $search) ->will($this->returnValue(['val'])); - $result = $this->itemService->findAllItems( - 3, $type, 20, 5, - true, true, 'jack', $search - ); + $result = $this->class->findAllWithFilters('jack', $type, 20, 5, true, $search); $this->assertEquals(['val'], $result); } + public function testFindAll() + { + $this->mapper->expects($this->once()) + ->method('findAll') + ->will($this->returnValue(['val'])); + $result = $this->class->findAll(); + $this->assertEquals(['val'], $result); + } - public function testStar() + public function testStarByGuid() { $itemId = 3; $feedId = 5; @@ -287,20 +226,19 @@ class ItemServiceTest extends TestCase $expectedItem->setId($itemId); $this->mapper->expects($this->once()) - ->method('findByGuidHash') - ->with($feedId, $guidHash) + ->method('findForUserByGuidHash') + ->with('jack', $feedId, $guidHash) ->will($this->returnValue($item)); $this->mapper->expects($this->once()) ->method('update') ->with($this->equalTo($expectedItem)); - $this->itemService->star($feedId, $guidHash, true, 'jack'); + $this->class->starByGuid('jack', $feedId, $guidHash, true); $this->assertTrue($item->isStarred()); } - public function testUnstar() { $itemId = 3; @@ -317,201 +255,379 @@ class ItemServiceTest extends TestCase $expectedItem->setId($itemId); $this->mapper->expects($this->once()) - ->method('findByGuidHash') - ->with($feedId, $guidHash) + ->method('findForUserByGuidHash') + ->with('jack', $feedId, $guidHash) ->will($this->returnValue($item)); $this->mapper->expects($this->once()) ->method('update') ->with($this->equalTo($expectedItem)); - $this->itemService->star($feedId, $guidHash, false, 'jack'); + $this->class->starByGuid('jack', $feedId, $guidHash, false); $this->assertFalse($item->isStarred()); } public function testRead() { - $itemId = 3; - $item = new Item(); - $item->setId($itemId); - $item->setUnread(true); + $item = $this->getMockBuilder(Item::class) + ->getMock(); - $expectedItem = new Item(); - $expectedItem->setUnread(false); - $expectedItem->setId($itemId); - $expectedItem->setLastModified($this->time); - - $this->oldItemMapper->expects($this->once()) - ->method('readItem') - ->with( - $this->equalTo($itemId), - $this->equalTo(true), - $this->equalTo($this->time), - $this->equalTo('jack') - ) + $item->expects($this->once()) + ->method('setUnread') + ->with(false); + + $this->mapper->expects($this->once()) + ->method('findFromUser') + ->with('jack', 3) ->will($this->returnValue($item)); - $this->itemService->read($itemId, true, 'jack'); - } + $this->mapper->expects($this->once()) + ->method('update') + ->with($item) + ->will($this->returnValue($item)); + $this->class->read('jack', 3, true); + } - public function testReadDoesNotExist() + public function testStar() { + $item = $this->getMockBuilder(Item::class) + ->getMock(); - $this->expectException(ServiceNotFoundException::class); - $this->oldItemMapper->expects($this->once()) - ->method('readItem') - ->will($this->throwException(new DoesNotExistException(''))); + $item->expects($this->once()) + ->method('setStarred') + ->with(true); + + $this->mapper->expects($this->once()) + ->method('findFromUser') + ->with('jack', 3) + ->will($this->returnValue($item)); + + $this->mapper->expects($this->once()) + ->method('update') + ->with($item) + ->will($this->returnValue($item)); - $this->itemService->read(1, true, 'jack'); + $this->class->star('jack', 3, true); } - public function testStarDoesNotExist() + public function testStarByGuidDoesNotExist() { $this->expectException(ServiceNotFoundException::class); $this->mapper->expects($this->once()) - ->method('findByGuidHash') + ->method('findForUserByGuidHash') ->will($this->throwException(new DoesNotExistException(''))); - $this->itemService->star(1, 'hash', true, 'jack'); + $this->class->starByGuid('jack', 1, 'hash', true); } + public function testStarByGuidDuplicate() + { + + $this->expectException(ServiceConflictException::class); + $this->mapper->expects($this->once()) + ->method('findForUserByGuidHash') + ->will($this->throwException(new MultipleObjectsReturnedException(''))); + + $this->class->starByGuid('jack', 1, 'hash', true); + } public function testReadAll() { $highestItemId = 6; - $this->oldItemMapper->expects($this->once()) + $this->mapper->expects($this->once()) ->method('readAll') - ->with( - $this->equalTo($highestItemId), - $this->equalTo($this->time), - $this->equalTo('jack') - ); + ->with('jack', $highestItemId); - $this->itemService->readAll($highestItemId, 'jack'); + $this->class->readAll('jack', $highestItemId); } - - public function testReadFolder() + public function testGetNewestItemId() { - $folderId = 3; - $highestItemId = 6; + $this->mapper->expects($this->once()) + ->method('newest') + ->with($this->equalTo('jack')) + ->will($this->returnValue(Item::fromParams(['id' => 12]))); + + $result = $this->class->newest('jack'); + $this->assertEquals(12, $result->getId()); + } - $this->oldItemMapper->expects($this->once()) - ->method('readFolder') - ->with( - $this->equalTo($folderId), - $this->equalTo($highestItemId), - $this->equalTo($this->time), - $this->equalTo('jack') + public function testGetNewestItemIdDoesNotExist() + { + $this->mapper->expects($this->once()) + ->method('newest') + ->with($this->equalTo('jack')) + ->will( + $this->throwException( + new DoesNotExistException('There are no items') + ) ); - $this->itemService->readFolder($folderId, $highestItemId, 'jack'); + $this->expectException(ServiceNotFoundException::class); + $this->class->newest('jack'); } - - public function testReadFeed() + public function testGetNewestItemDuplicate() { - $feedId = 3; - $highestItemId = 6; - - $this->oldItemMapper->expects($this->once()) - ->method('readFeed') - ->with( - $this->equalTo($feedId), - $this->equalTo($highestItemId), - $this->equalTo($this->time), - $this->equalTo('jack') + $this->mapper->expects($this->once()) + ->method('newest') + ->with($this->equalTo('jack')) + ->will( + $this->throwException( + new MultipleObjectsReturnedException('There are no items') + ) ); - $this->itemService->readFeed($feedId, $highestItemId, 'jack'); + $this->expectException(ServiceConflictException::class); + $this->class->newest('jack'); } - - public function testAutoPurgeOldWillPurgeOld() + public function testStarredCount() { - $this->config->expects($this->once()) - ->method('getAppValue') - ->with('news', 'autoPurgeCount') - ->will($this->returnValue(2)); - $this->oldItemMapper->expects($this->once()) - ->method('deleteReadOlderThanThreshold') - ->with($this->equalTo(2)); + $this->mapper->expects($this->once()) + ->method('findAllFromUser') + ->with('jack', ['starred' => 1]) + ->will($this->returnValue([new Item(), new Item()])); + + $result = $this->class->starred('jack'); - $this->itemService->autoPurgeOld(); + $this->assertEquals(2, count($result)); } - public function testAutoPurgeOldWontPurgeOld() + public function testInsertOrUpdateInserts() { - $this->config->expects($this->once()) - ->method('getAppValue') - ->with('news', 'autoPurgeCount') - ->will($this->returnValue(-1)); - $this->oldItemMapper->expects($this->never()) - ->method('deleteReadOlderThanThreshold'); + $item = $this->getMockBuilder(Item::class) + ->getMock(); - $this->itemService->autoPurgeOld(); - } + $item->expects($this->once()) + ->method('getFeedId') + ->will($this->returnValue(1)); + $item->expects($this->once()) + ->method('getGuidHash') + ->will($this->returnValue('hash')); - public function testGetNewestItemId() - { - $this->oldItemMapper->expects($this->once()) - ->method('getNewestItemId') - ->with($this->equalTo('jack')) - ->will($this->returnValue(12)); + $this->mapper->expects($this->once()) + ->method('findByGuidHash') + ->with(1, 'hash') + ->will($this->throwException(new DoesNotExistException('exception'))); + + $this->mapper->expects($this->once()) + ->method('insert') + ->with($item) + ->will($this->returnValue($item)); + + $result = $this->class->insertOrUpdate($item); - $result = $this->itemService->getNewestItemId('jack'); - $this->assertEquals(12, $result); + $this->assertEquals($item, $result); } + public function testInsertOrUpdateUpdates() + { + $item = $this->getMockBuilder(Item::class) + ->getMock(); + $db_item = $this->getMockBuilder(Item::class) + ->getMock(); + + $item->expects($this->once()) + ->method('getFeedId') + ->will($this->returnValue(1)); - public function testGetNewestItemIdDoesNotExist() + $item->expects($this->once()) + ->method('getGuidHash') + ->will($this->returnValue('hash')); + + $item->expects($this->once()) + ->method('setUnread') + ->with(true) + ->will($this->returnSelf()); + + $db_item->expects($this->once()) + ->method('isUnread') + ->will($this->returnValue(true)); + + $item->expects($this->once()) + ->method('setStarred') + ->with(true) + ->will($this->returnSelf()); + + $db_item->expects($this->once()) + ->method('isStarred') + ->will($this->returnValue(true)); + + $item->expects($this->once()) + ->method('generateSearchIndex') + ->will($this->returnSelf()); + + $item->expects($this->once()) + ->method('getFingerprint') + ->will($this->returnValue('fingerA')); + + $db_item->expects($this->once()) + ->method('getFingerprint') + ->will($this->returnValue('fingerB')); + + $item->expects($this->never()) + ->method('resetUpdatedFields'); + + $this->mapper->expects($this->once()) + ->method('findByGuidHash') + ->with(1, 'hash') + ->will($this->returnValue($db_item)); + + $this->mapper->expects($this->once()) + ->method('update') + ->with($item) + ->will($this->returnValue($item)); + + $result = $this->class->insertOrUpdate($item); + + $this->assertEquals($item, $result); + } + + public function testInsertOrUpdateSkipsSame() { - $this->oldItemMapper->expects($this->once()) - ->method('getNewestItemId') - ->with($this->equalTo('jack')) - ->will( - $this->throwException( - new DoesNotExistException('There are no items') - ) - ); + $item = $this->getMockBuilder(Item::class) + ->getMock(); + $db_item = $this->getMockBuilder(Item::class) + ->getMock(); - $this->expectException(ServiceNotFoundException::class); - $this->itemService->getNewestItemId('jack'); + $item->expects($this->once()) + ->method('getFeedId') + ->will($this->returnValue(1)); + + $item->expects($this->once()) + ->method('getGuidHash') + ->will($this->returnValue('hash')); + + $item->expects($this->once()) + ->method('setUnread') + ->with(true) + ->will($this->returnSelf()); + + $db_item->expects($this->once()) + ->method('isUnread') + ->will($this->returnValue(true)); + + $item->expects($this->once()) + ->method('setStarred') + ->with(true) + ->will($this->returnSelf()); + + $db_item->expects($this->once()) + ->method('isStarred') + ->will($this->returnValue(true)); + + $item->expects($this->once()) + ->method('generateSearchIndex') + ->will($this->returnSelf()); + + $item->expects($this->once()) + ->method('getFingerprint') + ->will($this->returnValue('fingerA')); + + $db_item->expects($this->once()) + ->method('getFingerprint') + ->will($this->returnValue('fingerA')); + + $item->expects($this->once()) + ->method('resetUpdatedFields'); + + $this->mapper->expects($this->once()) + ->method('findByGuidHash') + ->with(1, 'hash') + ->will($this->returnValue($db_item)); + + $this->mapper->expects($this->once()) + ->method('update') + ->with($item) + ->will($this->returnValue($item)); + + $result = $this->class->insertOrUpdate($item); + + $this->assertEquals($item, $result); } + public function testFindByGuidHash() + { + $item = $this->getMockBuilder(Item::class) + ->getMock(); - public function testStarredCount() + $this->mapper->expects($this->once()) + ->method('findByGuidHash') + ->with(1, 'a') + ->will($this->returnValue($item)); + + $result = $this->class->findByGuidHash(1, 'a'); + + $this->assertEquals($item, $result); + } + + public function testFindAllInFeed() { - $star = 18; + $items = [new Item(), new Item()]; - $this->oldItemMapper->expects($this->once()) - ->method('starredCount') - ->with($this->equalTo('jack')) - ->will($this->returnValue($star)); + $this->mapper->expects($this->once()) + ->method('findAllInFeedAfter') + ->with('jack', 1, PHP_INT_MIN, false) + ->will($this->returnValue($items)); - $result = $this->itemService->starredCount('jack'); + $result = $this->class->findAllInFeed('jack', 1); - $this->assertEquals($star, $result); + $this->assertEquals($items, $result); } + public function testPurgeOverThreshold() + { + $this->mapper->expects($this->once()) + ->method('deleteOverThreshold') + ->with(1, true) + ->will($this->returnValue(1)); - public function testGetUnreadOrStarred() + $result = $this->class->purgeOverThreshold(1, true); + + $this->assertEquals(1, $result); + } + + public function testPurgeOverThresholdWithNegative() { - $this->oldItemMapper->expects($this->once()) - ->method('findAllUnreadOrStarred') - ->with($this->equalTo('jack')) - ->will($this->returnValue([])); + $this->mapper->expects($this->never()) + ->method('deleteOverThreshold'); - $result = $this->itemService->getUnreadOrStarred('jack'); + $result = $this->class->purgeOverThreshold(-1, true); - $this->assertEquals([], $result); + $this->assertEquals(null, $result); } + public function testPurgeOverThresholdNull() + { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('news', 'autoPurgeCount', 200) + ->will($this->returnValue(200)); + + $this->mapper->expects($this->once()) + ->method('deleteOverThreshold') + ->with(200); + + $this->class->purgeOverThreshold(); + } + public function testPurgeOverThresholdSet() + { + $this->config->expects($this->never()) + ->method('getAppValue') + ->with('news', 'autoPurgeCount', 200); + + $this->mapper->expects($this->once()) + ->method('deleteOverThreshold') + ->with(5); + + $this->class->purgeOverThreshold(5); + } } diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index cfaf82c95..cc4e2604b 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.php @@ -14,8 +14,8 @@ namespace OCA\News\Tests\Unit\Service; use OCA\News\Db\Feed; -use OCA\News\Db\ItemMapper; use OCA\News\Db\ItemMapperV2; +use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\Service; use \OCP\AppFramework\Db\DoesNotExistException; @@ -112,7 +112,7 @@ class ServiceTest extends TestCase ->method('findFromUser') ->will($this->throwException($ex)); - $this->expectException(ServiceNotFoundException::class); + $this->expectException(ServiceConflictException::class); $this->class->find('', 1); } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 91e13a1db..b22549184 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,11 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <files psalm-version="4.4.1@9fd7a7d885b3a216cff8dec9d8c21a132f275224"> <file src="lib/AppInfo/Application.php"> - <MissingDependency occurrences="5"> + <MissingDependency occurrences="4"> <code>$fs</code> <code>$fs</code> <code>$fs</code> - <code>BeforeUserDeletedEvent</code> <code>IRootFolder</code> </MissingDependency> </file> @@ -21,18 +20,30 @@ </InvalidReturnType> </file> <file src="lib/Hooks/UserDeleteHook.php"> - <MissingDependency occurrences="2"> - <code>BeforeUserDeletedEvent</code> - <code>UserDeleteHook</code> - </MissingDependency> <MoreSpecificImplementedParamType occurrences="1"> <code>$event</code> </MoreSpecificImplementedParamType> </file> + <file src="lib/Service/Exceptions/ServiceConflictException.php"> + <MoreSpecificImplementedParamType occurrences="1"> + <code>$exception</code> + </MoreSpecificImplementedParamType> + </file> + <file src="lib/Service/Exceptions/ServiceNotFoundException.php"> + <MoreSpecificImplementedParamType occurrences="1"> + <code>$exception</code> + </MoreSpecificImplementedParamType> + </file> + <file src="lib/Service/Exceptions/ServiceValidationException.php"> + <MoreSpecificImplementedParamType occurrences="1"> + <code>$exception</code> + </MoreSpecificImplementedParamType> + </file> <file src="lib/Service/FeedServiceV2.php"> - <UndefinedMethod occurrences="2"> + <UndefinedMethod occurrences="3"> <code>findAllFromFolder</code> <code>findByURL</code> + <code>read</code> </UndefinedMethod> </file> <file src="lib/Service/FolderServiceV2.php"> @@ -43,18 +54,23 @@ <code>$this->timeFactory</code> <code>TimeFactory</code> </UndefinedDocblockClass> - </file> - <file src="lib/Service/ItemService.php"> <UndefinedMethod occurrences="1"> - <code>findByGuidHash</code> + <code>read</code> </UndefinedMethod> </file> <file src="lib/Service/ItemServiceV2.php"> - <UndefinedMethod occurrences="4"> + <UndefinedMethod occurrences="11"> <code>deleteOverThreshold</code> - <code>findAllForFeed</code> - <code>findByGuidHash</code> + <code>findAllAfter</code> + <code>findAllFeed</code> + <code>findAllFolder</code> + <code>findAllInFeedAfter</code> + <code>findAllInFolderAfter</code> + <code>findAllItems</code> <code>findByGuidHash</code> + <code>findForUserByGuidHash</code> + <code>newest</code> + <code>readAll</code> </UndefinedMethod> </file> </files> |