From 702d611f354af61095bdf33792b3404f6edaefd3 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Sun, 28 Feb 2021 22:46:56 +0100 Subject: =?UTF-8?q?=F0=9F=94=80=20Resolving=20merge:=20moving=20shared=20t?= =?UTF-8?q?ests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- tests/Unit/Db/ItemMapperAfterTest.php | 115 ++ tests/Unit/Db/ItemMapperPaginatedTest.php | 200 +++- tests/Unit/Db/ItemMapperTest.php | 1635 ----------------------------- 3 files changed, 314 insertions(+), 1636 deletions(-) diff --git a/tests/Unit/Db/ItemMapperAfterTest.php b/tests/Unit/Db/ItemMapperAfterTest.php index 68bad19dc..75804e629 100644 --- a/tests/Unit/Db/ItemMapperAfterTest.php +++ b/tests/Unit/Db/ItemMapperAfterTest.php @@ -319,6 +319,121 @@ class ItemMapperAfterTest extends MapperTestUtility $this->assertEquals([Item::fromRow(['id' => 4])], $result); } + public function testFindAllSharedAfter() + { + $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('andWhere') + ->withConsecutive( + ['items.last_modified >= :updatedSince'], + ['items.shared_with = :sharedWith'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'sharedWith' => 'jack', + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.last_modified', '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->findAllSharedAfter('jack', 1610903351, false); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllSharedAfterHideRead() + { + $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(3)) + ->method('andWhere') + ->withConsecutive( + ['items.last_modified >= :updatedSince'], + ['items.shared_with = :sharedWith'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameters') + ->with([ + 'updatedSince' => 1610903351, + 'sharedWith' => 'jack' + ]) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.last_modified', '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->findAllSharedAfter('jack', 1610903351, true); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + public function testFindAllAfterUnread() { $this->db->expects($this->once()) diff --git a/tests/Unit/Db/ItemMapperPaginatedTest.php b/tests/Unit/Db/ItemMapperPaginatedTest.php index 448622280..964f27029 100644 --- a/tests/Unit/Db/ItemMapperPaginatedTest.php +++ b/tests/Unit/Db/ItemMapperPaginatedTest.php @@ -1287,4 +1287,202 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->assertEquals([Item::fromRow(['id' => 4])], $result); } -} + public function testFindAllSharedWithUser() + { + $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('andWhere') + ->with('items.shared_with = :sharedWith') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->with('sharedWith', '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.last_modified', '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->findAllSharedWithUser('jack', 10, 10, false, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllSharedWithUserHideRead() + { + $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('andWhere') + ->withConsecutive( + ['items.shared_with = :sharedWith'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('setParameter') + ->with('sharedWith', '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.last_modified', '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->findAllSharedWithUser('jack', 10, 10, true, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + + public function testFindAllSharedWithUserSearch() + { + $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(3)) + ->method('andWhere') + ->withConsecutive( + ['items.shared_with = :sharedWith'], + ['items.search_index LIKE :term0'], + ['items.search_index LIKE :term1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive( + ['sharedWith', '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.last_modified', '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->findAllSharedWithUser('jack', 10, 10, false, false, ['key', 'word']); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + +} \ No newline at end of file diff --git a/tests/Unit/Db/ItemMapperTest.php b/tests/Unit/Db/ItemMapperTest.php index 0a7a852e1..0900c6b4e 100644 --- a/tests/Unit/Db/ItemMapperTest.php +++ b/tests/Unit/Db/ItemMapperTest.php @@ -484,1641 +484,6 @@ class ItemMapperTest extends MapperTestUtility $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(4)) - ->method('andWhere') - ->withConsecutive( - ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], - ['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.last_modified', '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(5)) - ->method('andWhere') - ->withConsecutive( - ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], - ['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.last_modified', '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(4)) - ->method('andWhere') - ->withConsecutive( - ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], - ['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.last_modified', '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(5)) - ->method('andWhere') - ->withConsecutive( - ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], - ['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.last_modified', '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 testFindAllSharedAfter() - { - $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('andWhere') - ->withConsecutive( - ['items.last_modified >= :updatedSince'], - ['items.shared_with = :sharedWith'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameters') - ->with([ - 'updatedSince' => 1610903351, - 'sharedWith' => 'jack', - ]) - ->will($this->returnSelf()); - - $this->builder->expects($this->once()) - ->method('orderBy') - ->with('items.last_modified', '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->findAllSharedAfter('jack', 1610903351, false); - $this->assertEquals([Item::fromRow(['id' => 4])], $result); - } - - public function testFindAllSharedAfterHideRead() - { - $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(3)) - ->method('andWhere') - ->withConsecutive( - ['items.last_modified >= :updatedSince'], - ['items.shared_with = :sharedWith'], - ['items.unread = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameters') - ->with([ - 'updatedSince' => 1610903351, - 'sharedWith' => 'jack' - ]) - ->will($this->returnSelf()); - - $this->builder->expects($this->once()) - ->method('orderBy') - ->with('items.last_modified', '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->findAllSharedAfter('jack', 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.last_modified >= :updatedSince'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ['items.unread = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameters') - ->with([ - 'updatedSince' => 1610903351, - 'userId' => 'jack', - 'sharedWith' => 'jack' - ]) - ->will($this->returnSelf()); - - $this->builder->expects($this->once()) - ->method('orderBy') - ->with('items.last_modified', '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.last_modified >= :updatedSince'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ['items.starred = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameters') - ->with([ - 'updatedSince' => 1610903351, - 'userId' => 'jack', - 'sharedWith' => 'jack' - ]) - ->will($this->returnSelf()); - - $this->builder->expects($this->once()) - ->method('orderBy') - ->with('items.last_modified', '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.last_modified >= :updatedSince'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameters') - ->with([ - 'updatedSince' => 1610903351, - 'userId' => 'jack', - 'sharedWith' => 'jack' - ]) - ->will($this->returnSelf()); - - $this->builder->expects($this->once()) - ->method('orderBy') - ->with('items.last_modified', '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 AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(2)) - ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', '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.last_modified', '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 AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ['items.unread = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(2)) - ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', '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.last_modified', '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 AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ['items.starred = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(2)) - ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', '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.last_modified', '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 AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], - ['items.search_index LIKE :term0'], - ['items.search_index LIKE :term1'], - ['items.starred = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(4)) - ->method('setParameter') - ->withConsecutive( - ['userId', 'jack'], - ['sharedWith', '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.last_modified', '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(3)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], - ) - ->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.last_modified', '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(4)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], - ['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.last_modified', '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(5)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], - ['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.last_modified', '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(3)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - ['items.shared_by = \'\''], - ['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.last_modified', '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(4)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - [('items.shared_by = \'\'')], - ['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.last_modified', '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(4)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - ['items.shared_by = \'\''], - ['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.last_modified', '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', new Literal(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(5)) - ->method('andWhere') - ->withConsecutive( - ['feeds.user_id = :userId'], - ['items.shared_by = \'\''], - ['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.last_modified', '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 testFindAllSharedWithUser() - { - $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('andWhere') - ->with('items.shared_with = :sharedWith') - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameter') - ->with('sharedWith', '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.last_modified', '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->findAllSharedWithUser('jack', 10, 10, false, false, []); - $this->assertEquals([Item::fromRow(['id' => 4])], $result); - } - - public function testFindAllSharedWithUserHideRead() - { - $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('andWhere') - ->withConsecutive( - ['items.shared_with = :sharedWith'], - ['items.unread = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setParameter') - ->with('sharedWith', '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.last_modified', '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->findAllSharedWithUser('