diff --git a/.github/workflows/api-integration-tests.yml b/.github/workflows/api-integration-tests.yml index bc2c0b8b0b..cdde1aa169 100644 --- a/.github/workflows/api-integration-tests.yml +++ b/.github/workflows/api-integration-tests.yml @@ -28,16 +28,16 @@ jobs: - 5432:5432 # Maps tcp port 5432 on service container to the host strategy: matrix: - php-versions: ['8.0', '8.1'] - nextcloud: ['stable27'] + php-versions: ['8.2', '8.3'] + nextcloud: ['stable29'] database: ['sqlite', 'pgsql', 'mysql'] experimental: [false] include: - - php-versions: 8.1 + - php-versions: 8.3 nextcloud: pre-release database: sqlite experimental: true - - php-versions: 8.2 + - php-versions: 8.3 nextcloud: pre-release database: sqlite experimental: true diff --git a/.github/workflows/api-php-static-code-check.yml b/.github/workflows/api-php-static-code-check.yml index 9a37fc40cc..5ed3a0f1c2 100644 --- a/.github/workflows/api-php-static-code-check.yml +++ b/.github/workflows/api-php-static-code-check.yml @@ -7,11 +7,11 @@ jobs: continue-on-error: true strategy: matrix: - php-versions: ['8.0', '8.1', '8.2' ] - nextcloud: [ 'stable27' ] + php-versions: ['8.2', '8.3' ] + nextcloud: [ 'stable29' ] database: [ 'sqlite' ] include: - - php-versions: 8.2 + - php-versions: 8.3 nextcloud: pre-release database: sqlite experimental: true diff --git a/.github/workflows/api-php-tests.yml b/.github/workflows/api-php-tests.yml index 2fb7907700..4742b7b47c 100644 --- a/.github/workflows/api-php-tests.yml +++ b/.github/workflows/api-php-tests.yml @@ -9,14 +9,14 @@ jobs: name: "PHP: Nextcloud ${{ matrix.nextcloud }} - PHP ${{ matrix.php-versions }} - DB ${{ matrix.database }}" strategy: matrix: - php-versions: ['8.1'] - nextcloud: ['stable27'] + php-versions: ['8.3'] + nextcloud: ['stable29'] database: ['sqlite'] experimental: [false] codecoverage: [false] include: - - php-versions: 8.2 - nextcloud: stable27 + - php-versions: 8.3 + nextcloud: stable29 database: sqlite experimental: false codecoverage: true diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index c8f5a988a4..739a028ec5 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -14,8 +14,8 @@ jobs: name: "Release: build, sign and upload the app" strategy: matrix: - php-versions: ['8.1'] - nextcloud: ['stable27'] + php-versions: ['8.3'] + nextcloud: ['stable29'] database: ['sqlite'] steps: - name: Checkout diff --git a/.github/workflows/frontend-nodejs-tests.yml b/.github/workflows/frontend-nodejs-tests.yml index 6b0cbbed97..b772e19a4c 100644 --- a/.github/workflows/frontend-nodejs-tests.yml +++ b/.github/workflows/frontend-nodejs-tests.yml @@ -9,8 +9,8 @@ jobs: name: "Frontend: Nextcloud ${{ matrix.nextcloud }} - PHP ${{ matrix.php-versions }} - DB ${{ matrix.database }}" strategy: matrix: - php-versions: ['8.1'] - nextcloud: ['stable27'] + php-versions: ['8.3'] + nextcloud: ['stable29'] database: ['sqlite'] experimental: [false] steps: diff --git a/.github/workflows/post-merge-tasks.yml b/.github/workflows/post-merge-tasks.yml index 58859acecf..1e27e00800 100644 --- a/.github/workflows/post-merge-tasks.yml +++ b/.github/workflows/post-merge-tasks.yml @@ -10,9 +10,9 @@ jobs: name: "Coverage: Nextcloud ${{ matrix.nextcloud }} PHP ${{ matrix.php-version }}" strategy: matrix: - nextcloud: ['stable27'] + php-version: ["8.3"] + nextcloud: ['stable29'] codecoverage: [true] - php-version: ["8.1"] steps: - name: Checkout uses: actions/checkout@v4 @@ -41,11 +41,11 @@ jobs: - name: Prep PHP tests run: cd ../server/apps/news && make php-test-dependencies - + - name: Unittests run: cd ../server/apps/news && make unit-test env: CODECOVERAGE: ${{ matrix.codecoverage }} - + - name: Upload codecoverage run: cd ../server/apps/news && bash <(curl -s https://codecov.io/bash) -f build/php-unit.clover diff --git a/.github/workflows/updater-test.yml b/.github/workflows/updater-test.yml index 7ae6103fcf..f5cd39b249 100644 --- a/.github/workflows/updater-test.yml +++ b/.github/workflows/updater-test.yml @@ -16,8 +16,8 @@ jobs: name: "Update Test: Nextcloud ${{ matrix.nextcloud }} - PHP ${{ matrix.php-versions }}" strategy: matrix: - php-versions: ['8.1'] - nextcloud: ['stable27'] + php-versions: ['8.3'] + nextcloud: ['stable29'] database: ['sqlite'] experimental: [false] steps: @@ -71,7 +71,7 @@ jobs: sleep 2 cd ${{ github.workspace }}/../server - + bats apps/news/tests/updater # Kill php server diff --git a/CHANGELOG.md b/CHANGELOG.md index fb7f5a3221..cb0d1a9d95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the # Unreleased ## [25.x.x] ### Changed - +- Require NC 29 +- Require PHP 8.2 or higher ### Fixed - Allow feed title to be null in DB. #2745 diff --git a/appinfo/info.xml b/appinfo/info.xml index 5e28a90042..1fc3218b97 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -43,7 +43,7 @@ Report a [feed issue](https://github.com/nextcloud/news/discussions/new) https://raw.githubusercontent.com/nextcloud/news/master/screenshots/2.png https://raw.githubusercontent.com/nextcloud/news/master/screenshots/3.png - + pgsql sqlite mysql @@ -55,7 +55,7 @@ Report a [feed issue](https://github.com/nextcloud/news/discussions/new) json - + diff --git a/composer.json b/composer.json index b8bc03e0db..ee5d836fcf 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "source": "https://github.com/nextcloud/news/" }, "require": { - "php": "~8.0", + "php": "^8.2", "ezyang/htmlpurifier": "^4.17.0", "pear/net_url2": "^2.2.2", "riimu/kit-pathjoin": "^1.2.0", diff --git a/composer.lock b/composer.lock index 6097e214dc..a0f37136b7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f1ad2694267655dcaf945b7355046a14", + "content-hash": "c9df39887dfca2bfe740bb13d5b55c32", "packages": [ { "name": "arthurhoaro/favicon", @@ -766,16 +766,16 @@ }, { "name": "doctrine/dbal", - "version": "3.9.1", + "version": "3.9.0", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "d7dc08f98cba352b2bab5d32c5e58f7e745c11a7" + "reference": "d8f68ea6cc00912e5313237130b8c8decf4d28c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/d7dc08f98cba352b2bab5d32c5e58f7e745c11a7", - "reference": "d7dc08f98cba352b2bab5d32c5e58f7e745c11a7", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/d8f68ea6cc00912e5313237130b8c8decf4d28c6", + "reference": "d8f68ea6cc00912e5313237130b8c8decf4d28c6", "shasum": "" }, "require": { @@ -791,7 +791,7 @@ "doctrine/coding-standard": "12.0.0", "fig/log-test": "^1", "jetbrains/phpstorm-stubs": "2023.1", - "phpstan/phpstan": "1.12.0", + "phpstan/phpstan": "1.11.7", "phpstan/phpstan-strict-rules": "^1.6", "phpunit/phpunit": "9.6.20", "psalm/plugin-phpunit": "0.18.4", @@ -859,7 +859,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.9.1" + "source": "https://github.com/doctrine/dbal/tree/3.9.0" }, "funding": [ { @@ -875,7 +875,7 @@ "type": "tidelift" } ], - "time": "2024-09-01T13:49:23+00:00" + "time": "2024-08-15T07:34:42+00:00" }, { "name": "doctrine/deprecations", @@ -1323,16 +1323,16 @@ }, { "name": "phpstan/extension-installer", - "version": "1.4.2", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/phpstan/extension-installer.git", - "reference": "46c8219b3fb0deb3fc08301e8f0797d321d17dcd" + "reference": "f6b87faf9fc7978eab2f7919a8760bc9f58f9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/46c8219b3fb0deb3fc08301e8f0797d321d17dcd", - "reference": "46c8219b3fb0deb3fc08301e8f0797d321d17dcd", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f6b87faf9fc7978eab2f7919a8760bc9f58f9203", + "reference": "f6b87faf9fc7978eab2f7919a8760bc9f58f9203", "shasum": "" }, "require": { @@ -1359,28 +1359,24 @@ "MIT" ], "description": "Composer plugin for automatic installation of PHPStan extensions", - "keywords": [ - "dev", - "static analysis" - ], "support": { "issues": "https://github.com/phpstan/extension-installer/issues", - "source": "https://github.com/phpstan/extension-installer/tree/1.4.2" + "source": "https://github.com/phpstan/extension-installer/tree/1.4.1" }, - "time": "2024-08-26T07:38:00+00:00" + "time": "2024-06-10T08:20:49+00:00" }, { "name": "phpstan/phpstan", - "version": "1.12.4", + "version": "1.11.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "ffa517cb918591b93acc9b95c0bebdcd0e4538bd" + "reference": "640410b32995914bde3eed26fa89552f9c2c082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ffa517cb918591b93acc9b95c0bebdcd0e4538bd", - "reference": "ffa517cb918591b93acc9b95c0bebdcd0e4538bd", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", + "reference": "640410b32995914bde3eed26fa89552f9c2c082f", "shasum": "" }, "require": { @@ -1425,7 +1421,7 @@ "type": "github" } ], - "time": "2024-09-19T07:58:01+00:00" + "time": "2024-08-08T09:02:50+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -1476,16 +1472,16 @@ }, { "name": "phpstan/phpstan-doctrine", - "version": "1.5.3", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-doctrine.git", - "reference": "38db3bad8f1567d7bf64806738d724261f8a2b5c" + "reference": "caa046bd6152818e781260fb3a7a96d6b0fadeed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/38db3bad8f1567d7bf64806738d724261f8a2b5c", - "reference": "38db3bad8f1567d7bf64806738d724261f8a2b5c", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/caa046bd6152818e781260fb3a7a96d6b0fadeed", + "reference": "caa046bd6152818e781260fb3a7a96d6b0fadeed", "shasum": "" }, "require": { @@ -1542,9 +1538,9 @@ "description": "Doctrine extensions for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-doctrine/issues", - "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.5.3" + "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.5.0" }, - "time": "2024-09-01T13:17:34+00:00" + "time": "2024-08-05T13:47:07+00:00" }, { "name": "phpstan/phpstan-phpunit", @@ -3083,16 +3079,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.10.3", + "version": "3.10.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "62d32998e820bddc40f99f8251958aed187a5c9c" + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/62d32998e820bddc40f99f8251958aed187a5c9c", - "reference": "62d32998e820bddc40f99f8251958aed187a5c9c", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017", "shasum": "" }, "require": { @@ -3159,7 +3155,7 @@ "type": "open_collective" } ], - "time": "2024-09-18T10:38:58+00:00" + "time": "2024-07-21T23:26:44+00:00" }, { "name": "theseer/tokenizer", diff --git a/lib/Command/Updater/Job.php b/lib/Command/Updater/Job.php index b8124d82f5..0596ef6c7e 100644 --- a/lib/Command/Updater/Job.php +++ b/lib/Command/Updater/Job.php @@ -10,8 +10,7 @@ use DateTime; use DateInterval; -use OCP\Util; -use OCP\IConfig; +use OCP\IAppConfig; use OCA\News\AppInfo\Application; use OCA\News\Service\StatusService; use OCA\News\Service\UpdaterService; @@ -22,27 +21,12 @@ class Job extends Command { - /** - * @var IConfig - */ - private $config; - - /** - * @var StatusService Status service - */ - private $statusService; - - /** - * @var UpdaterService Update service - */ - private $updaterService; - - public function __construct(IConfig $config, StatusService $statusService, UpdaterService $updaterService) - { + public function __construct( + private IAppConfig $config, + private StatusService $statusService, + private UpdaterService $updaterService + ) { parent::__construct(); - $this->config = $config; - $this->statusService = $statusService; - $this->updaterService = $updaterService; } /** @@ -71,12 +55,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $reset = (bool) $input->getOption('reset'); $checkElapsed = (bool) $input->getOption('check-elapsed'); - [$major, $minor, $micro] = Util::getVersion(); - - if ($major < 26) { - $output->writeln("Error: This only works with Nextcloud 26 or newer."); - return 1; - } $output->writeln("Checking update Status"); $date = new DateTime(); $date->setTimestamp($this->statusService->getUpdateTime()); @@ -95,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($checkElapsed) { - $updateInterval = $this->config->getAppValue( + $updateInterval = $this->config->getValueString( Application::NAME, 'updateInterval', Application::DEFAULT_SETTINGS['updateInterval'] diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index 710c41e245..048b06f038 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -18,6 +18,8 @@ use OCA\News\AppInfo\Application; use OCA\News\Fetcher\Client\FeedIoClient; use OCP\IConfig; +use OCP\IAppConfig; +use Net_URL2; /** * Class FetcherConfig @@ -61,29 +63,30 @@ class FetcherConfig /** * FetcherConfig constructor. * - * @param IConfig $config + * @param IAppConfig $config App configuration + * @param IConfig $systemconfig System configuration */ - public function __construct(IConfig $config) + public function __construct(IAppConfig $config, IConfig $systemconfig) { - $this->client_timeout = $config->getAppValue( + $this->client_timeout = $config->getValueInt( Application::NAME, 'feedFetcherTimeout', Application::DEFAULT_SETTINGS['feedFetcherTimeout'] ); - $this->redirects = $config->getAppValue( + $this->redirects = $config->getValueInt( Application::NAME, 'maxRedirects', Application::DEFAULT_SETTINGS['maxRedirects'] ); - $proxy = $config->getSystemValue('proxy', null); + $proxy = $systemconfig->getSystemValue('proxy', null); if (is_null($proxy)) { return $this; } - $url = new \Net_URL2($proxy); + $url = new Net_URL2($proxy); - $creds = $config->getSystemValue('proxyuserpwd', null); + $creds = $systemconfig->getSystemValue('proxyuserpwd', null); if ($creds !== null) { $auth = explode(':', $creds, 2); $url->setUserinfo($auth[0], $auth[1]); @@ -97,9 +100,9 @@ public function __construct(IConfig $config) /** * Checks for available encoding options * - * @return String list of supported encoding types + * @return string list of supported encoding types */ - public function checkEncoding() + public function checkEncoding(): string { $supportedEncoding = []; diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index abdd3f2f78..e37d0bc618 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -16,6 +16,7 @@ use OCA\News\AppInfo\Application; use OCA\News\Explore\Exceptions\RecommendedSiteNotFoundException; use OCP\IRequest; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; @@ -32,46 +33,17 @@ class PageController extends Controller { use JSONHttpErrorTrait; - /** - * @var IConfig - */ - private $settings; - - /** - * @var IL10N - */ - private $l10n; - - /** - * @var IURLGenerator - */ - private $urlGenerator; - - /** - * @var RecommendedSites - */ - private $recommendedSites; - - /** - * @var StatusService - */ - private $statusService; - public function __construct( IRequest $request, - IConfig $settings, - IURLGenerator $urlGenerator, - IL10N $l10n, - RecommendedSites $recommendedSites, - StatusService $statusService, - ?IUserSession $userSession + ?IUserSession $userSession, + private IAppConfig $settings, + private IConfig $config, + private IURLGenerator $urlGenerator, + private IL10N $l10n, + private RecommendedSites $recommendedSites, + private StatusService $statusService ) { parent::__construct($request, $userSession); - $this->settings = $settings; - $this->urlGenerator = $urlGenerator; - $this->l10n = $l10n; - $this->recommendedSites = $recommendedSites; - $this->statusService = $statusService; } @@ -121,7 +93,7 @@ public function settings(): array 'compactExpand' ]; - $exploreUrl = $this->settings->getAppValue( + $exploreUrl = $this->settings->getValueString( $this->appName, 'exploreUrl', Application::DEFAULT_SETTINGS['exploreUrl'] @@ -141,7 +113,7 @@ public function settings(): array ]; foreach ($settings as $setting) { - $result[$setting] = $this->settings->getUserValue( + $result[$setting] = $this->config->getUserValue( $this->getUserId(), $this->appName, $setting @@ -177,7 +149,7 @@ public function updateSettings( foreach ($settings as $setting => $value) { $value = $value ? '1' : '0'; - $this->settings->setUserValue( + $this->config->setUserValue( $this->getUserId(), $this->appName, $setting, @@ -195,13 +167,13 @@ public function updateSettings( */ public function explore(string $lang) { - $this->settings->setUserValue( + $this->config->setUserValue( $this->getUserId(), $this->appName, 'lastViewedFeedId', 0 ); - $this->settings->setUserValue( + $this->config->setUserValue( $this->getUserId(), $this->appName, 'lastViewedFeedType', diff --git a/lib/Controller/UtilityApiController.php b/lib/Controller/UtilityApiController.php index 943aa7b15e..02e65c2e40 100644 --- a/lib/Controller/UtilityApiController.php +++ b/lib/Controller/UtilityApiController.php @@ -17,7 +17,7 @@ use OCA\News\Service\UpdaterService; use \OCP\IRequest; -use \OCP\IConfig; +use \OCP\IAppConfig; use \OCP\IUserSession; use \OCA\News\Service\StatusService; @@ -25,21 +25,14 @@ class UtilityApiController extends ApiController { - private $updaterService; - private $settings; - private $statusService; - public function __construct( IRequest $request, ?IUserSession $userSession, - UpdaterService $updater, - IConfig $settings, - StatusService $statusService + private UpdaterService $updaterService, + private IAppConfig $settings, + private StatusService $statusService ) { parent::__construct($request, $userSession); - $this->updaterService = $updater; - $this->settings = $settings; - $this->statusService = $statusService; } @@ -50,7 +43,7 @@ public function __construct( */ public function version(): array { - $version = $this->settings->getAppValue( + $version = $this->settings->getValueString( $this->appName, 'installed_version' ); diff --git a/lib/Cron/UpdaterJob.php b/lib/Cron/UpdaterJob.php index 44bb7bfa30..bac95537c0 100644 --- a/lib/Cron/UpdaterJob.php +++ b/lib/Cron/UpdaterJob.php @@ -17,36 +17,20 @@ use OCA\News\AppInfo\Application; use OCA\News\Service\StatusService; use OCA\News\Service\UpdaterService; -use OCP\IConfig; +use OCP\IAppConfig; class UpdaterJob extends TimedJob { - /** - * @var IConfig - */ - private $config; - /** - * @var StatusService - */ - private $statusService; - /** - * @var UpdaterService - */ - private $updaterService; - public function __construct( ITimeFactory $time, - IConfig $config, - StatusService $status, - UpdaterService $updaterService + private IAppConfig $config, + private StatusService $statusService, + private UpdaterService $updaterService ) { parent::__construct($time); - $this->config = $config; - $this->statusService = $status; - $this->updaterService = $updaterService; - $interval = $this->config->getAppValue( + $interval = $this->config->getValueString( Application::NAME, 'updateInterval', Application::DEFAULT_SETTINGS['updateInterval'] @@ -58,9 +42,9 @@ public function __construct( /** * @return void */ - protected function run($argument) + protected function run($argument): void { - $uses_cron = (bool) $this->config->getAppValue( + $uses_cron = $this->config->getValueBool( Application::NAME, 'useCronUpdates', Application::DEFAULT_SETTINGS['useCronUpdates'] diff --git a/lib/Search/FeedSearchProvider.php b/lib/Search/FeedSearchProvider.php index 65b2059c5d..3d9caeb21e 100644 --- a/lib/Search/FeedSearchProvider.php +++ b/lib/Search/FeedSearchProvider.php @@ -20,20 +20,12 @@ */ class FeedSearchProvider implements IProvider { - /** @var IL10N */ - private $l10n; - /** @var IURLGenerator */ - private $urlGenerator; - - /** @var FeedServiceV2 */ - private $service; - - public function __construct(IL10N $l10n, IURLGenerator $urlGenerator, FeedServiceV2 $service) - { - $this->l10n = $l10n; - $this->urlGenerator = $urlGenerator; - $this->service = $service; + public function __construct( + private IL10N $l10n, + private IURLGenerator $urlGenerator, + private FeedServiceV2 $service + ) { } public function getId(): string @@ -66,13 +58,14 @@ public function search(IUser $user, ISearchQuery $query): SearchResult } $term = strtolower($term); + $imageurl = $this->urlGenerator->imagePath('core', 'rss.svg'); foreach ($this->service->findAllForUser($user->getUID()) as $feed) { if (strpos(strtolower($feed->getTitle()), $term) === false) { continue; } $list[] = new SearchResultEntry( - $this->urlGenerator->imagePath('core', 'rss.svg'), + $imageurl, $feed->getTitle(), $this->l10n->t('Unread articles') . ': ' . $feed->getUnreadCount(), $this->urlGenerator->linkToRoute('news.page.index') . '#/feed/' . $feed->getId() diff --git a/lib/Search/FolderSearchProvider.php b/lib/Search/FolderSearchProvider.php index 3997eba363..9ccbbf5607 100644 --- a/lib/Search/FolderSearchProvider.php +++ b/lib/Search/FolderSearchProvider.php @@ -67,13 +67,14 @@ public function search(IUser $user, ISearchQuery $query): SearchResult } $term = strtolower($term); + $imageurl = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg'); foreach ($this->service->findAllForUser($user->getUID()) as $folder) { if (strpos(strtolower($folder->getName()), $term) === false) { continue; } $list[] = new SearchResultEntry( - $this->urlGenerator->imagePath('core', 'filetypes/folder.svg'), + $imageurl, $folder->getName(), '', $this->urlGenerator->linkToRoute('news.page.index') . '#/folder/' . $folder->getId() diff --git a/lib/Service/FolderServiceV2.php b/lib/Service/FolderServiceV2.php index e70e4dee9f..feb6f3d49e 100644 --- a/lib/Service/FolderServiceV2.php +++ b/lib/Service/FolderServiceV2.php @@ -28,24 +28,13 @@ */ class FolderServiceV2 extends Service { - /** - * @var FeedServiceV2 - */ - private $feedService; - /** - * @var TimeFactory - */ - private $timeFactory; - public function __construct( FolderMapperV2 $mapper, - FeedServiceV2 $feedService, - TimeFactory $timeFactory, - LoggerInterface $logger + LoggerInterface $logger, + private FeedServiceV2 $feedService, + private TimeFactory $timeFactory, ) { parent::__construct($mapper, $logger); - $this->feedService = $feedService; - $this->timeFactory = $timeFactory; } /** diff --git a/lib/Service/ItemServiceV2.php b/lib/Service/ItemServiceV2.php index ab83ba5c54..4f1401c9db 100644 --- a/lib/Service/ItemServiceV2.php +++ b/lib/Service/ItemServiceV2.php @@ -23,7 +23,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\MultipleObjectsReturnedException; -use OCP\IConfig; +use OCP\IAppConfig; use Psr\Log\LoggerInterface; /** @@ -34,25 +34,19 @@ class ItemServiceV2 extends Service { - /** - * @var IConfig - */ - protected $config; - /** * ItemService constructor. * * @param ItemMapperV2 $mapper - * @param IConfig $config + * @param IAppConfig $config * @param LoggerInterface $logger */ public function __construct( ItemMapperV2 $mapper, - IConfig $config, - LoggerInterface $logger + LoggerInterface $logger, + protected IAppConfig $config ) { parent::__construct($mapper, $logger); - $this->config = $config; } /** @@ -152,17 +146,17 @@ public function read(string $userId, int $id, bool $read): Entity */ public function purgeOverThreshold(int $threshold = null, bool $purgeUnread = null): ?int { - $threshold = (int) ($threshold ?? $this->config->getAppValue( + $threshold = $threshold ?? $this->config->getValueInt( Application::NAME, 'autoPurgeCount', Application::DEFAULT_SETTINGS['autoPurgeCount'] - )); + ); - $purgeUnread = (bool) ($purgeUnread ?? $this->config->getAppValue( + $purgeUnread = $purgeUnread ?? $this->config->getValueBool( Application::NAME, 'purgeUnread', Application::DEFAULT_SETTINGS['purgeUnread'] - )); + ); if ($threshold <= 0) { return null; diff --git a/lib/Service/StatusService.php b/lib/Service/StatusService.php index 09cea9e4a2..3733513864 100644 --- a/lib/Service/StatusService.php +++ b/lib/Service/StatusService.php @@ -14,32 +14,24 @@ namespace OCA\News\Service; use OCA\News\AppInfo\Application; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IDBConnection; use OCP\BackgroundJob\IJobList; -use OCP\Util; use OCA\News\Cron\UpdaterJob; class StatusService { - /** @var IConfig */ - private $settings; - /** @var string */ - private $appName; - /** @var IDBConnection */ - private $connection; - /** @var IJobList */ - private $jobList; + /** + * Name of the app + */ + private string $appName; public function __construct( - IConfig $settings, - IDBConnection $connection, - IJobList $jobList + private IAppConfig $settings, + private IDBConnection $connection, + private IJobList $jobList ) { - $this->settings = $settings; - $this->connection = $connection; $this->appName = Application::NAME; - $this->jobList = $jobList; } /** @@ -50,13 +42,13 @@ public function __construct( public function isCronProperlyConfigured(): bool { //Is NC cron enabled? - $cronMode = $this->settings->getAppValue('core', 'backgroundjobs_mode'); + $cronMode = $this->settings->getValueString('core', 'backgroundjobs_mode'); //Expect nextcloud cron - $cronOff = !boolval($this->settings->getAppValue( + $cronOff = !$this->settings->getValueBool( Application::NAME, 'useCronUpdates', Application::DEFAULT_SETTINGS['useCronUpdates'] - )); + ); // check for cron modes which may lead to problems return $cronMode === 'cron' || $cronOff; @@ -70,7 +62,7 @@ public function isCronProperlyConfigured(): bool */ public function getStatus(): array { - $version = $this->settings->getAppValue( + $version = $this->settings->getValueString( $this->appName, 'installed_version' ); @@ -94,7 +86,7 @@ public function getUpdateTime(): int $myJobList = $this->jobList->getJobsIterator(UpdaterJob::class, 1, 0); $time = $myJobList->current()->getLastRun(); - + return $time; } } diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index 5e4e83920a..1a1637a6fe 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -5,45 +5,36 @@ use OCA\News\AppInfo\Application; use OCA\News\Service\StatusService; use OCP\AppFramework\Http\TemplateResponse; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\Settings\ISettings; use OCP\AppFramework\Services\IInitialState; class AdminSettings implements ISettings { - /** - * @var IConfig - */ - private $config; - /** @var IInitialState */ - private $initialState; - /** @var StatusService */ - private $service; - - public function __construct(IConfig $config, IInitialState $initialState, StatusService $service) - { - $this->config = $config; - $this->initialState = $initialState; - $this->service = $service; + public function __construct( + private IAppConfig $config, + private IInitialState $initialState, + private StatusService $service + ) { } public function getForm() { foreach (array_keys(Application::DEFAULT_SETTINGS) as $setting) { - $this->initialState->provideInitialState($setting, $this->config->getAppValue( + $this->initialState->provideInitialState($setting, $this->config->getValueString( Application::NAME, $setting, - (string)Application::DEFAULT_SETTINGS[$setting] + (string) Application::DEFAULT_SETTINGS[$setting] )); } - + if ($this->service->isCronProperlyConfigured()) { $lastUpdate = $this->service->getUpdateTime(); } else { $lastUpdate = 0; } - + $this->initialState->provideInitialState("lastCron", $lastUpdate); return new TemplateResponse(Application::NAME, 'admin', []); diff --git a/lib/Utility/Cache.php b/lib/Utility/Cache.php index 6337487cfa..5721a1797e 100644 --- a/lib/Utility/Cache.php +++ b/lib/Utility/Cache.php @@ -15,7 +15,7 @@ class Cache { - + /** * @var ITempManager diff --git a/tests/Unit/Config/FetcherConfigTest.php b/tests/Unit/Config/FetcherConfigTest.php index 6f5364490e..942155ec9b 100644 --- a/tests/Unit/Config/FetcherConfigTest.php +++ b/tests/Unit/Config/FetcherConfigTest.php @@ -20,16 +20,12 @@ namespace OCA\News\Tests\Config; -use OCA\News\Command\Debug\ItemList; -use OCA\News\Command\Updater\UpdateFeed; use OCA\News\Config\FetcherConfig; use OCA\News\Fetcher\Client\FeedIoClient; -use OCA\News\Service\ItemServiceV2; +use OCP\IAppConfig; use OCP\IConfig; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; /** * Class FetcherConfigTest @@ -40,17 +36,24 @@ */ class FetcherConfigTest extends TestCase { - /** @var MockObject|IConfig */ + /** @var MockObject|IAppConfig */ protected $config; + /** @var MockObject|IConfig */ + protected $sysconfig; + /** @var FetcherConfig */ protected $class; protected function setUp(): void { - $this->config = $this->getMockBuilder(IConfig::class) + $this->config = $this->getMockBuilder(IAppConfig::class) ->disableOriginalConstructor() ->getMock(); + + $this->sysconfig = $this->getMockBuilder(IConfig::class) + ->disableOriginalConstructor() + ->getMock(); } /** @@ -58,7 +61,7 @@ protected function setUp(): void */ public function testGetClient() { - $this->class = new FetcherConfig($this->config); + $this->class = new FetcherConfig($this->config, $this->sysconfig); $this->assertInstanceOf(FeedIoClient::class, $this->class->getClient()); } diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 4e29504796..4672a61a43 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -19,6 +19,7 @@ use OCA\News\Explore\Exceptions\RecommendedSiteNotFoundException; use OCA\News\Explore\RecommendedSites; use OCA\News\Service\StatusService; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; @@ -31,10 +32,15 @@ class PageControllerTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + * @var \PHPUnit\Framework\MockObject\MockObject|IAppConfig */ private $settings; + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ + private $config; + /** * @var \PHPUnit\Framework\MockObject\MockObject|IRequest */ @@ -88,7 +94,10 @@ public function setUp(): void $this->l10n = $this->request = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); - $this->settings = $this->getMockBuilder(IConfig::class) + $this->settings = $this->getMockBuilder(IAppConfig::class) + ->disableOriginalConstructor() + ->getMock(); + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder(IRequest::class) @@ -114,12 +123,13 @@ public function setUp(): void ->will($this->returnValue($this->user)); $this->controller = new PageController( $this->request, + $this->userSession, $this->settings, + $this->config, $this->urlGenerator, $this->l10n, $this->recommended, - $this->status, - $this->userSession + $this->status ); } @@ -173,26 +183,27 @@ public function testSettings() ]; $this->l10n->expects($this->once()) - ->method('getLanguageCode') - ->will($this->returnValue('de')); - $this->settings->expects($this->exactly(5)) - ->method('getUserValue') - ->withConsecutive( - ['becka', 'news', 'showAll'], - ['becka', 'news', 'compact'], - ['becka', 'news', 'preventReadOnScroll'], - ['becka', 'news', 'oldestFirst'], - ['becka', 'news', 'compactExpand'] - ) - ->will($this->returnValue('1')); + ->method('getLanguageCode') + ->will($this->returnValue('de')); + + $this->config->expects($this->exactly(5)) + ->method('getUserValue') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] + ) + ->will($this->returnValue('1')); $this->settings->expects($this->once()) - ->method('getAppValue') - ->with('news', 'exploreUrl') - ->will($this->returnValue(' ')); + ->method('getValueString') + ->with('news', 'exploreUrl') + ->will($this->returnValue(' ')); $this->urlGenerator->expects($this->once()) - ->method('linkToRoute') - ->with('news.page.explore', ['lang' => 'en']) - ->will($this->returnValue('test')); + ->method('linkToRoute') + ->with('news.page.explore', ['lang' => 'en']) + ->will($this->returnValue('test')); $response = $this->controller->settings(); @@ -215,22 +226,23 @@ public function testSettingsExploreUrlSet() ]; $this->l10n->expects($this->once()) - ->method('getLanguageCode') - ->will($this->returnValue('de')); - $this->settings->expects($this->exactly(5)) - ->method('getUserValue') - ->withConsecutive( - ['becka', 'news', 'showAll'], - ['becka', 'news', 'compact'], - ['becka', 'news', 'preventReadOnScroll'], - ['becka', 'news', 'oldestFirst'], - ['becka', 'news', 'compactExpand'] - ) - ->will($this->returnValue('1')); + ->method('getLanguageCode') + ->will($this->returnValue('de')); + + $this->config->expects($this->exactly(5)) + ->method('getUserValue') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] + ) + ->will($this->returnValue('1')); $this->settings->expects($this->once()) - ->method('getAppValue') - ->with('news', 'exploreUrl') - ->will($this->returnValue('abc')); + ->method('getValueString') + ->with('news', 'exploreUrl') + ->will($this->returnValue('abc')); $this->urlGenerator->expects($this->never()) ->method('getAbsoluteURL'); @@ -244,15 +256,15 @@ public function testSettingsExploreUrlSet() */ public function testUpdateSettings() { - $this->settings->expects($this->exactly(5)) - ->method('setUserValue') - ->withConsecutive( - ['becka', 'news', 'showAll', '1'], - ['becka', 'news', 'compact', '1'], - ['becka', 'news', 'preventReadOnScroll', '0'], - ['becka', 'news', 'oldestFirst', '1'], - ['becka', 'news', 'compactExpand', '1'] - ); + $this->config->expects($this->exactly(5)) + ->method('setUserValue') + ->withConsecutive( + ['becka', 'news', 'showAll', '1'], + ['becka', 'news', 'compact', '1'], + ['becka', 'news', 'preventReadOnScroll', '0'], + ['becka', 'news', 'oldestFirst', '1'], + ['becka', 'news', 'compactExpand', '1'] + ); $this->controller->updateSettings(true, true, false, true, true); } @@ -260,17 +272,17 @@ public function testUpdateSettings() public function testExplore() { $in = ['test']; - $this->settings->expects($this->exactly(2)) - ->method('setUserValue') - ->withConsecutive( - ['becka', 'news', 'lastViewedFeedId', 0], - ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] - ); + $this->config->expects($this->exactly(2)) + ->method('setUserValue') + ->withConsecutive( + ['becka', 'news', 'lastViewedFeedId', 0], + ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] + ); $this->recommended->expects($this->once()) - ->method('forLanguage') - ->with('en') - ->will($this->returnValue($in)); + ->method('forLanguage') + ->with('en') + ->will($this->returnValue($in)); $out = $this->controller->explore('en'); @@ -280,17 +292,17 @@ public function testExplore() public function testExploreError() { - $this->settings->expects($this->exactly(2)) - ->method('setUserValue') - ->withConsecutive( - ['becka', 'news', 'lastViewedFeedId', 0], - ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] - ); + $this->config->expects($this->exactly(2)) + ->method('setUserValue') + ->withConsecutive( + ['becka', 'news', 'lastViewedFeedId', 0], + ['becka', 'news', 'lastViewedFeedType', ListType::EXPLORE] + ); $this->recommended->expects($this->once()) - ->method('forLanguage') - ->with('nl') - ->will($this->throwException(new RecommendedSiteNotFoundException('error'))); + ->method('forLanguage') + ->with('nl') + ->will($this->throwException(new RecommendedSiteNotFoundException('error'))); $out = $this->controller->explore('nl'); diff --git a/tests/Unit/Controller/UtilityApiControllerTest.php b/tests/Unit/Controller/UtilityApiControllerTest.php index 16d583b71e..4271831ae7 100644 --- a/tests/Unit/Controller/UtilityApiControllerTest.php +++ b/tests/Unit/Controller/UtilityApiControllerTest.php @@ -18,7 +18,7 @@ use OCA\News\Controller\UtilityApiController; use OCA\News\Service\StatusService; use OCA\News\Service\UpdaterService; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; @@ -29,7 +29,7 @@ class UtilityApiControllerTest extends TestCase { /** - * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + * @var \PHPUnit\Framework\MockObject\MockObject|IAppConfig */ private $settings; @@ -71,7 +71,7 @@ class UtilityApiControllerTest extends TestCase protected function setUp(): void { $this->appName = 'news'; - $this->settings = $this->getMockBuilder(IConfig::class) + $this->settings = $this->getMockBuilder(IAppConfig::class) ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder(IRequest::class) @@ -105,12 +105,9 @@ protected function setUp(): void public function testGetVersion() { $this->settings->expects($this->once()) - ->method('getAppValue') - ->with( - $this->equalTo($this->appName), - $this->equalTo('installed_version') - ) - ->will($this->returnValue('1.0')); + ->method('getValueString') + ->with($this->appName, 'installed_version') + ->willReturn('1.0'); $response = $this->newsAPI->version(); $version = $response['version']; diff --git a/tests/Unit/Search/ItemSearchProviderTest.php b/tests/Unit/Search/ItemSearchProviderTest.php index c50e32a593..78f369efa7 100644 --- a/tests/Unit/Search/ItemSearchProviderTest.php +++ b/tests/Unit/Search/ItemSearchProviderTest.php @@ -9,6 +9,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\Search\ISearchQuery; +use OCP\Search\IFilter; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -86,10 +87,13 @@ public function testSearch() $query = $this->getMockBuilder(ISearchQuery::class) ->getMock(); + $term = $this->getMockBuilder(IFilter::class) + ->getMock(); + $query->expects($this->once()) ->method('getCursor') ->willReturn(null); - + $query->expects($this->once()) ->method('getLimit') ->willReturn(10); @@ -99,8 +103,13 @@ public function testSearch() ->willReturn('user'); $query->expects($this->once()) - ->method('getTerm') - ->willReturn('some text'); + ->method('getFilter') + ->with('term') + ->willReturn($term); + + $term->expects($this->once()) + ->method('get') + ->willReturn('some text'); $items = [ diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index bcc367f0cf..21131f7418 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.php @@ -17,10 +17,8 @@ use FeedIo\Explorer; use FeedIo\Reader\ReadErrorException; -use OC\L10N\L10N; use OCA\News\Db\FeedMapperV2; use OCA\News\Fetcher\FeedFetcher; -use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\FeedServiceV2; use OCA\News\Service\ItemServiceV2; @@ -29,8 +27,6 @@ use OCA\News\Db\Feed; use OCA\News\Db\Item; -use OCP\IConfig; -use OCP\IL10N; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -72,11 +68,6 @@ class FeedServiceTest extends TestCase */ private $purifier; - /** - * @var \PHPUnit\Framework\MockObject\MockObject|L10N - */ - private $l10n; - /** * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface */ @@ -99,9 +90,7 @@ protected function setUp(): void $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->l10n = $this->getMockBuilder(IL10N::class) - ->disableOriginalConstructor() - ->getMock(); + $this->mapper = $this ->getMockBuilder(FeedMapperV2::class) ->disableOriginalConstructor() @@ -122,9 +111,6 @@ protected function setUp(): void ->getMockBuilder(\HTMLPurifier::class) ->disableOriginalConstructor() ->getMock(); - $config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); $this->class = new FeedServiceV2( $this->mapper, diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 3e47c6136d..0d3ef8053a 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -90,7 +90,7 @@ protected function setUp(): void $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); - $this->class = new FolderServiceV2($this->mapper, $this->feedService, $timeFactory, $this->logger); + $this->class = new FolderServiceV2($this->mapper, $this->logger, $this->feedService, $timeFactory); } public function testFindAll() diff --git a/tests/Unit/Service/ImportServiceTest.php b/tests/Unit/Service/ImportServiceTest.php index 2a6a7b106f..a37b905617 100644 --- a/tests/Unit/Service/ImportServiceTest.php +++ b/tests/Unit/Service/ImportServiceTest.php @@ -14,24 +14,12 @@ namespace OCA\News\Tests\Unit\Service; -use FeedIo\Explorer; -use FeedIo\Reader\ReadErrorException; - -use OC\L10N\L10N; -use OCA\News\Db\FeedMapperV2; -use OCA\News\Fetcher\FeedFetcher; -use OCA\News\Service\Exceptions\ServiceConflictException; -use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\FeedServiceV2; use OCA\News\Service\ImportService; use OCA\News\Service\ItemServiceV2; -use OCA\News\Utility\Time; -use OCP\AppFramework\Db\DoesNotExistException; use OCA\News\Db\Feed; use OCA\News\Db\Item; -use OCP\IConfig; -use OCP\IL10N; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 17a67674c9..35dfb2076e 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -23,7 +23,7 @@ use \OCA\News\Db\Item; use \OCA\News\Db\ListType; use OCP\AppFramework\Db\MultipleObjectsReturnedException; -use OCP\IConfig; +use OCP\IAppConfig; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -47,7 +47,7 @@ class ItemServiceTest extends TestCase private $class; /** - * @var MockObject|IConfig + * @var MockObject|IAppConfig */ private $config; @@ -70,7 +70,7 @@ protected function setUp(): void $this->mapper = $this->getMockBuilder(ItemMapperV2::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(IConfig::class) + $this->config = $this->getMockBuilder(IAppConfig::class) ->disableOriginalConstructor() ->getMock(); @@ -80,8 +80,8 @@ protected function setUp(): void $this->class = new ItemServiceV2( $this->mapper, - $this->config, - $this->logger + $this->logger, + $this->config ); $this->user = 'jack'; $this->id = 3; @@ -605,28 +605,33 @@ public function testPurgeOverThresholdWithNegative() public function testPurgeOverThresholdNull() { - $this->config->expects($this->exactly(2)) - ->method('getAppValue') - ->withConsecutive(['news', 'autoPurgeCount', 200], ['news', 'purgeUnread', false]) - ->willReturnOnConsecutiveCalls(200, false); - + $this->config->expects($this->exactly(1)) + ->method('getValueInt') + ->with('news', 'autoPurgeCount', 200) + ->willReturn(200); + + $this->config->expects($this->exactly(1)) + ->method('getValueBool') + ->with('news', 'purgeUnread', false) + ->willReturn(false); + $this->mapper->expects($this->once()) - ->method('deleteOverThreshold') - ->with(200, false); + ->method('deleteOverThreshold') + ->with(200, false); $this->class->purgeOverThreshold(); } public function testPurgeOverThresholdSet() { - $this->config->expects($this->once()) - ->method('getAppValue') - ->with('news', 'purgeUnread', false) - ->will($this->returnValue(false)); + $this->config->expects($this->exactly(1)) + ->method('getValueBool') + ->with('news', 'purgeUnread', false) + ->willReturn(false); $this->mapper->expects($this->once()) - ->method('deleteOverThreshold') - ->with(5); + ->method('deleteOverThreshold') + ->with(5); $this->class->purgeOverThreshold(5); } diff --git a/tests/Unit/Service/OPMLServiceTest.php b/tests/Unit/Service/OPMLServiceTest.php index 6f117c0662..35529f3705 100644 --- a/tests/Unit/Service/OPMLServiceTest.php +++ b/tests/Unit/Service/OPMLServiceTest.php @@ -14,31 +14,15 @@ namespace OCA\News\Tests\Unit\Service; -use FeedIo\Explorer; -use FeedIo\Reader\ReadErrorException; - -use OC\L10N\L10N; -use OCA\News\Db\FeedMapperV2; use OCA\News\Db\Folder; -use OCA\News\Fetcher\FeedFetcher; -use OCA\News\Service\Exceptions\ServiceConflictException; -use OCA\News\Service\Exceptions\ServiceNotFoundException; use OCA\News\Service\FeedServiceV2; use OCA\News\Service\FolderServiceV2; -use OCA\News\Service\ImportService; -use OCA\News\Service\ItemServiceV2; use OCA\News\Service\OpmlService; use OCA\News\Utility\OPMLExporter; -use OCA\News\Utility\Time; -use OCP\AppFramework\Db\DoesNotExistException; use OCA\News\Db\Feed; -use OCA\News\Db\Item; -use OCP\IConfig; -use OCP\IL10N; use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; class OPMLServiceTest extends TestCase diff --git a/tests/Unit/Service/ShareServiceTest.php b/tests/Unit/Service/ShareServiceTest.php index d7c26a9181..164f972d21 100644 --- a/tests/Unit/Service/ShareServiceTest.php +++ b/tests/Unit/Service/ShareServiceTest.php @@ -11,24 +11,16 @@ namespace OCA\News\Tests\Unit\Service; -use FeedIo\Explorer; -use FeedIo\Reader\ReadErrorException; - -use OC\L10N\L10N; -use OCA\News\Service\Exceptions\ServiceConflictException; use OCA\News\Service\Exceptions\ServiceNotFoundException; -use OCP\AppFramework\Db\DoesNotExistException; use OCA\News\Service\FeedServiceV2; use OCA\News\Service\ItemServiceV2; use OCA\News\Service\ShareService; -use OCA\News\Utility\Time; use OCA\News\Db\Feed; use OCA\News\Db\Item; use OCP\IURLGenerator; use OCP\IUserManager; -use OCP\IConfig; use OCP\IL10N; use OCP\IUser; diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php index fdfe41af5c..c83f62aef8 100644 --- a/tests/Unit/Service/StatusServiceTest.php +++ b/tests/Unit/Service/StatusServiceTest.php @@ -14,7 +14,7 @@ namespace OCA\News\Tests\Unit\Service; use OCA\News\Service\StatusService; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IDBConnection; use OCP\BackgroundJob\IJobList; use PHPUnit\Framework\MockObject\MockObject; @@ -24,7 +24,7 @@ class StatusServiceTest extends TestCase { /** - * @var MockObject|IConfig + * @var MockObject|IAppConfig */ private $settings; @@ -46,7 +46,7 @@ class StatusServiceTest extends TestCase public function setUp(): void { - $this->settings = $this->getMockBuilder(IConfig::class) + $this->settings = $this->getMockBuilder(IAppConfig::class) ->disableOriginalConstructor() ->getMock(); $this->connection = $this->getMockBuilder(IDBConnection::class) @@ -60,19 +60,19 @@ public function setUp(): void public function testGetStatus() { - $this->settings->expects($this->exactly(3)) - ->method('getAppValue') - ->withConsecutive( - ['news', 'installed_version'], - ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] - ) + $this->settings->expects($this->exactly(2)) + ->method('getValueString') ->will($this->returnValueMap([ ['news', 'installed_version', '', '1.0'], ['core', 'backgroundjobs_mode', '', 'cron'], - ['news', 'useCronUpdates', true, true], ])); + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $this->connection->expects($this->exactly(1)) ->method('supports4ByteText') ->will($this->returnValue(true)); @@ -90,19 +90,27 @@ public function testGetStatus() public function testGetStatusNoCorrectCronAjax() { - $this->settings->expects($this->exactly(3)) - ->method('getAppValue') + $this->settings->expects($this->exactly(2)) + ->method('getValueString') ->withConsecutive( ['news', 'installed_version'], ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] ) ->will($this->returnValueMap([ ['news', 'installed_version', '', '1.0'], ['core', 'backgroundjobs_mode', '', 'ajax'], - ['news', 'useCronUpdates', true, true], ])); + + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->withConsecutive( + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $this->connection->expects($this->exactly(1)) ->method('supports4ByteText') ->will($this->returnValue(true)); @@ -120,19 +128,27 @@ public function testGetStatusNoCorrectCronAjax() public function testGetStatusNoCorrectCronTurnedOff() { - $this->settings->expects($this->exactly(3)) - ->method('getAppValue') + $this->settings->expects($this->exactly(2)) + ->method('getValueString') ->withConsecutive( ['news', 'installed_version'], ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] ) ->will($this->returnValueMap([ ['news', 'installed_version', '', '1.0'], ['core', 'backgroundjobs_mode', '', 'ajax'], - ['news', 'useCronUpdates', true, false], ])); + + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->withConsecutive( + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $this->connection->expects($this->exactly(1)) ->method('supports4ByteText') ->will($this->returnValue(true)); @@ -150,19 +166,27 @@ public function testGetStatusNoCorrectCronTurnedOff() public function testGetStatusReportsNon4ByteText() { - $this->settings->expects($this->exactly(3)) - ->method('getAppValue') + $this->settings->expects($this->exactly(2)) + ->method('getValueString') ->withConsecutive( ['news', 'installed_version'], ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] ) ->will($this->returnValueMap([ ['news', 'installed_version', '', '1.0'], ['core', 'backgroundjobs_mode', '', 'ajax'], - ['news', 'useCronUpdates', true, false], ])); + + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->withConsecutive( + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $this->connection->expects($this->exactly(1)) ->method('supports4ByteText') ->will($this->returnValue(false)); @@ -180,53 +204,81 @@ public function testGetStatusReportsNon4ByteText() public function testIsProperlyConfiguredNone() { - $this->settings->expects($this->exactly(2)) - ->method('getAppValue') + $this->settings->expects($this->exactly(1)) + ->method('getValueString') ->withConsecutive( ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] ) ->will($this->returnValueMap([ ['core', 'backgroundjobs_mode', '', 'ajax'], - ['news', 'useCronUpdates', true, true], ])); + + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->withConsecutive( + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $response = $this->service->isCronProperlyConfigured(); $this->assertFalse($response); } public function testIsProperlyConfiguredModeCronNoSystem() { - $this->settings->expects($this->exactly(2)) - ->method('getAppValue') + $this->settings->expects($this->exactly(1)) + ->method('getValueString') ->withConsecutive( + ['news', 'installed_version'], ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] ) ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], ['core', 'backgroundjobs_mode', '', 'cron'], - ['news', 'useCronUpdates', true, false], ])); + + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->withConsecutive( + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $response = $this->service->isCronProperlyConfigured(); $this->assertTrue($response); } public function testIsProperlyConfiguredModeCron() { - $this->settings->expects($this->exactly(2)) - ->method('getAppValue') + $this->settings->expects($this->exactly(1)) + ->method('getValueString') ->withConsecutive( + ['news', 'installed_version'], ['core', 'backgroundjobs_mode'], - ['news', 'useCronUpdates'] ) ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], ['core', 'backgroundjobs_mode', '', 'cron'], - ['news', 'useCronUpdates', true, false], ])); + + $this->settings->expects($this->exactly(1)) + ->method('getValueBool') + ->withConsecutive( + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'useCronUpdates', true, true], + ])); + $response = $this->service->isCronProperlyConfigured(); $this->assertTrue($response); } -} \ No newline at end of file +}