From 87848e70e4b104b85737b3b713563b7e3d90c529 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 16 Feb 2021 21:16:18 +0100 Subject: [PATCH 1/2] Command: Add debug item list commands Signed-off-by: Sean Molenaar --- .github/workflows/api-integration-tests.yml | 9 ++ CHANGELOG.md | 1 + appinfo/info.xml | 3 + lib/Command/Debug/FeedItemList.php | 99 +++++++++++++++++++ lib/Command/Debug/FolderItemList.php | 100 ++++++++++++++++++++ lib/Command/Debug/ItemList.php | 94 ++++++++++++++++++ lib/Db/{FeedType.php => ListType.php} | 0 7 files changed, 306 insertions(+) create mode 100644 lib/Command/Debug/FeedItemList.php create mode 100644 lib/Command/Debug/FolderItemList.php create mode 100644 lib/Command/Debug/ItemList.php rename lib/Db/{FeedType.php => ListType.php} (100%) diff --git a/.github/workflows/api-integration-tests.yml b/.github/workflows/api-integration-tests.yml index 3c0d057b36..809d63e4ca 100644 --- a/.github/workflows/api-integration-tests.yml +++ b/.github/workflows/api-integration-tests.yml @@ -126,9 +126,17 @@ jobs: working-directory: ../server run: | ./occ news:feed:add 'admin' "https://nextcloud.com/blog/feed/" + ./occ news:feed:add 'admin' "https://github.com/nextcloud/news/releases.atom" ./occ news:feed:list 'admin' | grep 'nextcloud\.com' ./occ news:feed:list 'admin' | grep -F '"faviconLink": "https:\/\/nextcloud.com\/media\/screenshot-150x150.png"' + - name: Functional tests items + working-directory: ../server + run: | + ./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep '15.3.2' + ./occ news:item:list-folder "admin" --limit 200 | grep '15.3.2' + ./occ news:item:list "admin" --limit 200 | grep '15.3.2' + - name: Functional tests opml working-directory: ../server run: ./occ news:opml:export 'admin' | grep 'nextcloud\.com' @@ -138,6 +146,7 @@ jobs: run: | ./occ news:folder:delete 'admin' $(./occ news:folder:list 'admin' | grep 'Something' -1 | head -1 | grep -oE '[0-9]*') ./occ news:feed:delete 'admin' $(./occ news:feed:list 'admin' | grep 'nextcloud\.com' -1 | head -1 | grep -oE '[0-9]*') + ./occ news:feed:delete 'admin' $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') - name: Prep PHP tests working-directory: ../server/apps/news diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd59c9c40..2704847033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 - Stop returning all feeds after marking folder as read. - Always fetch favicon (#1164) - Use feed logo instead of favicon if it exists and is square +- Add CI for item lists ### Fixed diff --git a/appinfo/info.xml b/appinfo/info.xml index aad6268e8e..981efa634f 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -70,6 +70,9 @@ Before you update to a new version, [check the changelog](https://github.com/nex OCA\News\Command\Config\FeedDelete OCA\News\Command\Config\FeedDelete OCA\News\Command\Config\OpmlExport + OCA\News\Command\Debug\ItemList + OCA\News\Command\Debug\FolderItemList + OCA\News\Command\Debug\FeedItemList diff --git a/lib/Command/Debug/FeedItemList.php b/lib/Command/Debug/FeedItemList.php new file mode 100644 index 0000000000..49820993cd --- /dev/null +++ b/lib/Command/Debug/FeedItemList.php @@ -0,0 +1,99 @@ +itemService = $itemService; + } + + /** + * Configure command + * + * @return void + */ + protected function configure() + { + $this->setName('news:item:list-feed') + ->setDescription('List all items in a feed') + ->addArgument('user-id', InputArgument::REQUIRED, 'User to list the items for') + ->addArgument('feed', InputArgument::REQUIRED, 'Feed to list the items for') + ->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit for item amount', 40) + ->addOption('offset', 'o', InputOption::VALUE_REQUIRED, 'Item list offset', 0) + ->addOption('reverse-sort', null, InputOption::VALUE_NONE, 'Item list sorting') + ->addOption('hide-read', null, InputOption::VALUE_NONE, 'Hide read items'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('user-id'); + + $feed = $input->getArgument('feed'); + if (!is_numeric($feed)) { + $output->writeln('Invalid Type!'); + return 255; + } + + $limit = $input->getOption('limit'); + if (!is_numeric($limit)) { + $output->writeln('Invalid limit!'); + return 255; + } + + $offset = $input->getOption('offset'); + if (!is_numeric($offset)) { + $output->writeln('Invalid offset!'); + return 255; + } + + $reverseSort = $input->getOption('reverse-sort'); + $hideRead = $input->getOption('hide-read'); + + $items = $this->itemService->findAllInFeedWithFilters( + $user, + intval($feed), + intval($limit), + intval($offset), + $hideRead, + $reverseSort, + [] + ); + + $output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT)); + + return 0; + } +} diff --git a/lib/Command/Debug/FolderItemList.php b/lib/Command/Debug/FolderItemList.php new file mode 100644 index 0000000000..4e6f07dae4 --- /dev/null +++ b/lib/Command/Debug/FolderItemList.php @@ -0,0 +1,100 @@ +itemService = $itemService; + } + + /** + * Configure command + * + * @return void + */ + protected function configure() + { + $this->setName('news:item:list-folder') + ->setDescription('List all items in a folder') + ->addArgument('user-id', InputArgument::REQUIRED, 'User to list the items for') + ->addArgument('folder', InputArgument::OPTIONAL, 'Folder to list the items for') + ->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit for item amount', 40) + ->addOption('offset', 'o', InputOption::VALUE_REQUIRED, 'Item list offset', 0) + ->addOption('reverse-sort', null, InputOption::VALUE_NONE, 'Item list sorting') + ->addOption('hide-read', null, InputOption::VALUE_NONE, 'Hide read items'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('user-id'); + + $folder = $input->getArgument('folder'); + if (!is_null($folder) && !is_numeric($folder)) { + $output->writeln('Invalid folder ID!'); + return 255; + } + + $limit = $input->getOption('limit'); + if (!is_numeric($limit)) { + $output->writeln('Invalid limit!'); + return 255; + } + + $offset = $input->getOption('offset'); + if (!is_numeric($offset)) { + $output->writeln('Invalid offset!'); + return 255; + } + + $folder = is_null($folder) ? $folder : intval($folder); + $reverseSort = $input->getOption('reverse-sort'); + $hideRead = $input->getOption('hide-read'); + + $items = $this->itemService->findAllInFolderWithFilters( + $user, + $folder, + intval($limit), + intval($offset), + $hideRead, + $reverseSort, + [] + ); + + $output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT)); + + return 0; + } +} diff --git a/lib/Command/Debug/ItemList.php b/lib/Command/Debug/ItemList.php new file mode 100644 index 0000000000..06f8b1c1bc --- /dev/null +++ b/lib/Command/Debug/ItemList.php @@ -0,0 +1,94 @@ +itemService = $itemService; + } + + /** + * Configure command + * + * @return void + */ + protected function configure() + { + $this->setName('news:item:list') + ->setDescription('List all items') + ->addArgument('user-id', InputArgument::REQUIRED, 'User to list the items for') + ->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Item type', ListType::ALL_ITEMS) + ->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit for item amount', 40) + ->addOption('offset', 'o', InputOption::VALUE_REQUIRED, 'Item list offset', 0) + ->addOption('reverse-sort', 'r', InputOption::VALUE_NONE, 'Item list sorting'); + } + + /** + * Execute command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $user = $input->getArgument('user-id'); + + $type = $input->getOption('type'); + if (!is_numeric($type)) { + $output->writeln('Invalid Type!'); + return 255; + } + $limit = $input->getOption('limit'); + if (!is_numeric($limit)) { + $output->writeln('Invalid limit!'); + return 255; + } + $offset = $input->getOption('offset'); + if (!is_numeric($offset)) { + $output->writeln('Invalid offset!'); + return 255; + } + $reverseSort = $input->getOption('reverse-sort'); + + $items = $this->itemService->findAllWithFilters( + $user, + intval($type), + intval($limit), + intval($offset), + $reverseSort, + [] + ); + + $output->writeln(json_encode($this->serialize($items), JSON_PRETTY_PRINT)); + + return 0; + } +} diff --git a/lib/Db/FeedType.php b/lib/Db/ListType.php similarity index 100% rename from lib/Db/FeedType.php rename to lib/Db/ListType.php From ed3eb6bb92858fe9ad0a914ff1838b628a935ef4 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 16 Feb 2021 21:17:10 +0100 Subject: [PATCH 2/2] General: Fix folder query Signed-off-by: Sean Molenaar --- .github/workflows/api-integration-tests.yml | 7 ++-- CHANGELOG.md | 1 + lib/Controller/FeedController.php | 8 ++--- lib/Controller/ItemApiController.php | 10 +++--- lib/Controller/ItemController.php | 10 +++--- lib/Controller/PageController.php | 4 +-- lib/Db/ItemMapperV2.php | 15 ++++++--- lib/Db/ListType.php | 16 ++++----- lib/Service/ItemServiceV2.php | 4 +-- tests/Unit/Controller/FeedControllerTest.php | 14 ++++---- tests/Unit/Controller/ItemControllerTest.php | 34 ++++++++++---------- tests/Unit/Controller/PageControllerTest.php | 6 ++-- tests/Unit/Db/ItemMapperTest.php | 3 +- tests/Unit/Service/ItemServiceTest.php | 8 ++--- 14 files changed, 74 insertions(+), 66 deletions(-) diff --git a/.github/workflows/api-integration-tests.yml b/.github/workflows/api-integration-tests.yml index 809d63e4ca..29df1d65dd 100644 --- a/.github/workflows/api-integration-tests.yml +++ b/.github/workflows/api-integration-tests.yml @@ -133,9 +133,10 @@ jobs: - name: Functional tests items working-directory: ../server run: | - ./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep '15.3.2' - ./occ news:item:list-folder "admin" --limit 200 | grep '15.3.2' - ./occ news:item:list "admin" --limit 200 | grep '15.3.2' + TAG=$(curl --silent "https://api.github.com/repos/nextcloud/news/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + ./occ news:item:list-feed "admin" $(./occ news:feed:list 'admin' | grep 'github\.com' -1 | head -1 | grep -oE '[0-9]*') --limit 200 | grep "$TAG" + ./occ news:item:list-folder "admin" --limit 200 | grep "$TAG" + ./occ news:item:list "admin" --limit 200 | grep "$TAG" - name: Functional tests opml working-directory: ../server diff --git a/CHANGELOG.md b/CHANGELOG.md index 2704847033..c7b5cd0994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 - Add CI for item lists ### Fixed +- Item list throwing error for folder and "all items" ## [15.3.2] - 2021-02-10 No changes compared to RC2 diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index 681dda4bc9..c80a5c327b 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -24,7 +24,7 @@ use OCP\IConfig; use OCP\AppFramework\Http; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCP\IUserSession; class FeedController extends Controller @@ -122,10 +122,10 @@ public function active(): array $feedType = intval($feedType); switch ($feedType) { - case FeedType::FOLDER: + case ListType::FOLDER: $this->folderService->find($this->getUserId(), $feedId); break; - case FeedType::FEED: + case ListType::FEED: $this->feedService->find($this->getUserId(), $feedId); break; default: @@ -133,7 +133,7 @@ public function active(): array } } catch (ServiceNotFoundException $ex) { $feedId = 0; - $feedType = FeedType::SUBSCRIPTIONS; + $feedType = ListType::ALL_ITEMS; } return [ diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php index 003c61fa2c..5f9da73a6a 100644 --- a/lib/Controller/ItemApiController.php +++ b/lib/Controller/ItemApiController.php @@ -15,7 +15,7 @@ namespace OCA\News\Controller; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceValidationException; use OCA\News\Service\ItemServiceV2; @@ -73,7 +73,7 @@ public function index( bool $oldestFirst = false ): array { switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedWithFilters( $this->getUserId(), $id, @@ -83,7 +83,7 @@ public function index( $oldestFirst ); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderWithFilters( $this->getUserId(), $id, @@ -130,10 +130,10 @@ public function updated(int $type = 3, int $id = 0, int $lastModified = 0): arra } switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedAfter($this->getUserId(), $id, $paddedLastModified, false); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderAfter($this->getUserId(), $id, $paddedLastModified, false); break; default: diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php index 02a308d872..85f67ef7a9 100644 --- a/lib/Controller/ItemController.php +++ b/lib/Controller/ItemController.php @@ -13,7 +13,7 @@ namespace OCA\News\Controller; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\FeedServiceV2; use OCP\AppFramework\Http\JSONResponse; @@ -136,7 +136,7 @@ public function index( } switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedWithFilters( $this->getUserId(), $id, @@ -147,7 +147,7 @@ public function index( $search_items ); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderWithFilters( $this->getUserId(), $id, @@ -201,7 +201,7 @@ public function newItems(int $type, int $id, $lastModified = 0): array try { switch ($type) { - case FeedType::FEED: + case ListType::FEED: $items = $this->itemService->findAllInFeedAfter( $this->getUserId(), $id, @@ -209,7 +209,7 @@ public function newItems(int $type, int $id, $lastModified = 0): array !$showAll ); break; - case FeedType::FOLDER: + case ListType::FOLDER: $items = $this->itemService->findAllInFolderAfter( $this->getUserId(), $id, diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 87ed91c734..9f17f5690f 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -25,7 +25,7 @@ use OCA\News\Service\StatusService; use OCA\News\Explore\RecommendedSites; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCP\IUserSession; class PageController extends Controller @@ -204,7 +204,7 @@ public function explore(string $lang) $this->getUserId(), $this->appName, 'lastViewedFeedType', - FeedType::EXPLORE + ListType::EXPLORE ); try { diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php index cfd30b75ec..1ef9da2440 100644 --- a/lib/Db/ItemMapperV2.php +++ b/lib/Db/ItemMapperV2.php @@ -12,6 +12,7 @@ namespace OCA\News\Db; +use OC\DB\QueryBuilder\Literal; use OCA\News\Service\Exceptions\ServiceValidationException; use Doctrine\DBAL\FetchMode; use OCA\News\Utility\Time; @@ -386,12 +387,14 @@ public function findAllAfter(string $userId, int $feedType, int $updatedSince): ->addOrderBy('items.id', 'DESC'); switch ($feedType) { - case FeedType::STARRED: + case ListType::STARRED: $builder->andWhere('items.starred = 1'); break; - case FeedType::UNREAD: + case ListType::UNREAD: $builder->andWhere('items.unread = 1'); break; + case ListType::ALL_ITEMS: + break; default: throw new ServiceValidationException('Unexpected Feed type in call'); } @@ -473,7 +476,7 @@ public function findAllFolder( if ($folderId === null) { $folderWhere = $builder->expr()->isNull('feeds.folder_id'); } else { - $folderWhere = $builder->expr()->eq('feeds.folder_id', $folderId); + $folderWhere = $builder->expr()->eq('feeds.folder_id', new Literal($folderId), IQueryBuilder::PARAM_INT); } $builder->select('items.*') @@ -542,12 +545,14 @@ public function findAllItems( } switch ($type) { - case FeedType::STARRED: + case ListType::STARRED: $builder->andWhere('items.starred = 1'); break; - case FeedType::UNREAD: + case ListType::UNREAD: $builder->andWhere('items.unread = 1'); break; + case ListType::ALL_ITEMS: + break; default: throw new ServiceValidationException('Unexpected Feed type in call'); } diff --git a/lib/Db/ListType.php b/lib/Db/ListType.php index 1ccd592a8d..e96e29ed6e 100644 --- a/lib/Db/ListType.php +++ b/lib/Db/ListType.php @@ -18,13 +18,13 @@ * * @package OCA\News\Db */ -class FeedType +class ListType { - const FEED = 0; - const FOLDER = 1; - const STARRED = 2; - const SUBSCRIPTIONS = 3; - const SHARED = 4; - const EXPLORE = 5; - const UNREAD = 6; + const FEED = 0; + const FOLDER = 1; + const STARRED = 2; + const ALL_ITEMS = 3; + const SHARED = 4; + const EXPLORE = 5; + const UNREAD = 6; } diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php index 8a518b5bdd..da675450fd 100644 --- a/lib/Service/ItemServiceV2.php +++ b/lib/Service/ItemServiceV2.php @@ -14,7 +14,7 @@ use OCA\News\AppInfo\Application; use OCA\News\Db\Feed; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Db\Item; use OCA\News\Db\ItemMapperV2; use OCA\News\Service\Exceptions\ServiceConflictException; @@ -307,7 +307,7 @@ public function findAllInFolderAfter(string $userId, ?int $folderId, int $update */ public function findAllAfter(string $userId, int $feedType, int $updatedSince): array { - if (!in_array($feedType, [FeedType::STARRED, FeedType::UNREAD])) { + if (!in_array($feedType, [ListType::STARRED, ListType::UNREAD, ListType::ALL_ITEMS])) { throw new ServiceValidationException('Trying to find in unknown type'); } diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index b8929d3731..cf7bc501e1 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -22,7 +22,7 @@ use OCP\AppFramework\Http; use OCA\News\Db\Feed; -use OCA\News\Db\FeedType; +use OCA\News\Db\ListType; use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\Exceptions\ServiceConflictException; use OCP\IConfig; @@ -125,7 +125,7 @@ public function setUp(): void $this->exampleResult = [ 'activeFeed' => [ 'id' => 0, - 'type' => FeedType::SUBSCRIPTIONS + 'type' => ListType::ALL_ITEMS ] ]; } @@ -207,7 +207,7 @@ private function activeInitMocks($id, $type): void public function testActive() { $id = 3; - $type = FeedType::STARRED; + $type = ListType::STARRED; $result = [ 'activeFeed' => [ 'id' => $id, @@ -226,7 +226,7 @@ public function testActive() public function testActiveFeed() { $id = 3; - $type = FeedType::FEED; + $type = ListType::FEED; $result = [ 'activeFeed' => [ 'id' => $id, @@ -250,7 +250,7 @@ public function testActiveFeed() public function testActiveFeedDoesNotExist() { $id = 3; - $type = FeedType::FEED; + $type = ListType::FEED; $ex = new ServiceNotFoundException('hiu'); $result = $this->exampleResult; @@ -269,7 +269,7 @@ public function testActiveFeedDoesNotExist() public function testActiveFolder() { - $type = FeedType::FOLDER; + $type = ListType::FOLDER; $folder = new Folder(); $folder->setId(3); @@ -296,7 +296,7 @@ public function testActiveFolder() public function testActiveFolderDoesNotExist() { $id = 3; - $type = FeedType::FOLDER; + $type = ListType::FOLDER; $ex = new ServiceNotFoundException('hiu'); $result = $this->exampleResult; diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index 546b392786..c64cd93300 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -20,7 +20,7 @@ use \OCA\News\Db\Item; use \OCA\News\Db\Feed; -use \OCA\News\Db\FeedType; +use \OCA\News\Db\ListType; use \OCA\News\Service\Exceptions\ServiceNotFoundException; use OCP\IConfig; use OCP\IRequest; @@ -234,7 +234,7 @@ public function testIndexForFeed() 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::FEED, '0'); + $this->itemsApiExpects(2, ListType::FEED, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -256,7 +256,7 @@ public function testIndexForFeed() ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::FEED, 2, 3); + $response = $this->controller->index(ListType::FEED, 2, 3); $this->assertEquals($result, $response); } @@ -271,7 +271,7 @@ public function testIndexForFolder() 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::FOLDER, '0'); + $this->itemsApiExpects(2, ListType::FOLDER, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -293,7 +293,7 @@ public function testIndexForFolder() ->with('user', 2, 3, 0, false, false, []) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::FOLDER, 2, 3); + $response = $this->controller->index(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } @@ -308,7 +308,7 @@ public function testIndexForOther() 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::STARRED, '0'); + $this->itemsApiExpects(2, ListType::STARRED, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -330,7 +330,7 @@ public function testIndexForOther() ->with('user', 2, 3, 0, false, []) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::STARRED, 2, 3); + $response = $this->controller->index(ListType::STARRED, 2, 3); $this->assertEquals($result, $response); } @@ -345,7 +345,7 @@ public function testIndexSearchFeed() 'starred' => 3 ]; - $this->itemsApiExpects(2, FeedType::FEED, '0'); + $this->itemsApiExpects(2, ListType::FEED, '0'); $this->feedService->expects($this->once()) ->method('findAllForUser') @@ -367,7 +367,7 @@ public function testIndexSearchFeed() ->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'); + $response = $this->controller->index(ListType::FEED, 2, 3, 0, null, null, 'test%20%20search%20'); $this->assertEquals($result, $response); } @@ -376,7 +376,7 @@ public function testItemsOffsetNotZero() { $result = ['items' => [new Item()]]; - $this->itemsApiExpects(2, FeedType::FEED); + $this->itemsApiExpects(2, ListType::FEED); $this->itemService->expects($this->once()) ->method('findAllInFeedWithFilters') @@ -386,21 +386,21 @@ public function testItemsOffsetNotZero() $this->feedService->expects($this->never()) ->method('findAllForUser'); - $response = $this->controller->index(FeedType::FEED, 2, 3, 10); + $response = $this->controller->index(ListType::FEED, 2, 3, 10); $this->assertEquals($result, $response); } public function testGetItemsNoNewestItemsId() { - $this->itemsApiExpects(2, FeedType::FEED); + $this->itemsApiExpects(2, ListType::FEED); $this->itemService->expects($this->once()) ->method('newest') ->with('user') ->will($this->throwException(new ServiceNotFoundException(''))); - $response = $this->controller->index(FeedType::FEED, 2, 3); + $response = $this->controller->index(ListType::FEED, 2, 3); $this->assertEquals([], $response); } @@ -440,7 +440,7 @@ public function testNewItemsFeed() ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); - $response = $this->controller->newItems(FeedType::FEED, 2, 3); + $response = $this->controller->newItems(ListType::FEED, 2, 3); $this->assertEquals($result, $response); } @@ -480,7 +480,7 @@ public function testNewItemsFolder() ->with('user', 2, 3, false) ->will($this->returnValue($result['items'])); - $response = $this->controller->newItems(FeedType::FOLDER, 2, 3); + $response = $this->controller->newItems(ListType::FOLDER, 2, 3); $this->assertEquals($result, $response); } @@ -520,7 +520,7 @@ public function testNewItemsOther() ->with('user', 6, 3) ->will($this->returnValue($result['items'])); - $response = $this->controller->newItems(FeedType::UNREAD, 2, 3); + $response = $this->controller->newItems(ListType::UNREAD, 2, 3); $this->assertEquals($result, $response); } @@ -537,7 +537,7 @@ public function testGetNewItemsNoNewestItemsId() ->with('user') ->will($this->throwException(new ServiceNotFoundException(''))); - $response = $this->controller->newItems(FeedType::FEED, 2, 3); + $response = $this->controller->newItems(ListType::FEED, 2, 3); $this->assertEquals([], $response); } diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 5f62bfe9fc..4e29504796 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -15,7 +15,7 @@ use OC\L10N\L10N; use OCA\News\Controller\PageController; -use \OCA\News\Db\FeedType; +use \OCA\News\Db\ListType; use OCA\News\Explore\Exceptions\RecommendedSiteNotFoundException; use OCA\News\Explore\RecommendedSites; use OCA\News\Service\StatusService; @@ -264,7 +264,7 @@ public function testExplore() ->method('setUserValue') ->withConsecutive( ['becka', 'news', 'lastViewedFeedId', 0], - ['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE] + ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] ); $this->recommended->expects($this->once()) @@ -284,7 +284,7 @@ public function testExploreError() ->method('setUserValue') ->withConsecutive( ['becka', 'news', 'lastViewedFeedId', 0], - ['becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE] + ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] ); $this->recommended->expects($this->once()) diff --git a/tests/Unit/Db/ItemMapperTest.php b/tests/Unit/Db/ItemMapperTest.php index 878f8c59db..c1e946d2bb 100644 --- a/tests/Unit/Db/ItemMapperTest.php +++ b/tests/Unit/Db/ItemMapperTest.php @@ -13,6 +13,7 @@ namespace OCA\News\Tests\Unit\Db; +use OC\DB\QueryBuilder\Literal; use OCA\News\Db\Feed; use OCA\News\Db\FeedMapperV2; use OCA\News\Db\Folder; @@ -1691,7 +1692,7 @@ public function testFindAllFolderSearchId() $expr->expects($this->once()) ->method('eq') - ->with('feeds.folder_id', 2) + ->with('feeds.folder_id', new Literal(2)) ->will($this->returnValue('x = y')); $this->db->expects($this->once()) diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index e82d5eda73..f91692cda1 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -21,7 +21,7 @@ use \OCP\AppFramework\Db\DoesNotExistException; use \OCA\News\Db\Item; -use \OCA\News\Db\FeedType; +use \OCA\News\Db\ListType; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\IConfig; @@ -133,7 +133,7 @@ public function testFindAllNewItemWrongType() $this->mapper->expects($this->never()) ->method('findAllAfter'); - $result = $this->class->findAllAfter($this->user, 3, 20333); + $result = $this->class->findAllAfter($this->user, 5, 20333); $this->assertEquals([], $result); } @@ -176,7 +176,7 @@ public function testFindAllFolder() public function testFindAllItems() { - $type = FeedType::STARRED; + $type = ListType::STARRED; $this->mapper->expects($this->once()) ->method('findAllItems') ->with('jack', $type, 20, 5, true, []) @@ -188,7 +188,7 @@ public function testFindAllItems() public function testFindAllSearch() { - $type = FeedType::STARRED; + $type = ListType::STARRED; $search = ['test'];