From 077e75065076a86c89d6facf14cd112360e76d2a Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 11 Jun 2024 16:20:37 +0200 Subject: [PATCH] feat: lift min PHP version and NC Signed-off-by: Sean Molenaar --- .github/workflows/api-integration-tests.yml | 8 +- .../workflows/api-php-static-code-check.yml | 6 +- .github/workflows/api-php-tests.yml | 8 +- .github/workflows/build-release.yml | 4 +- .github/workflows/frontend-nodejs-tests.yml | 4 +- .github/workflows/post-merge-tasks.yml | 8 +- .github/workflows/updater-test.yml | 6 +- CHANGELOG.md | 3 +- appinfo/info.xml | 4 +- composer.json | 2 +- lib/Command/Updater/Job.php | 36 +---- lib/Config/FetcherConfig.php | 21 +-- lib/Controller/PageController.php | 54 ++----- lib/Controller/UtilityApiController.php | 17 +-- lib/Cron/UpdaterJob.php | 30 +--- lib/Search/FeedSearchProvider.php | 21 +-- lib/Search/FolderSearchProvider.php | 3 +- lib/Service/FolderServiceV2.php | 17 +-- lib/Service/ItemServiceV2.php | 22 +-- lib/Service/StatusService.php | 34 ++--- lib/Settings/AdminSettings.php | 29 ++-- lib/Utility/Cache.php | 2 +- tests/Unit/Config/FetcherConfigTest.php | 19 ++- tests/Unit/Controller/PageControllerTest.php | 140 ++++++++++-------- .../Controller/UtilityApiControllerTest.php | 15 +- tests/Unit/Search/FeedSearchProviderTest.php | 7 +- tests/Unit/Search/ItemSearchProviderTest.php | 15 +- tests/Unit/Service/FeedServiceTest.php | 16 +- tests/Unit/Service/FolderServiceTest.php | 2 +- tests/Unit/Service/ImportServiceTest.php | 12 -- tests/Unit/Service/ItemServiceTest.php | 41 ++--- tests/Unit/Service/OPMLServiceTest.php | 16 -- tests/Unit/Service/ShareServiceTest.php | 8 - tests/Unit/Service/StatusServiceTest.php | 122 ++++++++++----- 34 files changed, 335 insertions(+), 417 deletions(-) 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 b33075c12c..129a9a0b67 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/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 a65e43cb4a..aff7f826dc 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'); @@ -279,17 +291,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 99b9a93e06..dc40449eb8 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/FeedSearchProviderTest.php b/tests/Unit/Search/FeedSearchProviderTest.php index 7b67cfdbcf..c566615bcb 100644 --- a/tests/Unit/Search/FeedSearchProviderTest.php +++ b/tests/Unit/Search/FeedSearchProviderTest.php @@ -103,10 +103,9 @@ public function testSearch() ->with('user') ->willReturn($folders); - $this->l10n->expects($this->exactly(2)) - ->method('t') - ->withConsecutive(['Unread articles'], ['News']) - ->willReturnArgument(0); + $this->l10n->expects($this->atLeast(2)) + ->method('t') + ->willReturnArgument(0); $this->generator->expects($this->once()) ->method('imagePath') diff --git a/tests/Unit/Search/ItemSearchProviderTest.php b/tests/Unit/Search/ItemSearchProviderTest.php index 1086ae0d9e..f5614cb30f 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 f981aeefd5..ca899be5ea 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; @@ -71,11 +67,6 @@ class FeedServiceTest extends TestCase */ private $purifier; - /** - * @var \PHPUnit\Framework\MockObject\MockObject|L10N - */ - private $l10n; - /** * @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface */ @@ -98,9 +89,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() @@ -121,9 +110,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 7c96312fac..6701d0be93 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -89,7 +89,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 c4e7a4338a..dae535a301 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 eee0af85d6..e6c9ac38b7 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 4e95264d5f..41bbbeef09 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 145595bbcf..3a488f2e2c 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 287d5ce6d0..c3317bf6a4 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; @@ -23,7 +23,7 @@ class StatusServiceTest extends TestCase { /** - * @var MockObject|IConfig + * @var MockObject|IAppConfig */ private $settings; @@ -45,7 +45,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) @@ -59,19 +59,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)); @@ -89,19 +89,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)); @@ -119,19 +127,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)); @@ -149,19 +165,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)); @@ -179,51 +203,79 @@ 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); }