From 2ee5112760d721e441abee4ededfa5484269a3c9 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Wed, 3 Mar 2021 23:01:36 +0100 Subject: =?UTF-8?q?=F0=9F=94=A5=20Remove=20old=20share=20logic=20from=20te?= =?UTF-8?q?sts=20&=20old=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- tests/Unit/Controller/FeedControllerTest.php | 12 +- tests/Unit/Controller/ItemControllerTest.php | 145 +--------------- tests/Unit/Db/ItemMapperAfterTest.php | 139 +--------------- tests/Unit/Db/ItemMapperPaginatedTest.php | 238 ++------------------------- tests/Unit/Db/ItemMapperTest.php | 40 ++--- tests/Unit/Service/ItemServiceTest.php | 45 +---- 6 files changed, 51 insertions(+), 568 deletions(-) (limited to 'tests') diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 2ea13b1ec..fde821088 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -137,8 +137,7 @@ class FeedControllerTest extends TestCase 'feeds' => [ ['a feed'], ], - 'starred' => 4, - 'shared' => 3 + 'starred' => 4 ]; $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -152,10 +151,6 @@ class FeedControllerTest extends TestCase ->method('starred') ->with($this->uid) ->will($this->returnValue([1, 2, 3, 4])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with($this->equalTo($this->uid)) - ->will($this->returnValue([0, 1, 2])); $response = $this->class->index(); @@ -170,7 +165,6 @@ class FeedControllerTest extends TestCase ['a feed'], ], 'starred' => 2, - 'shared' => 3, 'newestItemId' => 5 ]; $this->feedService->expects($this->once()) @@ -185,10 +179,6 @@ class FeedControllerTest extends TestCase ->method('starred') ->with($this->uid) ->will($this->returnValue([1, 2])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with($this->equalTo($this->uid)) - ->will($this->returnValue([4, 5, 6])); $response = $this->class->index(); diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index 6836cd119..8c10dad4b 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -258,8 +258,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 2 + 'starred' => 3 ]; $this->itemsApiExpects(2, ListType::FEED, '0'); @@ -279,11 +278,6 @@ class ItemControllerTest extends TestCase ->with('user') ->will($this->returnValue([1, 2, 3])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([4, 5])); - $this->itemService->expects($this->once()) ->method('findAllInFeedWithFilters') ->with('user', 2, 3, 0, false, false, []) @@ -301,8 +295,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 2 + 'starred' => 3 ]; $this->itemsApiExpects(2, ListType::FOLDER, '0'); @@ -322,11 +315,6 @@ class ItemControllerTest extends TestCase ->with('user') ->will($this->returnValue([1, 2, 3])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([0, 1])); - $this->itemService->expects($this->once()) ->method('findAllInFolderWithFilters') ->with('user', 2, 3, 0, false, false, []) @@ -337,49 +325,6 @@ class ItemControllerTest extends TestCase } - public function testIndexForShared() - { - $feeds = [new Feed()]; - $result = [ - 'items' => [new Item()], - 'feeds' => $feeds, - 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 4 - ]; - - $this->itemsApiExpects(2, ListType::SHARED, '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('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2, 3, 4])); - - $this->itemService->expects($this->once()) - ->method('findAllSharedWithUserWithFilters') - ->with('user', 3, 0, false, false, []) - ->will($this->returnValue($result['items'])); - - $response = $this->controller->index(ListType::SHARED, 2, 3); - $this->assertEquals($result, $response); - } - - public function testIndexForOther() { $feeds = [new Feed()]; @@ -387,8 +332,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 4 + 'starred' => 3 ]; $this->itemsApiExpects(2, ListType::STARRED, '0'); @@ -413,11 +357,6 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, []) ->will($this->returnValue($result['items'])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2, 3, 4])); - $response = $this->controller->index(ListType::STARRED, 2, 3); $this->assertEquals($result, $response); } @@ -430,8 +369,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 2 + 'starred' => 3 ]; $this->itemsApiExpects(2, ListType::FEED, '0'); @@ -456,11 +394,6 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, 0, false, false, ['test', 'search']) ->will($this->returnValue($result['items'])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2])); - $response = $this->controller->index(ListType::FEED, 2, 3, 0, null, null, 'test%20%20search%20'); $this->assertEquals($result, $response); } @@ -506,8 +439,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 3 + 'starred' => 3 ]; $this->settings->expects($this->once()) @@ -530,11 +462,6 @@ class ItemControllerTest extends TestCase ->with('user') ->will($this->returnValue([1, 2, 3])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2, 3])); - $this->itemService->expects($this->once()) ->method('findAllInFeedAfter') ->with('user', 2, 3, false) @@ -552,8 +479,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 2 + 'starred' => 3 ]; $this->settings->expects($this->once()) @@ -581,62 +507,11 @@ class ItemControllerTest extends TestCase ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2])); - $response = $this->controller->newItems(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } - public function testNewItemsShared() - { - $feeds = [new Feed()]; - $result = [ - 'items' => [new Item()], - 'feeds' => $feeds, - 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 5 - ]; - - $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('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2, 3, 4, 5])); - - $this->itemService->expects($this->once()) - ->method('findAllSharedAfter') - ->with('user', 3, false) - ->will($this->returnValue($result['items'])); - - $response = $this->controller->newItems(ListType::SHARED, 2, 3); - $this->assertEquals($result, $response); - } - - public function testNewItemsOther() { $feeds = [new Feed()]; @@ -644,8 +519,7 @@ class ItemControllerTest extends TestCase 'items' => [new Item()], 'feeds' => $feeds, 'newestItemId' => $this->newestItemId, - 'starred' => 3, - 'shared' => 2 + 'starred' => 3 ]; $this->settings->expects($this->once()) @@ -673,11 +547,6 @@ class ItemControllerTest extends TestCase ->with('user', 6, 3) ->will($this->returnValue($result['items'])); - $this->itemService->expects($this->once()) - ->method('sharedWithUser') - ->with('user') - ->will($this->returnValue([1, 2])); - $response = $this->controller->newItems(ListType::UNREAD, 2, 3); $this->assertEquals($result, $response); } diff --git a/tests/Unit/Db/ItemMapperAfterTest.php b/tests/Unit/Db/ItemMapperAfterTest.php index 5c91fa00d..eccebbcf5 100644 --- a/tests/Unit/Db/ItemMapperAfterTest.php +++ b/tests/Unit/Db/ItemMapperAfterTest.php @@ -62,11 +62,10 @@ class ItemMapperAfterTest extends MapperTestUtility ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') ->will($this->returnSelf()); - $this->builder->expects($this->exactly(4)) + $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], ['feeds.user_id = :userId'], ['feeds.id = :feedId'], ['feeds.deleted_at = 0'] @@ -128,11 +127,10 @@ class ItemMapperAfterTest extends MapperTestUtility ->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id') ->will($this->returnSelf()); - $this->builder->expects($this->exactly(5)) + $this->builder->expects($this->exactly(4)) ->method('andWhere') ->withConsecutive( ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], ['feeds.user_id = :userId'], ['feeds.id = :feedId'], ['feeds.deleted_at = 0'], @@ -203,11 +201,10 @@ class ItemMapperAfterTest extends MapperTestUtility ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(4)) + $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], ['folders.id = :folderId'] @@ -272,11 +269,10 @@ class ItemMapperAfterTest extends MapperTestUtility ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(5)) + $this->builder->expects($this->exactly(4)) ->method('andWhere') ->withConsecutive( ['items.last_modified >= :updatedSince'], - ['items.shared_by = \'\''], ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], ['folders.id = :folderId'], @@ -323,121 +319,6 @@ 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()) @@ -464,7 +345,7 @@ class ItemMapperAfterTest extends MapperTestUtility ->withConsecutive( ['items.last_modified >= :updatedSince'], ['feeds.deleted_at = 0'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['items.unread = :unread'] ) ->will($this->returnSelf()); @@ -474,7 +355,6 @@ class ItemMapperAfterTest extends MapperTestUtility ->with([ 'updatedSince' => 1610903351, 'userId' => 'jack', - 'sharedWith' => 'jack' ]) ->will($this->returnSelf()); @@ -534,7 +414,7 @@ class ItemMapperAfterTest extends MapperTestUtility ->withConsecutive( ['items.last_modified >= :updatedSince'], ['feeds.deleted_at = 0'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['items.starred = :starred'] ) ->will($this->returnSelf()); @@ -544,7 +424,6 @@ class ItemMapperAfterTest extends MapperTestUtility ->with([ 'updatedSince' => 1610903351, 'userId' => 'jack', - 'sharedWith' => 'jack' ]) ->will($this->returnSelf()); @@ -604,7 +483,7 @@ class ItemMapperAfterTest extends MapperTestUtility ->withConsecutive( ['items.last_modified >= :updatedSince'], ['feeds.deleted_at = 0'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'] + ['feeds.user_id = :userId'] ) ->will($this->returnSelf()); @@ -613,7 +492,6 @@ class ItemMapperAfterTest extends MapperTestUtility ->with([ 'updatedSince' => 1610903351, 'userId' => 'jack', - 'sharedWith' => 'jack' ]) ->will($this->returnSelf()); @@ -671,7 +549,7 @@ class ItemMapperAfterTest extends MapperTestUtility ->withConsecutive( ['items.last_modified >= :updatedSince'], ['feeds.deleted_at = 0'], - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'] + ['feeds.user_id = :userId'] ) ->will($this->returnSelf()); @@ -680,7 +558,6 @@ class ItemMapperAfterTest extends MapperTestUtility ->with([ 'updatedSince' => 1610903351, 'userId' => 'jack', - 'sharedWith' => 'jack' ]) ->will($this->returnSelf()); diff --git a/tests/Unit/Db/ItemMapperPaginatedTest.php b/tests/Unit/Db/ItemMapperPaginatedTest.php index f9ed9b6e5..e0625aa0c 100644 --- a/tests/Unit/Db/ItemMapperPaginatedTest.php +++ b/tests/Unit/Db/ItemMapperPaginatedTest.php @@ -70,14 +70,14 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'] ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(3)) + $this->builder->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', 'jack'], ['offset', 10]) + ->withConsecutive(['userId', 'jack'], ['offset', 10]) ->will($this->returnSelf()); @@ -140,15 +140,15 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], ['items.id > :offset'] ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(3)) + $this->builder->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', 'jack'], ['offset', 10]) + ->withConsecutive(['userId', 'jack'], ['offset', 10]) ->will($this->returnSelf()); @@ -212,16 +212,16 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->builder->expects($this->exactly(4)) ->method('andWhere') ->withConsecutive( - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], ['items.id < :offset'], ['items.unread = :unread'] ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(3)) + $this->builder->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', 'jack'], ['offset', 10], ['unread', true]) + ->withConsecutive(['userId', 'jack'], ['offset', 10], ['unread', true]) ->will($this->returnSelf()); $this->builder->expects($this->exactly(1)) @@ -352,16 +352,16 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->builder->expects($this->exactly(4)) ->method('andWhere') ->withConsecutive( - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], ['items.id < :offset'], ['items.starred = :starred'] ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(3)) + $this->builder->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive(['userId', 'jack'], ['sharedWith', 'jack'], ['offset', 10], ['starred', true]) + ->withConsecutive(['userId', 'jack'], ['offset', 10], ['starred', true]) ->will($this->returnSelf()); @@ -427,7 +427,7 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->builder->expects($this->exactly(6)) ->method('andWhere') ->withConsecutive( - ['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith'], + ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], ['items.search_index LIKE :term0'], ['items.search_index LIKE :term1'], @@ -436,11 +436,10 @@ class ItemMapperPaginatedTest extends MapperTestUtility ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(5)) + $this->builder->expects($this->exactly(4)) ->method('setParameter') ->withConsecutive( ['userId', 'jack'], - ['sharedWith', 'jack'], ['term0', '%key%'], ['term1', '%word%'], ['offset', 10], @@ -506,13 +505,12 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(4)) + $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( ['feeds.deleted_at = 0'], ['feeds.user_id = :userId'], ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], ['items.id < :offset'] ) ->will($this->returnSelf()); @@ -651,13 +649,12 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(4)) + $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( ['feeds.deleted_at = 0'], ['feeds.user_id = :userId'], ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], ['items.id > :offset'] ) ->will($this->returnSelf()); @@ -723,13 +720,12 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(5)) + $this->builder->expects($this->exactly(4)) ->method('andWhere') ->withConsecutive( ['feeds.deleted_at = 0'], ['feeds.user_id = :userId'], ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], ['items.id < :offset'], ['items.unread = :unread'] ) @@ -801,13 +797,12 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(6)) + $this->builder->expects($this->exactly(5)) ->method('andWhere') ->withConsecutive( ['feeds.deleted_at = 0'], ['feeds.user_id = :userId'], ['items.feed_id = :feedId'], - ['items.shared_by = \'\''], ['items.search_index LIKE :term0'], ['items.search_index LIKE :term1'], ['items.id < :offset'] @@ -900,7 +895,6 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive( ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], - ['items.shared_by = \'\''], ['x IS NULL'], ['items.id < :offset'] ) @@ -1069,7 +1063,6 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive( ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], - ['items.shared_by = \'\''], ['x IS NULL'], ['items.id < :offset'], ['items.unread = :unread'] @@ -1156,7 +1149,6 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive( ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], - ['items.shared_by = \'\''], ['x IS NULL'], ['items.id > :offset'], ['items.unread = :unread'] @@ -1246,7 +1238,6 @@ class ItemMapperPaginatedTest extends MapperTestUtility ->withConsecutive( ['feeds.user_id = :userId'], ['feeds.deleted_at = 0'], - ['items.shared_by = \'\''], ['x = y'], ['items.search_index LIKE :term0'], ['items.search_index LIKE :term1'], @@ -1295,197 +1286,4 @@ class ItemMapperPaginatedTest extends MapperTestUtility $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(2)) - ->method('andWhere') - ->withConsecutive( - ['items.shared_with = :sharedWith'], - ['items.id < :offset'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(2)) - ->method('setParameter') - ->withConsecutive( - ['sharedWith', 'jack'], - ['offset', 10] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setMaxResults') - ->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(3)) - ->method('andWhere') - ->withConsecutive( - ['items.shared_with = :sharedWith'], - ['items.id < :offset'], - ['items.unread = 1'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(2)) - ->method('setParameter') - ->withConsecutive(['sharedWith', 'jack'], ['offset', 10]) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setMaxResults') - ->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(4)) - ->method('andWhere') - ->withConsecutive( - ['items.shared_with = :sharedWith'], - ['items.search_index LIKE :term0'], - ['items.search_index LIKE :term1'], - ['items.id < :offset'] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(4)) - ->method('setParameter') - ->withConsecutive( - ['sharedWith', 'jack'], - ['term0', '%key%'], - ['term1', '%word%'], - ['offset', 10] - ) - ->will($this->returnSelf()); - - $this->builder->expects($this->exactly(1)) - ->method('setMaxResults') - ->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); - } - } diff --git a/tests/Unit/Db/ItemMapperTest.php b/tests/Unit/Db/ItemMapperTest.php index 0900c6b4e..ba73d93b8 100644 --- a/tests/Unit/Db/ItemMapperTest.php +++ b/tests/Unit/Db/ItemMapperTest.php @@ -93,7 +93,7 @@ class ItemMapperTest extends MapperTestUtility $this->builder->expects($this->once()) ->method('where') - ->with('(feeds.user_id = :user_id AND items.shared_by = \'\') OR items.shared_with = :shared_with') + ->with('feeds.user_id = :user_id') ->will($this->returnSelf()); $this->builder->expects($this->once()) @@ -101,9 +101,9 @@ class ItemMapperTest extends MapperTestUtility ->with('feeds.deleted_at = 0') ->will($this->returnSelf()); - $this->builder->expects($this->exactly(2)) + $this->builder->expects($this->exactly(1)) ->method('setParameter') - ->withConsecutive(['user_id', 'jack'], ['shared_with', 'jack']) + ->withConsecutive(['user_id', 'jack']) ->will($this->returnSelf()); $this->builder->expects($this->once()) @@ -154,7 +154,7 @@ class ItemMapperTest extends MapperTestUtility $this->builder->expects($this->once()) ->method('where') - ->with('(feeds.user_id = :user_id AND items.shared_by = \'\') OR items.shared_with = :shared_with') + ->with('feeds.user_id = :user_id') ->will($this->returnSelf()); $this->builder->expects($this->exactly(2)) @@ -162,9 +162,9 @@ class ItemMapperTest extends MapperTestUtility ->withConsecutive(['feeds.deleted_at = 0'], ['key = :val']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(2)) + $this->builder->expects($this->exactly(1)) ->method('setParameter') - ->withConsecutive(['user_id', 'jack'], ['shared_with', 'jack']) + ->withConsecutive(['user_id', 'jack']) ->will($this->returnSelf()); $this->builder->expects($this->once()) @@ -296,7 +296,7 @@ class ItemMapperTest extends MapperTestUtility $this->builder->expects($this->once()) ->method('where') - ->with('(feeds.user_id = :user_id AND items.shared_by = \'\') OR items.shared_with = :shared_with') + ->with('feeds.user_id = :user_id') ->will($this->returnSelf()); $this->builder->expects($this->exactly(2)) @@ -304,9 +304,9 @@ class ItemMapperTest extends MapperTestUtility ->withConsecutive(['items.id = :item_id'], ['feeds.deleted_at = 0']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(3)) + $this->builder->expects($this->exactly(2)) ->method('setParameter') - ->withConsecutive(['user_id', 'jack'], ['shared_with', 'jack'], ['item_id', 4]) + ->withConsecutive(['user_id', 'jack'], ['item_id', 4]) ->will($this->returnSelf()); $this->builder->expects($this->once()) @@ -389,20 +389,15 @@ class ItemMapperTest extends MapperTestUtility $this->builder->expects($this->exactly(3)) ->method('andWhere') ->withConsecutive( - ['(feeds.user_id = :user_id AND items.shared_by = \'\') OR items.shared_with = :shared_with'], + ['feeds.user_id = :user_id'], ['feeds.id = :feed_id'], ['items.guid_hash = :guid_hash'] ) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(4)) + $this->builder->expects($this->exactly(3)) ->method('setParameter') - ->withConsecutive( - ['user_id', 'jack'], - ['shared_with', 'jack'], - ['feed_id', 4], - ['guid_hash', 'hash'] - ) + ->withConsecutive(['user_id', 'jack'], ['feed_id', 4], ['guid_hash', 'hash']) ->will($this->returnSelf()); $this->builder->expects($this->once()) @@ -453,15 +448,12 @@ class ItemMapperTest extends MapperTestUtility $this->builder->expects($this->exactly(1)) ->method('where') - ->withConsecutive(['(feeds.user_id = :userId AND items.shared_by = \'\') OR items.shared_with = :sharedWith']) + ->withConsecutive(['feeds.user_id = :userId']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(2)) + $this->builder->expects($this->exactly(1)) ->method('setParameter') - ->withConsecutive( - ['userId', 'jack'], - ['sharedWith', 'jack'] - ) + ->withConsecutive(['userId', 'jack']) ->will($this->returnSelf()); $this->builder->expects($this->exactly(1)) @@ -559,7 +551,7 @@ class ItemMapperTest extends MapperTestUtility ->withConsecutive(['id IN (:idList)'], ['unread != :unread']) ->will($this->returnSelf()); - $this->builder->expects($this->exactly(3)) + $this->builder->expects($this->exactly(2)) ->method('setParameter') ->withConsecutive(['unread', false], ['idList', [1, 2]]) ->will($this->returnSelf()); diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 6c4658d5e..1985bdc18 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -114,17 +114,6 @@ class ItemServiceTest extends TestCase $this->assertEquals([], $result); } - public function testFindAllNewShared() - { - $this->mapper->expects($this->once()) - ->method('findAllSharedAfter') - ->with('jack', 20333, true) - ->will($this->returnValue([])); - - $result = $this->class->findAllSharedAfter($this->user, 20333, true); - $this->assertEquals([], $result); - } - public function testFindAllNewItem() { $this->mapper->expects($this->once()) @@ -185,27 +174,7 @@ class ItemServiceTest extends TestCase $this->assertEquals(['val'], $result); } - public function testFindAllSharedWithUser() - { - $this->mapper->expects($this->once()) - ->method('findAllSharedWithUser') - ->with('user', 20, 5, true, true, []) - ->will($this->returnValue(['val'])); - - $result = $this->class->findAllSharedWithUserWithFilters( - 'user', - 20, - 5, - true, - true, - [] - ); - - $this->assertEquals(['val'], $result); - } - - - public function testFindAll() + public function testFindAllItems() { $type = ListType::STARRED; $this->mapper->expects($this->once()) @@ -716,16 +685,4 @@ class ItemServiceTest extends TestCase $this->class->share('sender', 1, 'recipient'); } - - public function testSharedCount() - { - $this->mapper->expects($this->once()) - ->method('findAllFromUser') - ->with('user', ['shared_with' => 'user', 'unread' => true]) - ->will($this->returnValue([new Item(), new Item()])); - - $result = $this->class->sharedWithUser('user'); - - $this->assertEquals(2, count($result)); - } } -- cgit v1.2.3