diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index b48d2ac79e..14244ab2a9 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -28,8 +28,8 @@ jobs: - 5432:5432 # Maps tcp port 5432 on service container to the host strategy: matrix: - php-versions: ['7.2', '7.3', '7.4'] - nextcloud: ['17', '18', '19'] + php-versions: ['7.3', '7.4'] + nextcloud: ['20'] database: ['sqlite', 'pgsql', 'mysql'] experimental: [false] include: diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index 79a26d4374..004514978d 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: php-versions: ['7.4'] - nextcloud: ['19'] + nextcloud: ['20'] database: ['sqlite'] experimental: [false] steps: diff --git a/.travis.yml b/.travis.yml index 3680e17502..74c58fc977 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ php: env: global: - MOZ_HEADLESS=1 - - CORE_BRANCH=stable19 DB=sqlite + - CORE_BRANCH=stable20 DB=sqlite before_install: - make diff --git a/AUTHORS.md b/AUTHORS.md index ea686cb5a0..187c491c49 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -8,8 +8,8 @@ * [Sean Molenaar](mailto:SMillerDev@users.noreply.github.com) * [Jan-Christoph Borchardt](mailto:hey@jancborchardt.net) * [Daniel Schaal](mailto:daniel@schaal.email) -* [Davide Saurino](mailto:davide.saurino@alcacoop.it) * [Sean Molenaar](mailto:sean@seanmolenaar.eu) +* [Davide Saurino](mailto:davide.saurino@alcacoop.it) * [raghunayyar](mailto:me@iraghu.com) * [bastei](mailto:bastei@users.noreply.github.com) * [Bernhard Posselt](mailto:bep@foryouandyourcustomers.com) @@ -81,6 +81,7 @@ * [DriverXX](mailto:DriverXX@users.noreply.github.com) * [DriverXX](mailto:thegio.f@gmail.com) * [DudleyDursley](mailto:35841630+DudleyDursley@users.noreply.github.com) +* [Felix](mailto:22506886+felurx@users.noreply.github.com) * [Felix](mailto:eppfel@users.noreply.github.com) * [Felix Bartels](mailto:felix@host-consultants.de) * [Florian Hülsmann](mailto:fh@cbix.de) diff --git a/appinfo/info.xml b/appinfo/info.xml index dc09c50f7b..a9eb039f5e 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -37,7 +37,7 @@ Before you update to a new version, [check the changelog](https://github.com/nex SimpleXML iconv - + @@ -47,6 +47,7 @@ Before you update to a new version, [check the changelog](https://github.com/nex OCA\News\Migration\MigrateStatusFlags + OCA\News\Migration\MigrateConfig diff --git a/composer.json b/composer.json index 26654a69c6..25d0db9082 100644 --- a/composer.json +++ b/composer.json @@ -42,10 +42,10 @@ }, "require": { "php": "^7.2", - "ezyang/htmlpurifier": "4.12.0", + "ezyang/htmlpurifier": "^4.13.0", "pear/net_url2": "2.2.2", "riimu/kit-pathjoin": "1.2.0", - "debril/feed-io": "^4.5", + "debril/feed-io": "^v4.7.8", "arthurhoaro/favicon": "^1.2", "ext-json": "*", "ext-simplexml": "*", @@ -53,11 +53,11 @@ "andreskrey/readability.php": "^2.1" }, "require-dev": { - "phpunit/phpunit": "^7.5", - "squizlabs/php_codesniffer": "^3.4", + "phpunit/phpunit": "9.2.6", + "squizlabs/php_codesniffer": "^3.5.6", "guzzlehttp/guzzle": "^6.3", - "symfony/service-contracts": "1.1.8", - "phpstan/phpstan": "^0.12.38" + "symfony/service-contracts": "2.2.0", + "phpstan/phpstan": "^0.12.43" }, "replace": { "guzzlehttp/guzzle": "*", diff --git a/composer.lock b/composer.lock index 6e091a9ca1..7b31b1ac99 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": "bc8a010805b2f925d3c58ddc19b728e8", + "content-hash": "d026de8b34993e486d928ef4c509676d", "packages": [ { "name": "andreskrey/readability.php", @@ -111,16 +111,16 @@ }, { "name": "debril/feed-io", - "version": "v4.7.8", + "version": "v4.7.9", "source": { "type": "git", "url": "https://github.com/alexdebril/feed-io.git", - "reference": "2fe979f7e288fff334deaa0ddeaa1f229632ab6e" + "reference": "3fbc023b52d7b97fed7e7ab0dd9a83fb9c556414" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alexdebril/feed-io/zipball/2fe979f7e288fff334deaa0ddeaa1f229632ab6e", - "reference": "2fe979f7e288fff334deaa0ddeaa1f229632ab6e", + "url": "https://api.github.com/repos/alexdebril/feed-io/zipball/3fbc023b52d7b97fed7e7ab0dd9a83fb9c556414", + "reference": "3fbc023b52d7b97fed7e7ab0dd9a83fb9c556414", "shasum": "" }, "require": { @@ -174,20 +174,20 @@ "type": "github" } ], - "time": "2020-08-17T13:46:18+00:00" + "time": "2020-09-21T08:29:55+00:00" }, { "name": "ezyang/htmlpurifier", - "version": "v4.12.0", + "version": "v4.13.0", "source": { "type": "git", "url": "https://github.com/ezyang/htmlpurifier.git", - "reference": "a617e55bc62a87eec73bd456d146d134ad716f03" + "reference": "08e27c97e4c6ed02f37c5b2b20488046c8d90d75" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/a617e55bc62a87eec73bd456d146d134ad716f03", - "reference": "a617e55bc62a87eec73bd456d146d134ad716f03", + "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/08e27c97e4c6ed02f37c5b2b20488046c8d90d75", + "reference": "08e27c97e4c6ed02f37c5b2b20488046c8d90d75", "shasum": "" }, "require": { @@ -203,6 +203,9 @@ }, "files": [ "library/HTMLPurifier.composer.php" + ], + "exclude-from-classmap": [ + "/library/HTMLPurifier/Language/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -221,7 +224,7 @@ "keywords": [ "html" ], - "time": "2019-10-28T03:44:26+00:00" + "time": "2020-06-29T00:56:53+00:00" }, { "name": "pear/net_url2", @@ -663,16 +666,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.2.1", + "version": "5.2.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44" + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d870572532cd70bc3fab58f2e23ad423c8404c44", - "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", "shasum": "" }, "require": { @@ -711,20 +714,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-08-15T11:14:08+00:00" + "time": "2020-09-03T19:13:55+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651" + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651", - "reference": "e878a14a65245fbe78f8080eba03b47c3b705651", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", "shasum": "" }, "require": { @@ -756,7 +759,7 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-06-27T10:12:23+00:00" + "time": "2020-09-17T18:55:26+00:00" }, { "name": "phpspec/prophecy", @@ -823,16 +826,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.42", + "version": "0.12.44", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "7c43b7c2d5ca6554f6231e82e342a710163ac5f4" + "reference": "330b45776ea77f167b150e24787412414a8fa469" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7c43b7c2d5ca6554f6231e82e342a710163ac5f4", - "reference": "7c43b7c2d5ca6554f6231e82e342a710163ac5f4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/330b45776ea77f167b150e24787412414a8fa469", + "reference": "330b45776ea77f167b150e24787412414a8fa469", "shasum": "" }, "require": { @@ -875,44 +878,45 @@ "type": "tidelift" } ], - "time": "2020-09-02T13:14:53+00:00" + "time": "2020-09-24T15:28:47+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "6.1.4", + "version": "8.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" + "reference": "ca6647ffddd2add025ab3f21644a441d7c146cdc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca6647ffddd2add025ab3f21644a441d7c146cdc", + "reference": "ca6647ffddd2add025ab3f21644a441d7c146cdc", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.1", - "phpunit/php-file-iterator": "^2.0", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0", - "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.1 || ^4.0", - "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" + "php": "^7.3", + "phpunit/php-file-iterator": "^3.0", + "phpunit/php-text-template": "^2.0", + "phpunit/php-token-stream": "^4.0", + "sebastian/code-unit-reverse-lookup": "^2.0", + "sebastian/environment": "^5.0", + "sebastian/version": "^3.0", + "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "suggest": { - "ext-xdebug": "^2.6.0" + "ext-pcov": "*", + "ext-xdebug": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.1-dev" + "dev-master": "8.0-dev" } }, "autoload": { @@ -938,32 +942,38 @@ "testing", "xunit" ], - "time": "2018-10-31T16:06:48+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-05-23T08:02:54+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "2.0.2", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "050bedf145a257b1ff02746c31894800e5122946" + "reference": "25fefc5b19835ca653877fe081644a3f8c1d915e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", - "reference": "050bedf145a257b1ff02746c31894800e5122946", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/25fefc5b19835ca653877fe081644a3f8c1d915e", + "reference": "25fefc5b19835ca653877fe081644a3f8c1d915e", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -988,26 +998,99 @@ "filesystem", "iterator" ], - "time": "2018-09-13T20:33:42+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-07-11T05:18:21+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "7a85b66acc48cacffdf87dadd3694e7123674298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/7a85b66acc48cacffdf87dadd3694e7123674298", + "reference": "7a85b66acc48cacffdf87dadd3694e7123674298", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-08-06T07:04:15+00:00" }, { "name": "phpunit/php-text-template", - "version": "1.2.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + "reference": "6ff9c8ea4d3212b88fcf74e25e516e2c51c99324" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/6ff9c8ea4d3212b88fcf74e25e516e2c51c99324", + "reference": "6ff9c8ea4d3212b88fcf74e25e516e2c51c99324", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -1029,32 +1112,38 @@ "keywords": [ "template" ], - "time": "2015-06-21T13:50:34+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T11:55:37+00:00" }, { "name": "phpunit/php-timer", - "version": "2.1.2", + "version": "5.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" + "reference": "cc49734779cbb302bf51a44297dab8c4bbf941e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/cc49734779cbb302bf51a44297dab8c4bbf941e7", + "reference": "cc49734779cbb302bf51a44297dab8c4bbf941e7", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -1078,33 +1167,39 @@ "keywords": [ "timer" ], - "time": "2019-06-07T04:22:29+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T11:58:13+00:00" }, { "name": "phpunit/php-token-stream", - "version": "3.1.1", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" + "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/a853a0e183b9db7eed023d7933a858fa1c8d25a3", + "reference": "a853a0e183b9db7eed023d7933a858fa1c8d25a3", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.1" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1127,58 +1222,65 @@ "keywords": [ "tokenizer" ], + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], "abandoned": true, - "time": "2019-09-17T06:23:10+00:00" + "time": "2020-08-04T08:28:15+00:00" }, { "name": "phpunit/phpunit", - "version": "7.5.20", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "9467db479d1b0487c99733bb1e7944d32deded2c" + "reference": "1c6a9e4312e209e659f1fce3ce88dd197c2448f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9467db479d1b0487c99733bb1e7944d32deded2c", - "reference": "9467db479d1b0487c99733bb1e7944d32deded2c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c6a9e4312e209e659f1fce3ce88dd197c2448f6", + "reference": "1c6a9e4312e209e659f1fce3ce88dd197c2448f6", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.1", + "doctrine/instantiator": "^1.3.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.7", - "phar-io/manifest": "^1.0.2", - "phar-io/version": "^2.0", - "php": "^7.1", - "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.7", - "phpunit/php-file-iterator": "^2.0.1", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1", - "sebastian/comparator": "^3.0", - "sebastian/diff": "^3.0", - "sebastian/environment": "^4.0", - "sebastian/exporter": "^3.1", - "sebastian/global-state": "^2.0", - "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0", - "sebastian/version": "^2.0.1" - }, - "conflict": { - "phpunit/phpunit-mock-objects": "*" + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.9.5", + "phar-io/manifest": "^1.0.3", + "phar-io/version": "^2.0.1", + "php": "^7.3", + "phpspec/prophecy": "^1.10.3", + "phpunit/php-code-coverage": "^8.0.2", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-invoker": "^3.0.2", + "phpunit/php-text-template": "^2.0.2", + "phpunit/php-timer": "^5.0.1", + "sebastian/code-unit": "^1.0.5", + "sebastian/comparator": "^4.0.3", + "sebastian/diff": "^4.0.1", + "sebastian/environment": "^5.1.2", + "sebastian/exporter": "^4.0.2", + "sebastian/global-state": "^4.0", + "sebastian/object-enumerator": "^4.0.2", + "sebastian/resource-operations": "^3.0.2", + "sebastian/type": "^2.1.1", + "sebastian/version": "^3.0.1" }, "require-dev": { - "ext-pdo": "*" + "ext-pdo": "*", + "phpspec/prophecy-phpunit": "^2.0" }, "suggest": { "ext-soap": "*", - "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0" + "ext-xdebug": "*" }, "bin": [ "phpunit" @@ -1186,12 +1288,15 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.5-dev" + "dev-master": "9.2-dev" } }, "autoload": { "classmap": [ "src/" + ], + "files": [ + "src/Framework/Assert/Functions.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1212,7 +1317,17 @@ "testing", "xunit" ], - "time": "2020-01-08T08:45:45+00:00" + "funding": [ + { + "url": "https://phpunit.de/donate.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-07-13T17:55:55+00:00" }, { "name": "psr/container", @@ -1263,30 +1378,82 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "sebastian/code-unit", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "c1e2df332c905079980b119c4db103117e5e5c90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/c1e2df332c905079980b119c4db103117e5e5c90", + "reference": "c1e2df332c905079980b119c4db103117e5e5c90", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:50:45+00:00" + }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + "reference": "ee51f9bb0c6d8a43337055db3120829fa14da819" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ee51f9bb0c6d8a43337055db3120829fa14da819", + "reference": "ee51f9bb0c6d8a43337055db3120829fa14da819", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1306,34 +1473,40 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:04:00+00:00" }, { "name": "sebastian/comparator", - "version": "3.0.2", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + "reference": "dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f", + "reference": "dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f", "shasum": "" }, "require": { - "php": "^7.1", - "sebastian/diff": "^3.0", - "sebastian/exporter": "^3.1" + "php": "^7.3 || ^8.0", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1346,6 +1519,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -1357,10 +1534,6 @@ { "name": "Bernhard Schussek", "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" } ], "description": "Provides the functionality to compare PHP values for equality", @@ -1370,33 +1543,39 @@ "compare", "equality" ], - "time": "2018-07-12T15:12:46+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:05:46+00:00" }, { "name": "sebastian/diff", - "version": "3.0.2", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + "reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113", + "reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "symfony/process": "^2 || ^3.3 || ^4" + "phpunit/phpunit": "^9.0", + "symfony/process": "^4.2 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1409,13 +1588,13 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" } ], "description": "Diff implementation", @@ -1426,27 +1605,33 @@ "unidiff", "unified diff" ], - "time": "2019-02-04T06:01:07+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-30T04:46:02+00:00" }, { "name": "sebastian/environment", - "version": "4.2.3", + "version": "5.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" + "reference": "0a757cab9d5b7ef49a619f1143e6c9c1bc0fe9d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0a757cab9d5b7ef49a619f1143e6c9c1bc0fe9d2", + "reference": "0a757cab9d5b7ef49a619f1143e6c9c1bc0fe9d2", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^9.0" }, "suggest": { "ext-posix": "*" @@ -1454,7 +1639,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -1479,34 +1664,40 @@ "environment", "hhvm" ], - "time": "2019-11-20T08:46:58+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:07:24+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.2", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + "reference": "571d721db4aec847a0e59690b954af33ebf9f023" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/571d721db4aec847a0e59690b954af33ebf9f023", + "reference": "571d721db4aec847a0e59690b954af33ebf9f023", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/recursion-context": "^3.0" + "php": "^7.3 || ^8.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1546,27 +1737,36 @@ "export", "exporter" ], - "time": "2019-09-14T09:02:43+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:08:55+00:00" }, { "name": "sebastian/global-state", - "version": "2.0.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bdb1e7c79e592b8c82cb1699be3c8743119b8a72", + "reference": "bdb1e7c79e592b8c82cb1699be3c8743119b8a72", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "ext-dom": "*", + "phpunit/phpunit": "^9.0" }, "suggest": { "ext-uopz": "*" @@ -1574,7 +1774,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1597,34 +1797,34 @@ "keywords": [ "global state" ], - "time": "2017-04-27T15:39:26+00:00" + "time": "2020-02-07T06:11:37+00:00" }, { "name": "sebastian/object-enumerator", - "version": "3.0.3", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + "reference": "074fed2d0a6d08e1677dd8ce9d32aecb384917b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/074fed2d0a6d08e1677dd8ce9d32aecb384917b8", + "reference": "074fed2d0a6d08e1677dd8ce9d32aecb384917b8", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" + "php": "^7.3 || ^8.0", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1644,32 +1844,38 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03T12:35:26+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:11:32+00:00" }, { "name": "sebastian/object-reflector", - "version": "1.1.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "773f97c67f28de00d397be301821b06708fca0be" + "reference": "127a46f6b057441b201253526f81d5406d6c7840" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", - "reference": "773f97c67f28de00d397be301821b06708fca0be", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/127a46f6b057441b201253526f81d5406d6c7840", + "reference": "127a46f6b057441b201253526f81d5406d6c7840", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1689,32 +1895,38 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29T09:07:27+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:12:55+00:00" }, { "name": "sebastian/recursion-context", - "version": "3.0.0", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + "reference": "062231bf61d2b9448c4fa5a7643b5e1829c11d63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/062231bf61d2b9448c4fa5a7643b5e1829c11d63", + "reference": "062231bf61d2b9448c4fa5a7643b5e1829c11d63", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1727,14 +1939,14 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, { "name": "Adam Harvey", "email": "aharvey@php.net" @@ -1742,29 +1954,38 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03T06:23:57+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:14:17+00:00" }, { "name": "sebastian/resource-operations", - "version": "2.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + "reference": "0653718a5a629b065e91f774595267f8dc32e213" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0653718a5a629b065e91f774595267f8dc32e213", + "reference": "0653718a5a629b065e91f774595267f8dc32e213", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1784,29 +2005,87 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2018-10-04T04:07:39+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:16:22+00:00" + }, + { + "name": "sebastian/type", + "version": "2.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "86991e2b33446cd96e648c18bcdb1e95afb2c05a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/86991e2b33446cd96e648c18bcdb1e95afb2c05a", + "reference": "86991e2b33446cd96e648c18bcdb1e95afb2c05a", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-07-05T08:31:53+00:00" }, { "name": "sebastian/version", - "version": "2.0.1", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + "reference": "626586115d0ed31cb71483be55beb759b5af5a3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/626586115d0ed31cb71483be55beb759b5af5a3c", + "reference": "626586115d0ed31cb71483be55beb759b5af5a3c", "shasum": "" }, "require": { - "php": ">=5.6" + "php": "^7.3 || ^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1827,7 +2106,13 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:18:43+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -1958,20 +2243,20 @@ }, { "name": "symfony/service-contracts", - "version": "v1.1.8", + "version": "v2.2.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "ffc7f5692092df31515df2a5ecf3b7302b3ddacf" + "reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/ffc7f5692092df31515df2a5ecf3b7302b3ddacf", - "reference": "ffc7f5692092df31515df2a5ecf3b7302b3ddacf", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/d15da7ba4957ffb8f1747218be9e1a121fd298a1", + "reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1", "shasum": "" }, "require": { - "php": "^7.1.3", + "php": ">=7.2.5", "psr/container": "^1.0" }, "suggest": { @@ -1980,7 +2265,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "2.2-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -2012,7 +2301,21 @@ "interoperability", "standards" ], - "time": "2019-10-14T12:27:06+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-09-07T11:33:47+00:00" }, { "name": "theseer/tokenizer", diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b0d2d1e4f7..005a264a46 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -18,28 +18,32 @@ use HTMLPurifier_Config; use Favicon\Favicon; +use OC\Encryption\Update; +use OCA\News\Config\LegacyConfig; use OCA\News\Config\FetcherConfig; +use OCA\News\Db\FolderMapper; +use OCA\News\Service\FeedService; +use OCA\News\Service\FolderService; +use OCA\News\Service\ItemService; use OCA\News\Utility\PsrLogger; -use OCP\BackgroundJob\IJobList; +use OCA\News\Utility\Updater; use OCP\IContainer; -use OCP\INavigationManager; -use OCP\IURLGenerator; use OCP\IConfig; +use OCP\ILogger; use OCP\ITempManager; use OCP\AppFramework\App; use OCP\Files\IRootFolder; use OCP\Files\Node; -use OCA\News\Config\AppConfig; -use OCA\News\Config\Config; use OCA\News\Db\MapperFactory; use OCA\News\Db\ItemMapper; use OCA\News\Fetcher\FeedFetcher; use OCA\News\Fetcher\Fetcher; use OCA\News\Fetcher\YoutubeFetcher; use OCA\News\Scraper\Scraper; +use Psr\Log\LoggerInterface; /** * Class Application @@ -49,6 +53,24 @@ class Application extends App { + /** + * App Name + */ + public const NAME = 'news'; + + /** + * List of default settings + */ + public const DEFAULT_SETTINGS = [ + 'autoPurgeMinimumInterval' => 60, + 'autoPurgeCount' => 200, + 'maxRedirects' => 10, + 'feedFetcherTimeout' => 60, + 'useCronUpdates' => true, + 'exploreUrl' => '', + 'updateInterval' => 3600, + ]; + /** * Application constructor. * @@ -56,7 +78,7 @@ class Application extends App */ public function __construct(array $urlParams = []) { - parent::__construct('news', $urlParams); + parent::__construct(self::NAME, $urlParams); $container = $this->getContainer(); @@ -77,20 +99,6 @@ public function __construct(array $urlParams = []) return $c->query(MapperFactory::class)->build(); }); - /** - * App config parser. - */ - $container->registerService(AppConfig::class, function (IContainer $c): AppConfig { - $config = new AppConfig( - $c->query(INavigationManager::class), - $c->query(IURLGenerator::class), - $c->query(IJobList::class) - ); - - $config->loadConfig($c->query('info')); - return $config; - }); - /** * Core */ @@ -98,38 +106,24 @@ public function __construct(array $urlParams = []) return ['app' => $c->query('AppName')]; }); - $container->registerService('databaseType', function (IContainer $c) { - return $c->query(IConfig::class)->getSystemValue('dbtype'); - }); - - $container->registerService('ConfigView', function (IContainer $c): Node { + $container->registerService('ConfigView', function (IContainer $c): ?Node { /** @var IRootFolder $fs */ $fs = $c->query(IRootFolder::class); $path = 'news/config'; if ($fs->nodeExists($path)) { return $fs->get($path); } else { - return $fs->newFolder($path); + return null; } }); - /** - * Logger base - */ - $container->registerService(PsrLogger::class, function (IContainer $c): PsrLogger { - return new PsrLogger( - $c->query('ServerContainer')->getLogger(), - $c->query('AppName') - ); - }); - - $container->registerService(Config::class, function (IContainer $c): Config { - $config = new Config( + $container->registerService(LegacyConfig::class, function (IContainer $c): LegacyConfig { + $config = new LegacyConfig( $c->query('ConfigView'), - $c->query(PsrLogger::class), + $c->query(LoggerInterface::class), $c->query('LoggerParameters') ); - $config->read($c->query('configFile'), true); + $config->read($c->query('configFile'), false); return $config; }); @@ -175,7 +169,7 @@ public function __construct(array $urlParams = []) */ $container->registerService(FetcherConfig::class, function (IContainer $c): FetcherConfig { $fConfig = new FetcherConfig(); - $fConfig->setConfig($c->query(Config::class)) + $fConfig->setConfig($c->query(IConfig::class)) ->setProxy($c->query(IConfig::class)); return $fConfig; @@ -183,7 +177,7 @@ public function __construct(array $urlParams = []) $container->registerService(FeedIo::class, function (IContainer $c): FeedIo { $config = $c->query(FetcherConfig::class); - return new FeedIo($config->getClient(), $c->query(PsrLogger::class)); + return new FeedIo($config->getClient(), $c->query(LoggerInterface::class)); }); $container->registerService(Favicon::class, function (IContainer $c): Favicon { @@ -209,7 +203,7 @@ public function __construct(array $urlParams = []) */ $container->registerService(Scraper::class, function (IContainer $c): Scraper { return new Scraper( - $c->query(PsrLogger::class) + $c->query(LoggerInterface::class) ); }); } diff --git a/lib/Command/ShowFeed.php b/lib/Command/ShowFeed.php index 572b68e26f..878b711231 100644 --- a/lib/Command/ShowFeed.php +++ b/lib/Command/ShowFeed.php @@ -13,7 +13,15 @@ use FeedIo\FeedIo; use Favicon\Favicon; +use HTMLPurifier; +use OCA\News\Db\FeedMapper; +use OCA\News\Db\ItemMapper; use OCA\News\Fetcher\Fetcher; +use OCA\News\Service\FeedService; +use OCA\News\Utility\Time; +use OCP\IConfig; +use OCP\IL10N; +use OCP\ILogger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; @@ -38,8 +46,8 @@ class ShowFeed extends Command */ public function __construct(Fetcher $feedFetcher) { - $this->feedFetcher = $feedFetcher; parent::__construct(); + $this->feedFetcher = $feedFetcher; } protected function configure() diff --git a/lib/Config/Config.php b/lib/Config/Config.php deleted file mode 100644 index 97099db48c..0000000000 --- a/lib/Config/Config.php +++ /dev/null @@ -1,207 +0,0 @@ - - * @author Bernhard Posselt - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - */ - -namespace OCA\News\Config; - -use OCA\News\Utility\PsrLogger; -use OCP\Files\Folder; - -class Config -{ - - private $fileSystem; - private $autoPurgeMinimumInterval; // seconds, used to define how - // long deleted folders and feeds - // should still be kept for an - // undo actions - private $autoPurgeCount; // number of allowed unread articles per feed - private $maxRedirects; // seconds - private $feedFetcherTimeout; // seconds - private $useCronUpdates; // turn off updates run by the cron - private $logger; - private $loggerParams; - private $maxSize; - private $exploreUrl; - private $updateInterval; - - public function __construct( - Folder $fileSystem, - PsrLogger $logger, - $LoggerParameters - ) { - $this->fileSystem = $fileSystem; - $this->autoPurgeMinimumInterval = 60; - $this->autoPurgeCount = 200; - $this->maxRedirects = 10; - $this->maxSize = 100 * 1024 * 1024; // 100Mb - $this->feedFetcherTimeout = 60; - $this->useCronUpdates = true; - $this->logger = $logger; - $this->exploreUrl = ''; - $this->loggerParams = $LoggerParameters; - $this->updateInterval = 3600; - } - - public function getAutoPurgeMinimumInterval() - { - if ($this->autoPurgeMinimumInterval > 60) { - return $this->autoPurgeMinimumInterval; - } else { - return 60; - } - } - - public function getAutoPurgeCount() - { - return $this->autoPurgeCount; - } - - - public function getMaxRedirects() - { - return $this->maxRedirects; - } - - - public function getFeedFetcherTimeout() - { - return $this->feedFetcherTimeout; - } - - - public function getUseCronUpdates() - { - return $this->useCronUpdates; - } - - - public function getMaxSize() - { - return $this->maxSize; - } - - - public function getExploreUrl() - { - return $this->exploreUrl; - } - - public function getUpdateInterval() - { - return $this->updateInterval; - } - - public function setAutoPurgeMinimumInterval($value) - { - $this->autoPurgeMinimumInterval = $value; - } - - - public function setAutoPurgeCount($value) - { - $this->autoPurgeCount = $value; - } - - - public function setMaxRedirects($value) - { - $this->maxRedirects = $value; - } - - - public function setFeedFetcherTimeout($value) - { - $this->feedFetcherTimeout = $value; - } - - - public function setUseCronUpdates($value) - { - $this->useCronUpdates = $value; - } - - public function setMaxSize($value) - { - $this->maxSize = $value; - } - - - public function setExploreUrl($value) - { - $this->exploreUrl = $value; - } - - public function setUpdateInterval($value) - { - $this->updateInterval = $value; - } - - - - public function read($configPath, $createIfNotExists = false) - { - if ($createIfNotExists && !$this->fileSystem->nodeExists($configPath)) { - $this->fileSystem->newFile($configPath); - $this->write($configPath); - } else { - $content = $this->fileSystem->get($configPath)->getContent(); - $configValues = parse_ini_string($content); - - if ($configValues === false || count($configValues) === 0) { - $this->logger->warning( - 'Configuration invalid. Ignoring values.', - $this->loggerParams - ); - } else { - foreach ($configValues as $key => $value) { - if (property_exists($this, $key)) { - $type = gettype($this->$key); - settype($value, $type); - $this->$key = $value; - } else { - $this->logger->warning( - 'Configuration value "' . $key . - '" does not exist. Ignored value.', - $this->loggerParams - ); - } - } - } - } - } - - - public function write($configPath) - { - $ini = - 'autoPurgeMinimumInterval = ' . - $this->autoPurgeMinimumInterval . "\n" . - 'autoPurgeCount = ' . - $this->autoPurgeCount . "\n" . - 'maxRedirects = ' . - $this->maxRedirects . "\n" . - 'maxSize = ' . - $this->maxSize . "\n" . - 'exploreUrl = ' . - $this->exploreUrl . "\n" . - 'feedFetcherTimeout = ' . - $this->feedFetcherTimeout . "\n" . - 'updateInterval = ' . - $this->updateInterval . "\n" . - 'useCronUpdates = ' . - var_export($this->useCronUpdates, true); - ; - - $this->fileSystem->get($configPath)->putContent($ini); - } -} diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index 866f9a4f17..1e9b7941e0 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -15,6 +15,7 @@ use FeedIo\Adapter\ClientInterface; use \GuzzleHttp\Client; +use OCA\News\AppInfo\Application; use OCA\News\Fetcher\Client\FeedIoClient; use OCA\News\Fetcher\Client\LegacyGuzzleClient; use OCP\IConfig; @@ -44,13 +45,6 @@ class FetcherConfig */ protected $redirects; - /** - * Max size of the recieved data. - * @deprecated guzzle can't handle this - * @var string - */ - protected $max_size; - /** * User agent for the client. * @var string @@ -96,8 +90,7 @@ private function getConfig() $config['redirect.max'] = $this->redirects; } - $guzzle = new Client($config); - return $guzzle; + return new Client($config); } /** @@ -121,22 +114,28 @@ private function getOldConfig() $config['request.options']['redirect.max'] = $this->redirects; } - $guzzle = new Client($config); - return $guzzle; + return new Client($config); } /** * Set settings for config. * - * @param Config $config The shared configuration + * @param IConfig $config The shared configuration * * @return self */ - public function setConfig(Config $config) + public function setConfig(IConfig $config) { - $this->client_timeout = $config->getFeedFetcherTimeout(); - $this->redirects = $config->getMaxRedirects(); - $this->max_size = $config->getMaxSize(); + $this->client_timeout = $config->getAppValue( + Application::NAME, + 'feedFetcherTimeout', + Application::DEFAULT_SETTINGS['feedFetcherTimeout'] + ); + $this->redirects = $config->getAppValue( + Application::NAME, + 'maxRedirects', + Application::DEFAULT_SETTINGS['maxRedirects'] + ); return $this; } diff --git a/lib/Config/LegacyConfig.php b/lib/Config/LegacyConfig.php new file mode 100644 index 0000000000..71e19acfa8 --- /dev/null +++ b/lib/Config/LegacyConfig.php @@ -0,0 +1,87 @@ + + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt + */ + +namespace OCA\News\Config; + +use OCA\News\AppInfo\Application; +use OCA\News\Utility\PsrLogger; +use OCP\Files\Folder; +use OCP\IConfig; +use Psr\Log\LoggerInterface; + +class LegacyConfig +{ + + private $fileSystem; + public $autoPurgeMinimumInterval; // seconds, used to define how + // long deleted folders and feeds + // should still be kept for an + // undo actions + public $autoPurgeCount; // number of allowed unread articles per feed + public $maxRedirects; // seconds + public $feedFetcherTimeout; // seconds + public $useCronUpdates; // turn off updates run by the cron + public $logger; + public $loggerParams; + public $maxSize; + public $exploreUrl; + public $updateInterval; + + public function __construct( + ?Folder $fileSystem, + LoggerInterface $logger, + $LoggerParameters + ) { + $this->fileSystem = $fileSystem; + $this->autoPurgeMinimumInterval = 60; + $this->autoPurgeCount = 200; + $this->maxRedirects = 10; + $this->maxSize = 100 * 1024 * 1024; // 100Mb + $this->feedFetcherTimeout = 60; + $this->useCronUpdates = true; + $this->logger = $logger; + $this->exploreUrl = ''; + $this->loggerParams = $LoggerParameters; + $this->updateInterval = 3600; + } + + public function read($configPath, $createIfNotExists = false) + { + if ($this->fileSystem === null) { + return; + } + $content = $this->fileSystem->get($configPath)->getContent(); + $configValues = parse_ini_string($content); + + if ($configValues === false || count($configValues) === 0) { + $this->logger->warning( + 'Configuration invalid. Ignoring values.', + $this->loggerParams + ); + } else { + foreach ($configValues as $key => $value) { + if (property_exists($this, $key)) { + $type = gettype($this->$key); + settype($value, $type); + $this->$key = $value; + } else { + $this->logger->warning( + 'Configuration value "' . $key . + '" does not exist. Ignored value.', + $this->loggerParams + ); + } + } + } + } +} diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index c5a4765776..addc535917 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -14,11 +14,12 @@ namespace OCA\News\Controller; +use OCA\News\AppInfo\Application; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; use OCP\IRequest; use OCP\AppFramework\Controller; -use OCA\News\Config\Config; use OCA\News\Service\ItemService; /** @@ -28,8 +29,15 @@ */ class AdminController extends Controller { + + /** + * @var IConfig + */ private $config; - private $configPath; + + /** + * @var ItemService + */ private $itemService; /** @@ -37,20 +45,17 @@ class AdminController extends Controller * * @param string $appName The name of the app * @param IRequest $request The request - * @param Config $config Config for nextcloud + * @param IConfig $config Config for nextcloud * @param ItemService $itemService Service for items - * @param string $configFile Path to the config */ public function __construct( - $appName, + string $appName, IRequest $request, - Config $config, - ItemService $itemService, - $configFile + IConfig $config, + ItemService $itemService ) { parent::__construct($appName, $request); $this->config = $config; - $this->configPath = $configFile; $this->itemService = $itemService; } @@ -64,20 +69,23 @@ public function __construct( */ public function index() { - $data = [ - 'autoPurgeMinimumInterval' => - $this->config->getAutoPurgeMinimumInterval(), - 'autoPurgeCount' => $this->config->getAutoPurgeCount(), - 'maxRedirects' => $this->config->getMaxRedirects(), - 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), - 'useCronUpdates' => $this->config->getUseCronUpdates(), - 'maxSize' => $this->config->getMaxSize(), - 'exploreUrl' => $this->config->getExploreUrl(), - 'updateInterval' => $this->config->getupdateInterval(), - ]; - return new TemplateResponse($this->appName, 'admin', $data, 'blank'); + return new TemplateResponse($this->appName, 'admin', $this->getData(), 'blank'); } + private function getData() + { + $data = []; + + foreach (array_keys(Application::DEFAULT_SETTINGS) as $setting) { + $data[$setting] = $this->config->getAppValue( + Application::NAME, + $setting, + Application::DEFAULT_SETTINGS[$setting] + ); + } + + return $data; + } /** * Update the app config. @@ -86,7 +94,6 @@ public function index() * @param int $autoPurgeCount New value of auto-purge count * @param int $maxRedirects New value for max amount of redirects * @param int $feedFetcherTimeout New timeout value for feed fetcher - * @param int $maxSize New max feed size * @param bool $useCronUpdates Whether or not to use cron updates * @param string $exploreUrl URL to use for the explore feed * @param int $updateInterval Interval in which the feeds will be updated @@ -94,35 +101,22 @@ public function index() * @return array with the updated values */ public function update( - $autoPurgeMinimumInterval, - $autoPurgeCount, - $maxRedirects, - $feedFetcherTimeout, - $maxSize, - $useCronUpdates, - $exploreUrl, - $updateInterval + int $autoPurgeMinimumInterval, + int $autoPurgeCount, + int $maxRedirects, + int $feedFetcherTimeout, + bool $useCronUpdates, + string $exploreUrl, + int $updateInterval ) { - $this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval); - $this->config->setAutoPurgeCount($autoPurgeCount); - $this->config->setMaxRedirects($maxRedirects); - $this->config->setMaxSize($maxSize); - $this->config->setFeedFetcherTimeout($feedFetcherTimeout); - $this->config->setUseCronUpdates($useCronUpdates); - $this->config->setExploreUrl($exploreUrl); - $this->config->setUpdateInterval($updateInterval); - $this->config->write($this->configPath); + $this->config->setAppValue($this->appName, 'autoPurgeMinimumInterval', $autoPurgeMinimumInterval); + $this->config->setAppValue($this->appName, 'autoPurgeCount', $autoPurgeCount); + $this->config->setAppValue($this->appName, 'maxRedirects', $maxRedirects); + $this->config->setAppValue($this->appName, 'feedFetcherTimeout', $feedFetcherTimeout); + $this->config->setAppValue($this->appName, 'useCronUpdates', $useCronUpdates); + $this->config->setAppValue($this->appName, 'exploreUrl', $exploreUrl); + $this->config->setAppValue($this->appName, 'updateInterval', $updateInterval); - return [ - 'autoPurgeMinimumInterval' => - $this->config->getAutoPurgeMinimumInterval(), - 'autoPurgeCount' => $this->config->getAutoPurgeCount(), - 'maxRedirects' => $this->config->getMaxRedirects(), - 'maxSize' => $this->config->getMaxSize(), - 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), - 'useCronUpdates' => $this->config->getUseCronUpdates(), - 'exploreUrl' => $this->config->getExploreUrl(), - 'updateInterval' => $this->config->getUpdateInterval(), - ]; + return $this->getData(); } } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 6ae01811dd..d88f8181d2 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -13,6 +13,7 @@ namespace OCA\News\Controller; +use OCA\News\AppInfo\Application; use OCP\IRequest; use OCP\IConfig; use OCP\IL10N; @@ -24,7 +25,6 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCA\News\Service\StatusService; -use OCA\News\Config\Config; use OCA\News\Explore\RecommendedSites; use OCA\News\Explore\RecommendedSiteNotFoundException; use OCA\News\Db\FeedType; @@ -33,32 +33,51 @@ class PageController extends Controller { use JSONHttpError; + /** + * @var IConfig + */ private $settings; + + /** + * @var IL10N + */ private $l10n; + + /** + * @var string + */ private $userId; + + /** + * @var IURLGenerator + */ private $urlGenerator; - private $config; + + /** + * @var RecommendedSites + */ private $recommendedSites; + /** + * @var StatusService + */ private $statusService; public function __construct( - $appName, + string $appName, IRequest $request, IConfig $settings, IURLGenerator $urlGenerator, - Config $config, IL10N $l10n, RecommendedSites $recommendedSites, StatusService $statusService, - $UserId + string $UserId ) { parent::__construct($appName, $request); $this->settings = $settings; $this->urlGenerator = $urlGenerator; $this->l10n = $l10n; $this->userId = $UserId; - $this->config = $config; $this->recommendedSites = $recommendedSites; $this->statusService = $statusService; } @@ -109,7 +128,11 @@ public function settings() 'compactExpand' ]; - $exploreUrl = $this->config->getExploreUrl(); + $exploreUrl = $this->settings->getAppValue( + $this->appName, + 'exploreUrl', + Application::DEFAULT_SETTINGS['exploreUrl'] + ); if (trim($exploreUrl) === '') { // default url should not feature the sites.en.json $exploreUrl = $this->urlGenerator->linkToRoute( @@ -142,28 +165,25 @@ public function settings() * @param bool $compact * @param bool $preventReadOnScroll * @param bool $oldestFirst + * @param bool $compactExpand */ public function updateSettings( - $showAll, - $compact, - $preventReadOnScroll, - $oldestFirst, - $compactExpand + bool $showAll, + bool $compact, + bool $preventReadOnScroll, + bool $oldestFirst, + bool $compactExpand ) { $settings = [ - 'showAll', - 'compact', - 'preventReadOnScroll', - 'oldestFirst', - 'compactExpand' + 'showAll' => $showAll, + 'compact' => $compact, + 'preventReadOnScroll' => $preventReadOnScroll, + 'oldestFirst' => $oldestFirst, + 'compactExpand' => $compactExpand, ]; - foreach ($settings as $setting) { - if (${$setting}) { - $value = '1'; - } else { - $value = '0'; - } + foreach ($settings as $setting => $value) { + $value = $value ? '1' : '0'; $this->settings->setUserValue( $this->userId, $this->appName, @@ -178,7 +198,7 @@ public function updateSettings( * * @param string $lang */ - public function explore($lang) + public function explore(string $lang) { $this->settings->setUserValue( $this->userId, diff --git a/lib/Cron/Updater.php b/lib/Cron/Updater.php index a33d7e7c10..3d9336df70 100644 --- a/lib/Cron/Updater.php +++ b/lib/Cron/Updater.php @@ -13,15 +13,16 @@ use OC\BackgroundJob\TimedJob; -use OCA\News\Config\Config; +use OCA\News\AppInfo\Application; use OCA\News\Service\StatusService; use OCA\News\Utility\Updater as UpdaterService; +use OCP\IConfig; class Updater extends TimedJob { /** - * @var Config + * @var IConfig */ private $config; /** @@ -34,7 +35,7 @@ class Updater extends TimedJob private $updaterService; public function __construct( - Config $config, + IConfig $config, StatusService $status, UpdaterService $updaterService ) { @@ -42,14 +43,24 @@ public function __construct( $this->status = $status; $this->updaterService = $updaterService; - parent::setInterval($this->config->getUpdateInterval()); + $interval = $this->config->getAppValue( + Application::NAME, + 'updateInterval', + Application::DEFAULT_SETTINGS['updateInterval'] + ); + + parent::setInterval($interval); } protected function run($argument) { - if ($this->config->getUseCronUpdates() - && $this->status->isProperlyConfigured() - ) { + $uses_cron = $this->config->getAppValue( + Application::NAME, + 'useCronUpdates', + Application::DEFAULT_SETTINGS['useCronUpdates'] + ); + + if ($uses_cron && $this->status->isProperlyConfigured()) { $this->updaterService->beforeUpdate(); $this->updaterService->update(); $this->updaterService->afterUpdate(); diff --git a/lib/Db/ItemMapper.php b/lib/Db/ItemMapper.php index f0442aee97..2e08471db4 100644 --- a/lib/Db/ItemMapper.php +++ b/lib/Db/ItemMapper.php @@ -357,20 +357,27 @@ public function deleteReadOlderThanThreshold($threshold) while ($row = $result->fetch()) { $size = (int)$row['size']; $limit = $size - $threshold; + $feed_id = $row['feed_id']; if ($limit > 0) { - $params = [false, false, $row['feed_id'], $limit]; - - $sql = 'DELETE FROM `*PREFIX*news_items` ' . - 'WHERE `id` IN (' . - 'SELECT `id` FROM `*PREFIX*news_items` ' . + $params = [false, false, $feed_id, $limit]; + $sql = 'SELECT `id` FROM `*PREFIX*news_items` ' . 'WHERE `unread` = ? ' . 'AND `starred` = ? ' . 'AND `feed_id` = ? ' . 'ORDER BY `id` ASC ' . - 'LIMIT ?' . - ')'; - + 'LIMIT 1 ' . + 'OFFSET ? '; + } + $limit_result = $this->execute($sql, $params); + if ($limit_row = $limit_result->fetch()) { + $limit_id = (int)$limit_row['id']; + $params = [false, false, $feed_id, $limit_id]; + $sql = 'DELETE FROM `*PREFIX*news_items` ' . + 'WHERE `unread` = ? ' . + 'AND `starred` = ? ' . + 'AND `feed_id` = ? ' . + 'AND `id` < ? '; $this->execute($sql, $params); } } diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index c06b81b52e..99d3d90ab3 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -27,6 +27,7 @@ use OCA\News\Db\Feed; use OCA\News\Utility\Time; use OCA\News\Scraper\Scraper; +use Psr\Log\LoggerInterface; use SimpleXMLElement; class FeedFetcher implements IFeedFetcher @@ -44,7 +45,7 @@ public function __construct( Favicon $favicon, IL10N $l10n, Time $time, - PsrLogger $logger, + LoggerInterface $logger, Scraper $scraper ) { $this->reader = $fetcher; diff --git a/lib/Migration/MigrateConfig.php b/lib/Migration/MigrateConfig.php new file mode 100644 index 0000000000..b25fb8e75d --- /dev/null +++ b/lib/Migration/MigrateConfig.php @@ -0,0 +1,59 @@ + 2020 + */ + +namespace OCA\News\Migration; + +use OCA\News\AppInfo\Application; +use OCA\News\Config\LegacyConfig; +use OCP\IConfig; +use OCP\Migration\IRepairStep; +use OCP\Migration\IOutput; + +class MigrateConfig implements IRepairStep +{ + + /** + * @var LegacyConfig + */ + private $config; + + /** + * @var IConfig + */ + private $iConfig; + + /** + * @param LegacyConfig $config + * @param IConfig $iConfig + */ + public function __construct(LegacyConfig $config, IConfig $iConfig) + { + $this->config = $config; + $this->iConfig = $iConfig; + } + + public function getName() + { + return 'Migrate config to nextcloud managed config'; + } + + public function run(IOutput $output) + { + $version = $this->iConfig->getAppValue('news', 'installed_version', '0.0.0'); + if (version_compare($version, '15.0.0', '>')) { + return; + } + + foreach ($this->config as $key => $value) { + $this->iConfig->setAppValue(Application::NAME, $key, $value); + } + } +} diff --git a/lib/Scraper/Scraper.php b/lib/Scraper/Scraper.php index a99416c63e..65a1387993 100644 --- a/lib/Scraper/Scraper.php +++ b/lib/Scraper/Scraper.php @@ -11,11 +11,10 @@ namespace OCA\News\Scraper; -use OCA\News\Utility\PsrLogger; - use andreskrey\Readability\Readability; use andreskrey\Readability\Configuration; use andreskrey\Readability\ParseException; +use Psr\Log\LoggerInterface; class Scraper implements IScraper { @@ -24,7 +23,7 @@ class Scraper implements IScraper private $readability; private $curl_opts; - public function __construct(PsrLogger $logger) + public function __construct(LoggerInterface $logger) { $this->logger = $logger; $this->config = new Configuration([ diff --git a/lib/Service/FeedService.php b/lib/Service/FeedService.php index aff9626d83..6d57c80277 100644 --- a/lib/Service/FeedService.php +++ b/lib/Service/FeedService.php @@ -16,6 +16,8 @@ use FeedIo\Reader\ReadErrorException; use HTMLPurifier; +use OCA\News\AppInfo\Application; +use OCP\IConfig; use OCP\ILogger; use OCP\IL10N; use OCP\AppFramework\Db\DoesNotExistException; @@ -25,7 +27,6 @@ use OCA\News\Db\FeedMapper; use OCA\News\Db\ItemMapper; use OCA\News\Fetcher\Fetcher; -use OCA\News\Config\Config; use OCA\News\Utility\Time; class FeedService extends Service @@ -48,9 +49,8 @@ public function __construct( ILogger $logger, IL10N $l10n, Time $timeFactory, - Config $config, - HTMLPurifier $purifier, - $LoggerParameters + IConfig $config, + HTMLPurifier $purifier ) { parent::__construct($feedMapper); $this->feedFetcher = $feedFetcher; @@ -58,11 +58,14 @@ public function __construct( $this->logger = $logger; $this->l10n = $l10n; $this->timeFactory = $timeFactory; - $this->autoPurgeMinimumInterval = $config->getAutoPurgeMinimumInterval( + $this->autoPurgeMinimumInterval = $config->getAppValue( + Application::NAME, + 'autoPurgeMinimumInterval', + Application::DEFAULT_SETTINGS['autoPurgeMinimumInterval'] ); $this->purifier = $purifier; $this->feedMapper = $feedMapper; - $this->loggerParams = $LoggerParameters; + $this->loggerParams = ['app' => Application::NAME]; } /** diff --git a/lib/Service/FolderService.php b/lib/Service/FolderService.php index 9ba6b35e29..35eb77f958 100644 --- a/lib/Service/FolderService.php +++ b/lib/Service/FolderService.php @@ -13,10 +13,11 @@ namespace OCA\News\Service; +use OCA\News\AppInfo\Application; +use OCP\IConfig; use OCP\IL10N; use OCA\News\Db\Folder; use OCA\News\Db\FolderMapper; -use OCA\News\Config\Config; use OCA\News\Utility\Time; class FolderService extends Service @@ -31,13 +32,16 @@ public function __construct( FolderMapper $folderMapper, IL10N $l10n, Time $timeFactory, - Config $config + IConfig $config ) { parent::__construct($folderMapper); $this->l10n = $l10n; $this->timeFactory = $timeFactory; - $this->autoPurgeMinimumInterval = - $config->getAutoPurgeMinimumInterval(); + $this->autoPurgeMinimumInterval = $config->getAppValue( + Application::NAME, + 'autoPurgeMinimumInterval', + Application::DEFAULT_SETTINGS['autoPurgeMinimumInterval'] + ); $this->folderMapper = $folderMapper; } @@ -91,6 +95,7 @@ public function create($folderName, $userId, $parentId = 0) $folder->setUserId($userId); $folder->setParentId($parentId); $folder->setOpened(true); + return $this->folderMapper->insert($folder); } @@ -123,6 +128,7 @@ public function rename($folderId, $folderName, $userId) $folder = $this->find($folderId, $userId); $folder->setName($folderName); + return $this->folderMapper->update($folder); } @@ -160,7 +166,7 @@ public function unmarkDeleted($folderId, $userId) /** * Deletes all deleted folders * - * @param string $userId if given it purges only folders of that user + * @param ?string $userId if given it purges only folders of that user * @param boolean $useInterval defaults to true, if true it only purges * entries in a given interval to give the user a chance to undo the * deletion diff --git a/lib/Service/ItemService.php b/lib/Service/ItemService.php index c41217ff6a..5e1660cc0c 100644 --- a/lib/Service/ItemService.php +++ b/lib/Service/ItemService.php @@ -13,13 +13,13 @@ namespace OCA\News\Service; +use OCA\News\AppInfo\Application; use OCA\News\Db\Item; use OCP\IConfig; use OCP\AppFramework\Db\DoesNotExistException; use OCA\News\Db\ItemMapper; use OCA\News\Db\FeedType; -use OCA\News\Config\Config; use OCA\News\Utility\Time; class ItemService extends Service @@ -28,19 +28,16 @@ class ItemService extends Service private $config; private $timeFactory; private $itemMapper; - private $systemConfig; public function __construct( ItemMapper $itemMapper, Time $timeFactory, - Config $config, - IConfig $systemConfig + IConfig $config ) { parent::__construct($itemMapper); - $this->config = $config; $this->timeFactory = $timeFactory; $this->itemMapper = $itemMapper; - $this->systemConfig = $systemConfig; + $this->config = $config; } @@ -255,7 +252,11 @@ public function readFeed($feedId, $highestItemId, $userId) */ public function autoPurgeOld() { - $count = $this->config->getAutoPurgeCount(); + $count = $this->config->getAppValue( + Application::NAME, + 'autoPurgeCount', + Application::DEFAULT_SETTINGS['autoPurgeCount'] + ); if ($count >= 0) { $this->itemMapper->deleteReadOlderThanThreshold($count); } diff --git a/lib/Service/StatusService.php b/lib/Service/StatusService.php index 85be58a5da..f926258b6e 100644 --- a/lib/Service/StatusService.php +++ b/lib/Service/StatusService.php @@ -13,17 +13,14 @@ namespace OCA\News\Service; +use OCA\News\AppInfo\Application; use OCP\IConfig; use OCP\IDBConnection; -use OCA\News\Config\Config; - class StatusService { /** @var IConfig */ private $settings; - /** @var Config */ - private $config; /** @var string */ private $appName; /** @var IDBConnection */ @@ -32,22 +29,21 @@ class StatusService public function __construct( IConfig $settings, IDBConnection $connection, - Config $config, $AppName ) { $this->settings = $settings; - $this->config = $config; $this->appName = $AppName; $this->connection = $connection; } public function isProperlyConfigured() { - $cronMode = $this->settings->getAppValue( - 'core', - 'backgroundjobs_mode' + $cronMode = $this->settings->getSystemValue('backgroundjobs_mode'); + $cronOff = !$this->settings->getAppValue( + Application::NAME, + 'useCronUpdates', + Application::DEFAULT_SETTINGS['useCronUpdates'] ); - $cronOff = !$this->config->getUseCronUpdates(); // check for cron modes which may lead to problems return $cronMode === 'cron' || $cronOff; diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php deleted file mode 100644 index e8c9a0cb2b..0000000000 --- a/lib/Settings/Admin.php +++ /dev/null @@ -1,44 +0,0 @@ -config = $config; - } - - public function getForm() - { - $data = [ - 'autoPurgeMinimumInterval' => - $this->config->getAutoPurgeMinimumInterval(), - 'autoPurgeCount' => $this->config->getAutoPurgeCount(), - 'maxRedirects' => $this->config->getMaxRedirects(), - 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), - 'useCronUpdates' => $this->config->getUseCronUpdates(), - 'maxSize' => $this->config->getMaxSize(), - 'exploreUrl' => $this->config->getExploreUrl(), - 'updateInterval' => $this->config->getUpdateInterval(), - ]; - return new TemplateResponse('news', 'admin', $data, ''); - } - - public function getSection() - { - return 'news'; - } - - public function getPriority() - { - return 40; - } -} diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php new file mode 100644 index 0000000000..1f3d98c089 --- /dev/null +++ b/lib/Settings/AdminSettings.php @@ -0,0 +1,47 @@ +config = $config; + } + + public function getForm() + { + $data = []; + + foreach (array_keys(Application::DEFAULT_SETTINGS) as $setting) { + $data[$setting] = $this->config->getAppValue( + Application::NAME, + $setting, + Application::DEFAULT_SETTINGS[$setting] + ); + } + + return new TemplateResponse(Application::NAME, 'admin', $data); + } + + public function getSection() + { + return 'news'; + } + + public function getPriority() + { + return 40; + } +} diff --git a/lib/Utility/PsrLogger.php b/lib/Utility/PsrLogger.php deleted file mode 100644 index 5d9a2529bf..0000000000 --- a/lib/Utility/PsrLogger.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @copyright 2018 Sean Molenaar - */ - -namespace OCA\News\Utility; - -use \OCP\ILogger; - -/** - * This is a wrapper to make OC\Log conform to Psr\Log\LoggerInterface - * - * @package OCA\News\Utility - */ -class PsrLogger implements \Psr\Log\LoggerInterface -{ - private $logger; - private $appName; - - /** - * PsrLogger constructor. - * - * @param ILogger $logger The logger - * @param string $appName Name of the app - */ - public function __construct(ILogger $logger, $appName) - { - $this->logger = $logger; - $this->appName = $appName; - } - - public function logException($exception, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->logException($exception, $context); - } - - public function emergency($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->emergency($message, $context); - } - - public function alert($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->alert($message, $context); - } - - public function critical($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->critical($message, $context); - } - - public function error($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->error($message, $context); - } - - public function warning($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->warning($message, $context); - } - - public function notice($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->notice($message, $context); - } - - public function info($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->info($message, $context); - } - - public function debug($message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->debug($message, $context); - } - - public function log($level, $message, array $context = []) - { - $context['app'] = $this->appName; - $this->logger->log($level, $message, $context); - } -} diff --git a/lib/Utility/Updater.php b/lib/Utility/Updater.php index 02ede9c90d..01e07291b2 100644 --- a/lib/Utility/Updater.php +++ b/lib/Utility/Updater.php @@ -21,9 +21,19 @@ class Updater { - + /** + * @var FolderService + */ private $folderService; + + /** + * @var FeedService + */ private $feedService; + + /** + * @var ItemService + */ private $itemService; public function __construct( diff --git a/templates/admin.php b/templates/admin.php index 56bbd20672..fa714f463d 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -70,23 +70,6 @@ - - - - t('Maximum feed page size')); ?> - - - - - t( - 'Maximum feed size in bytes. If the RSS/Atom page is ' . - 'bigger than this value, the update will be aborted.' - )); ?> - - - - diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index 3d1ea71f4f..626b8f9a99 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -20,7 +20,7 @@ class FeedMapperTest extends IntegrationTest { - public function testFind() + public function testFind() { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -31,16 +31,14 @@ public function testFind() $this->assertEquals($feed->getLink(), $fetched->getLink()); } - /** - * @expectedException OCP\AppFramework\Db\DoesNotExistException - */ - public function testFindNotExisting() + public function testFindNotExisting() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->feedMapper->find(0, $this->user); } - public function testFindAll() + public function testFindAll() { $feeds = [ [ @@ -56,23 +54,23 @@ public function testFindAll() $fetched = $this->feedMapper->findAll(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testFindAllEmpty() + public function testFindAllEmpty() { $feeds = $this->feedMapper->findAll(); - $this->assertInternalType('array', $feeds); + $this->assertIsArray($feeds); $this->assertCount(0, $feeds); } - public function testFindAllFromUser() + public function testFindAllFromUser() { $feeds = [ [ @@ -88,7 +86,7 @@ public function testFindAllFromUser() $fetched = $this->feedMapper->findAllFromUser($this->user); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(1, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); @@ -96,16 +94,16 @@ public function testFindAllFromUser() } - public function testFindAllFromUserNotExisting() + public function testFindAllFromUserNotExisting() { $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(0, $fetched); } - public function testFindByUrlHash() + public function testFindByUrlHash() { $feed = new FeedFixture( [ @@ -124,8 +122,9 @@ public function testFindByUrlHash() /** * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException */ - public function testFindByUrlHashMoreThanOneResult() + public function testFindByUrlHashMoreThanOneResult() { + $this->expectException('OCP\AppFramework\Db\MultipleObjectsReturnedException'); $feed1 = $this->feedMapper->insert( new FeedFixture( [ @@ -148,13 +147,14 @@ public function testFindByUrlHashMoreThanOneResult() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindByUrlHashNotExisting() + public function testFindByUrlHashNotExisting() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->feedMapper->findByUrlHash('some random hash', $this->user); } - public function testDelete() + public function testDelete() { $this->loadFixtures('default'); @@ -178,7 +178,7 @@ public function testDelete() $this->assertCount(0, $items); } - public function testGetToDelete() + public function testGetToDelete() { $this->loadFeedFixtures( [ @@ -191,14 +191,14 @@ public function testGetToDelete() $fetched = $this->feedMapper->getToDelete(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(3, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteOlderThan() + public function testGetToDeleteOlderThan() { $this->loadFeedFixtures( [ @@ -211,14 +211,14 @@ public function testGetToDeleteOlderThan() $fetched = $this->feedMapper->getToDelete(1000); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteUser() + public function testGetToDeleteUser() { $this->loadFeedFixtures( [ @@ -231,22 +231,22 @@ public function testGetToDeleteUser() $fetched = $this->feedMapper->getToDelete(2000, $this->user); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteEmpty() + public function testGetToDeleteEmpty() { $fetched = $this->feedMapper->getToDelete(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(0, $fetched); } - public function testDeleteUser() + public function testDeleteUser() { $this->loadFixtures('default'); @@ -263,7 +263,10 @@ public function testDeleteUser() $this->assertCount(0, $items); } - public function testDeleteUserNotExisting() + /** + * @coversNothing + */ + public function testDeleteUserNotExisting() { $this->feedMapper->deleteUser('notexistinguser'); } diff --git a/tests/Integration/Db/FolderMapperTest.php b/tests/Integration/Db/FolderMapperTest.php deleted file mode 100644 index 889ac3e7c1..0000000000 --- a/tests/Integration/Db/FolderMapperTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - -namespace OCA\News\Tests\Integration\Db; - -use OCA\News\Tests\Integration\IntegrationTest; - -class FolderMapperTest extends IntegrationTest -{ - - - public function testFind() - { - - } - - - /* TBD - public function testFindByName () { - - } - - - public function testFindAllFromUser () { - - } - - - public function testDelete () { - - } - - - public function testGetToDelete () { - - } - - - public function testDeleteUser () { - - }*/ - - - -} diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index e510aab964..026834e6b1 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -18,7 +18,7 @@ class ItemMapperTest extends IntegrationTest { - public function testFind() + public function testFind() { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -38,7 +38,7 @@ public function testFind() * @param $title * @return mixed */ - private function whereTitleId($title) + private function whereTitleId($title) { return $this->findItemByTitle($title)->getId(); } @@ -46,8 +46,9 @@ private function whereTitleId($title) /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFeed() + public function testFindNotFoundWhenDeletedFeed() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('not found feed'); @@ -58,8 +59,9 @@ public function testFindNotFoundWhenDeletedFeed() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFolder() + public function testFindNotFoundWhenDeletedFolder() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); @@ -68,7 +70,7 @@ public function testFindNotFoundWhenDeletedFolder() } - private function deleteReadOlderThanThreshold() + private function deleteReadOlderThanThreshold() { $this->loadFixtures('default'); @@ -84,8 +86,9 @@ private function deleteReadOlderThanThreshold() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdOne() + public function testDeleteOlderThanThresholdOne() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('del1'); @@ -97,8 +100,9 @@ public function testDeleteOlderThanThresholdOne() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdTwo() + public function testDeleteOlderThanThresholdTwo() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('del2'); @@ -108,7 +112,7 @@ public function testDeleteOlderThanThresholdTwo() } - public function testStarredCount() + public function testStarredCount() { $this->loadFixtures('default'); @@ -117,7 +121,7 @@ public function testStarredCount() } - public function testReadAll() + public function testReadAll() { $this->loadFixtures('default'); @@ -146,7 +150,7 @@ public function testReadAll() } - public function testReadFolder() + public function testReadFolder() { $this->loadFixtures('default'); @@ -178,7 +182,7 @@ public function testReadFolder() } - public function testReadFeed() + public function testReadFeed() { $this->loadFixtures('default'); @@ -209,7 +213,7 @@ public function testReadFeed() } - public function testDeleteUser() + public function testDeleteUser() { $this->loadFixtures('default'); @@ -219,7 +223,7 @@ public function testDeleteUser() $this->assertEquals(0, $id); } - public function testGetNewestItemId() + public function testGetNewestItemId() { $this->loadFixtures('default'); @@ -229,7 +233,7 @@ public function testGetNewestItemId() $this->assertEquals($itemId, $id); } - public function testFindAllUnreadOrStarred() + public function testFindAllUnreadOrStarred() { $this->loadFixtures('default'); @@ -238,7 +242,7 @@ public function testFindAllUnreadOrStarred() } - public function testReadItem() + public function testReadItem() { $this->loadFixtures('readitem'); // assert that all items are unread @@ -277,7 +281,7 @@ public function testReadItem() } } - public function testUnreadItem() + public function testUnreadItem() { $this->loadFixtures('readitem'); // unread an item diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php deleted file mode 100644 index 60a292afc3..0000000000 --- a/tests/Unit/Config/ConfigTest.php +++ /dev/null @@ -1,261 +0,0 @@ - - * @author Bernhard Posselt - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - */ - -namespace OCA\News\Tests\Unit\Config; - -use OCA\News\Config\Config; -use OCP\Files\File; -use OCP\Files\Folder; -use OCP\ILogger; -use PHPUnit\Framework\TestCase; - -class ConfigTest extends TestCase -{ - - private $fileSystem; - private $config; - private $configPath; - private $loggerParams; - - public function setUp() - { - $this->logger = $this->getMockBuilder('OCA\News\Utility\PsrLogger') - ->disableOriginalConstructor() - ->getMock(); - $this->fileSystem = $this->getMockBuilder(Folder::class)->getMock(); - $this->loggerParams = ['hi']; - $this->config = new Config( - $this->fileSystem, - $this->logger, - $this->loggerParams - ); - $this->configPath = 'config.json'; - } - - - public function testDefaults() - { - $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); - $this->assertEquals(200, $this->config->getAutoPurgeCount()); - $this->assertEquals(10, $this->config->getMaxRedirects()); - $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); - $this->assertEquals(3600, $this->config->getUpdateInterval()); - $this->assertEquals(true, $this->config->getUseCronUpdates()); - $this->assertEquals('', $this->config->getExploreUrl()); - $this->assertEquals(1024*1024*100, $this->config->getMaxSize()); - } - - - public function testRead() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will( - $this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' - ) - ); - - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(true, $this->config->getUseCronUpdates()); - } - - - public function testReadIgnoresVeryLowPurgeInterval() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('autoPurgeMinimumInterval = 59')); - - $this->config->read($this->configPath); - - $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); - } - - - - public function testReadBool() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will( - $this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false' - ) - ); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(false, $this->config->getUseCronUpdates()); - } - - - public function testReadLogsInvalidValue() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('autoPurgeCounts = 3')); - $this->logger->expects($this->once()) - ->method('warning') - ->with( - $this->equalTo( - 'Configuration value "autoPurgeCounts" ' . - 'does not exist. Ignored value.' - ), - $this->equalTo($this->loggerParams) - ); - - $this->config->read($this->configPath); - } - - - public function testReadLogsInvalidINI() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('')); - $this->logger->expects($this->once()) - ->method('warning') - ->with( - $this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams) - ); - - $this->config->read($this->configPath); - } - - - public function testWrite() - { - $json = 'autoPurgeMinimumInterval = 60' . "\n" . - 'autoPurgeCount = 3' . "\n" . - 'maxRedirects = 10' . "\n" . - 'maxSize = 399' . "\n" . - 'exploreUrl = http://google.de' . "\n" . - 'feedFetcherTimeout = 60' . "\n" . - 'updateInterval = 3600' . "\n" . - 'useCronUpdates = true'; - $this->config->setAutoPurgeCount(3); - $this->config->setMaxSize(399); - $this->config->setExploreUrl('http://google.de'); - - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('putContent') - ->with($this->equalTo($json)); - - $this->config->write($this->configPath); - } - - - - public function testReadingNonExistentConfigWillWriteDefaults() - { - $this->fileSystem->expects($this->once()) - ->method('nodeExists') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue(false)); - - $this->config->setUseCronUpdates(false); - - $json = 'autoPurgeMinimumInterval = 60' . "\n" . - 'autoPurgeCount = 200' . "\n" . - 'maxRedirects = 10' . "\n" . - 'maxSize = 104857600' . "\n" . - 'exploreUrl = ' . "\n" . - 'feedFetcherTimeout = 60' . "\n" . - 'updateInterval = 3600' . "\n" . - 'useCronUpdates = false'; - - $this->fileSystem->expects($this->once()) - ->method('newFile') - ->with($this->equalTo($this->configPath)); - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('putContent') - ->with($this->equalTo($json)); - - $this->config->read($this->configPath, true); - } - - - public function testNoLowMinimumAutoPurgeInterval() - { - $this->config->setAutoPurgeMinimumInterval(59); - $interval = $this->config->getAutoPurgeMinimumInterval(); - - $this->assertSame(60, $interval); - } - - - public function testMinimumAutoPurgeInterval() - { - $this->config->setAutoPurgeMinimumInterval(61); - $interval = $this->config->getAutoPurgeMinimumInterval(); - - $this->assertSame(61, $interval); - } - - public function testMaxRedirects() - { - $this->config->setMaxRedirects(21); - $redirects = $this->config->getMaxRedirects(); - - $this->assertSame(21, $redirects); - } - - public function testFeedFetcherTimeout() - { - $this->config->setFeedFetcherTimeout(2); - $timout = $this->config->getFeedFetcherTimeout(); - - $this->assertSame(2, $timout); - } -} diff --git a/tests/Unit/Controller/AdminControllerTest.php b/tests/Unit/Controller/AdminControllerTest.php index b0b5510068..81490bb6fa 100644 --- a/tests/Unit/Controller/AdminControllerTest.php +++ b/tests/Unit/Controller/AdminControllerTest.php @@ -13,82 +13,84 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; use OCA\News\Controller\AdminController; use OCA\News\Service\ItemService; +use OCP\IConfig; use OCP\IRequest; use PHPUnit\Framework\TestCase; class AdminControllerTest extends TestCase { - + /** + * @var string + */ private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var AdminController + */ private $controller; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $config; - private $configPath; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + */ private $itemService; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder(ItemService::class) ->disableOriginalConstructor() ->getMock(); - $this->configPath = 'my.ini'; - $this->controller = new AdminController( - $this->appName, $this->request, - $this->config, $this->itemService, $this->configPath - ); + $this->controller = new AdminController($this->appName, $this->request, $this->config, $this->itemService); } - - public function testIndex() + /** + * Test \OCA\News\Controller\AdminController::index + */ + public function testIndex() { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5, - 'maxSize' => 7, + 'useCronUpdates' => false, 'exploreUrl' => 'test', - 'updateInterval' => 3600 + 'updateInterval' => 3601 ]; - $this->config->expects($this->once()) - ->method('getAutoPurgeMinimumInterval') - ->will($this->returnValue($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('getMaxRedirects') - ->will($this->returnValue($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('getMaxSize') - ->will($this->returnValue($expected['maxSize'])); - $this->config->expects($this->once()) - ->method('getExploreUrl') - ->will($this->returnValue($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('getUpdateInterval') - ->will($this->returnValue($expected['updateInterval'])); + $map = [ + ['news','autoPurgeMinimumInterval', 60, 1], + ['news','autoPurgeCount', 200, 2], + ['news','maxRedirects', 10, 3], + ['news','feedFetcherTimeout', 60, 4], + ['news','useCronUpdates', true, false,], + ['news','exploreUrl', '', 'test'], + ['news','updateInterval', 3600, 3601] + ]; + $this->config->expects($this->exactly(count($map))) + ->method('getAppValue') + ->will($this->returnValueMap($map)); $response = $this->controller->index(); $data = $response->getParams(); @@ -101,75 +103,48 @@ public function testIndex() } - public function testUpdate() + public function testUpdate() { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5, - 'maxSize' => 7, + 'useCronUpdates' => false, 'exploreUrl' => 'test', - 'updateInterval' => 3600 + 'updateInterval' => 3601 ]; - $this->config->expects($this->once()) - ->method('setAutoPurgeMinimumInterval') - ->with($this->equalTo($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('setAutoPurgeCount') - ->with($this->equalTo($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('setMaxRedirects') - ->with($this->equalTo($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('setFeedFetcherTimeout') - ->with($this->equalTo($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('setUseCronUpdates') - ->with($this->equalTo($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('setExploreUrl') - ->with($this->equalTo($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('setUpdateInterval') - ->with($this->equalTo($expected['updateInterval'])); - $this->config->expects($this->once()) - ->method('write') - ->with($this->equalTo($this->configPath)); - - $this->config->expects($this->once()) - ->method('getAutoPurgeMinimumInterval') - ->will($this->returnValue($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('getMaxRedirects') - ->will($this->returnValue($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('getMaxSize') - ->will($this->returnValue($expected['maxSize'])); - $this->config->expects($this->once()) - ->method('getExploreUrl') - ->will($this->returnValue($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('getUpdateInterval') - ->will($this->returnValue($expected['updateInterval'])); + $this->config->expects($this->exactly(count($expected))) + ->method('setAppValue') + ->withConsecutive( + ['news','autoPurgeMinimumInterval', 1], + ['news','autoPurgeCount', 2], + ['news','maxRedirects', 3], + ['news','feedFetcherTimeout', 4], + ['news','useCronUpdates', false], + ['news','exploreUrl', 'test'], + ['news','updateInterval', 3601] + ); + + $map = [ + ['news','autoPurgeMinimumInterval', 60, 1], + ['news','autoPurgeCount', 200, 2], + ['news','maxRedirects', 10, 3], + ['news','feedFetcherTimeout', 60, 4], + ['news','useCronUpdates', true, false,], + ['news','exploreUrl', '', 'test'], + ['news','updateInterval', 3600, 3601] + ]; + $this->config->expects($this->exactly(count($map))) + ->method('getAppValue') + ->will($this->returnValueMap($map)); $response = $this->controller->update( $expected['autoPurgeMinimumInterval'], $expected['autoPurgeCount'], $expected['maxRedirects'], $expected['feedFetcherTimeout'], - $expected['maxSize'], $expected['useCronUpdates'], $expected['exploreUrl'], $expected['updateInterval'] diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 84ded5c6f3..94ffa1ed1a 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.php @@ -41,7 +41,7 @@ class ExportControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'john'; diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index cc387161d9..c889a54b3e 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -44,7 +44,7 @@ class FeedApiControllerTest extends TestCase private $logger; private $loggerParams; - protected function setUp() + protected function setUp(): void { $this->loggerParams = ['hi']; $this->logger = $this->getMockBuilder(ILogger::class) @@ -85,7 +85,7 @@ protected function setUp() } - public function testIndex() + public function testIndex() { $feeds = [new Feed()]; $starredCount = 3; @@ -116,7 +116,7 @@ public function testIndex() } - public function testIndexNoNewestItemId() + public function testIndexNoNewestItemId() { $feeds = [new Feed()]; $starredCount = 3; @@ -145,7 +145,7 @@ public function testIndexNoNewestItemId() } - public function testDelete() + public function testDelete() { $this->feedService->expects($this->once()) ->method('delete') @@ -158,7 +158,7 @@ public function testDelete() } - public function testDeleteDoesNotExist() + public function testDeleteDoesNotExist() { $this->feedService->expects($this->once()) ->method('delete') @@ -176,7 +176,7 @@ public function testDeleteDoesNotExist() } - public function testCreate() + public function testCreate() { $feeds = [new Feed()]; @@ -206,7 +206,7 @@ public function testCreate() } - public function testCreateNoItems() + public function testCreateNoItems() { $feeds = [new Feed()]; @@ -236,7 +236,7 @@ public function testCreateNoItems() - public function testCreateExists() + public function testCreateExists() { $this->feedService->expects($this->once()) ->method('purgeDeleted') @@ -255,7 +255,7 @@ public function testCreateExists() } - public function testCreateError() + public function testCreateError() { $this->feedService->expects($this->once()) ->method('create') @@ -271,7 +271,7 @@ public function testCreateError() } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('readFeed') @@ -285,7 +285,7 @@ public function testRead() } - public function testMove() + public function testMove() { $this->feedService->expects($this->once()) ->method('patch') @@ -299,7 +299,7 @@ public function testMove() } - public function testMoveDoesNotExist() + public function testMoveDoesNotExist() { $this->feedService->expects($this->once()) ->method('patch') @@ -315,7 +315,7 @@ public function testMoveDoesNotExist() } - public function testRename() + public function testRename() { $feedId = 3; $feedTitle = 'test'; @@ -332,7 +332,7 @@ public function testRename() } - public function testRenameError() + public function testRenameError() { $feedId = 3; $feedTitle = 'test'; @@ -370,7 +370,7 @@ public function testfromAllUsers() } - public function testUpdate() + public function testUpdate() { $feedId = 3; $userId = 'hi'; @@ -383,7 +383,7 @@ public function testUpdate() } - public function testUpdateError() + public function testUpdateError() { $feedId = 3; $userId = 'hi'; diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 4703d307af..9a3114da0d 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -45,7 +45,7 @@ class FeedControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jack'; @@ -398,7 +398,7 @@ public function testUpdateReturnsJSONError() } - public function testImport() + public function testImport() { $feed = new Feed(); @@ -426,7 +426,7 @@ public function testImport() } - public function testImportCreatesNoAdditionalFeed() + public function testImportCreatesNoAdditionalFeed() { $this->feedService->expects($this->once()) ->method('importArticles') @@ -467,7 +467,7 @@ public function testReadFeed() } - public function testRestore() + public function testRestore() { $this->feedService->expects($this->once()) ->method('unmarkDeleted') @@ -492,7 +492,7 @@ public function testRestoreDoesNotExist() $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } - public function testPatch() + public function testPatch() { $expected = [ 'pinned' => true, diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index 3a93a460a3..311212169e 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -44,7 +44,7 @@ class FolderApiControllerTest extends TestCase private $request; private $msg; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) @@ -79,7 +79,7 @@ protected function setUp() } - public function testIndex() + public function testIndex() { $folders = [new Folder()]; @@ -98,7 +98,7 @@ public function testIndex() } - public function testCreate() + public function testCreate() { $folderName = 'test'; $folder = new Folder(); @@ -122,7 +122,7 @@ public function testCreate() } - public function testCreateAlreadyExists() + public function testCreateAlreadyExists() { $msg = 'exists'; @@ -141,7 +141,7 @@ public function testCreateAlreadyExists() } - public function testCreateInvalidFolderName() + public function testCreateInvalidFolderName() { $msg = 'exists'; @@ -162,7 +162,7 @@ public function testCreateInvalidFolderName() } - public function testDelete() + public function testDelete() { $folderId = 23; $this->folderService->expects($this->once()) @@ -173,7 +173,7 @@ public function testDelete() } - public function testDeleteDoesNotExist() + public function testDeleteDoesNotExist() { $folderId = 23; @@ -193,7 +193,7 @@ public function testDeleteDoesNotExist() } - public function testUpdate() + public function testUpdate() { $folderId = 23; $folderName = 'test'; @@ -209,7 +209,7 @@ public function testUpdate() $this->folderAPI->update($folderId, $folderName); } - public function testUpdateDoesNotExist() + public function testUpdateDoesNotExist() { $folderId = 23; $folderName = 'test'; @@ -230,7 +230,7 @@ public function testUpdateDoesNotExist() } - public function testUpdateExists() + public function testUpdateExists() { $folderId = 23; $folderName = 'test'; @@ -251,7 +251,7 @@ public function testUpdateExists() } - public function testUpdateInvalidFolderName() + public function testUpdateInvalidFolderName() { $folderId = 23; $folderName = ''; @@ -274,7 +274,7 @@ public function testUpdateInvalidFolderName() } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('readFolder') diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php index b9e0485a4c..abe1ebd7ab 100644 --- a/tests/Unit/Controller/FolderControllerTest.php +++ b/tests/Unit/Controller/FolderControllerTest.php @@ -44,7 +44,7 @@ class FolderControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jack'; diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 5733a0c871..412b9dd517 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -39,7 +39,7 @@ class ItemApiControllerTest extends TestCase private $request; private $msg; - protected function setUp() + protected function setUp(): void { $this->user = 'tom'; $this->appName = 'news'; @@ -71,7 +71,7 @@ protected function setUp() } - public function testIndex() + public function testIndex() { $item = new Item(); $item->setId(5); @@ -102,7 +102,7 @@ public function testIndex() } - public function testIndexDefaultBatchSize() + public function testIndexDefaultBatchSize() { $item = new Item(); $item->setId(5); @@ -133,7 +133,7 @@ public function testIndexDefaultBatchSize() } - public function testUpdated() + public function testUpdated() { $item = new Item(); $item->setId(5); @@ -162,7 +162,7 @@ public function testUpdated() } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('read') @@ -176,7 +176,7 @@ public function testRead() } - public function testReadDoesNotExist() + public function testReadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') @@ -194,7 +194,7 @@ public function testReadDoesNotExist() } - public function testUnread() + public function testUnread() { $this->itemService->expects($this->once()) ->method('read') @@ -208,7 +208,7 @@ public function testUnread() } - public function testUnreadDoesNotExist() + public function testUnreadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') @@ -226,7 +226,7 @@ public function testUnreadDoesNotExist() } - public function testStar() + public function testStar() { $this->itemService->expects($this->once()) ->method('star') @@ -241,7 +241,7 @@ public function testStar() } - public function testStarDoesNotExist() + public function testStarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') @@ -259,7 +259,7 @@ public function testStarDoesNotExist() } - public function testUnstar() + public function testUnstar() { $this->itemService->expects($this->once()) ->method('star') @@ -274,7 +274,7 @@ public function testUnstar() } - public function testUnstarDoesNotExist() + public function testUnstarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') @@ -292,7 +292,7 @@ public function testUnstarDoesNotExist() } - public function testReadAll() + public function testReadAll() { $this->itemService->expects($this->once()) ->method('readAll') @@ -306,7 +306,7 @@ public function testReadAll() - public function testReadMultiple() + public function testReadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -326,7 +326,7 @@ public function testReadMultiple() } - public function testReadMultipleDoesntCareAboutException() + public function testReadMultipleDoesntCareAboutException() { $this->itemService->expects($this->at(0)) ->method('read') @@ -342,7 +342,7 @@ public function testReadMultipleDoesntCareAboutException() } - public function testUnreadMultiple() + public function testUnreadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -362,7 +362,7 @@ public function testUnreadMultiple() } - public function testStarMultiple() + public function testStarMultiple() { $ids = [ [ @@ -395,7 +395,7 @@ public function testStarMultiple() } - public function testStarMultipleDoesntCareAboutException() + public function testStarMultipleDoesntCareAboutException() { $ids = [ [ @@ -423,7 +423,7 @@ public function testStarMultipleDoesntCareAboutException() } - public function testUnstarMultiple() + public function testUnstarMultiple() { $ids = [ [ diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index b24d741487..9dbcf15ce8 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -43,7 +43,7 @@ class ItemControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jackob'; @@ -96,7 +96,7 @@ public function testReadDoesNotExist() } - public function testReadMultiple() + public function testReadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -116,7 +116,7 @@ public function testReadMultiple() } - public function testReadMultipleDontStopOnException() + public function testReadMultipleDontStopOnException() { $this->itemService->expects($this->at(0)) ->method('read') diff --git a/tests/Unit/Controller/JSONHttpErrorTest.php b/tests/Unit/Controller/JSONHttpErrorTest.php index bf043bf547..c02b60c9e3 100644 --- a/tests/Unit/Controller/JSONHttpErrorTest.php +++ b/tests/Unit/Controller/JSONHttpErrorTest.php @@ -26,7 +26,7 @@ class JSONHttpErrorTest extends TestCase { - public function testError() + public function testError() { $ex = new \Exception('hi'); $test = new Test(); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index ce7a3e73d0..69fed0d77b 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -13,7 +13,7 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; +use OC\L10N\L10N; use OCA\News\Controller\PageController; use \OCA\News\Db\FeedType; use OCA\News\Explore\RecommendedSites; @@ -28,26 +28,51 @@ class PageControllerTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $settings; - private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var PageController + */ private $controller; - private $user; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator + */ private $urlGenerator; - private $appConfig; + + /** + * @var array + */ private $configData; - private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|RecommendedSites + */ private $recommended; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|StatusService + */ private $status; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { - $this->appName = 'news'; - $this->user = 'becka'; $this->configData = [ 'name' => 'AppTest', 'id' => 'apptest', @@ -70,12 +95,6 @@ public function setUp() $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); - $this->appConfig = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); - $this->config = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); $this->recommended = $this->getMockBuilder(RecommendedSites::class) ->disableOriginalConstructor() ->getMock(); @@ -83,10 +102,14 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); $this->controller = new PageController( - $this->appName, $this->request, - $this->settings, $this->urlGenerator, $this->config, - $this->l10n, $this->recommended, $this->status, - $this->user + 'news', + $this->request, + $this->settings, + $this->urlGenerator, + $this->l10n, + $this->recommended, + $this->status, + 'becka' ); } @@ -95,15 +118,7 @@ public function testIndex() { $this->status->expects($this->once()) ->method('getStatus') - ->will( - $this->returnValue( - [ - 'warnings' => [ - 'improperlyConfiguredCron' => false - ] - ] - ) - ); + ->will($this->returnValue(['warnings' => ['improperlyConfiguredCron' => false]])); $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); @@ -130,8 +145,10 @@ public function testIndexNoCorrectCronAjax() $this->assertEquals(true, $response->getParams()['warnings']['improperlyConfiguredCron']); } - - public function testSettings() + /** + * @covers \OCA\News\Controller\PageController::settings + */ + public function testSettings() { $result = [ 'settings' => [ @@ -148,55 +165,23 @@ public function testSettings() $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue(' ')); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') - ->with( - $this->equalTo('news.page.explore'), - $this->equalTo(['lang' => 'en']) - ) + ->with('news.page.explore', ['lang' => 'en']) ->will($this->returnValue('test')); @@ -205,7 +190,7 @@ public function testSettings() } - public function testSettingsExploreUrlSet() + public function testSettingsExploreUrlSet() { $result = [ 'settings' => [ @@ -222,48 +207,19 @@ public function testSettingsExploreUrlSet() $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue('abc')); $this->urlGenerator->expects($this->never()) ->method('getAbsoluteURL'); @@ -273,83 +229,50 @@ public function testSettingsExploreUrlSet() $this->assertEquals($result, $response); } - public function testUpdateSettings() + /** + * @covers \OCA\News\Controller\PageController::updateSettings + */ + public function testUpdateSettings() { $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'showAll', '1'); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'compact', '1'); $this->settings->expects($this->at(2)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll'), - $this->equalTo('0') - ); + ->with('becka', 'news', 'preventReadOnScroll', '0'); $this->settings->expects($this->at(3)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'oldestFirst', '1'); $this->settings->expects($this->at(4)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand'), - $this->equalTo('1') - ); - $this->controller->updateSettings(true, true, false, true, true); + ->with('becka', 'news', 'compactExpand', '1'); + $this->controller->updateSettings(true, true, false, true, true); } - public function testExplore() { $in = 'test'; $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId'), - $this->equalTo(0) - ); + ->with('becka', 'news', 'lastViewedFeedId', 0); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType'), - $this->equalTo(FeedType::EXPLORE) - ); + ->with('becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE); $this->recommended->expects($this->once()) ->method('forLanguage') - ->with($this->equalTo('en')) + ->with('en') ->will($this->returnValue($in)); - $out = $this->controller->explore('en'); $this->assertEquals($in, $out); + } } diff --git a/tests/Unit/Controller/UserApiControllerTest.php b/tests/Unit/Controller/UserApiControllerTest.php index d9df73fe73..dd0140c81e 100644 --- a/tests/Unit/Controller/UserApiControllerTest.php +++ b/tests/Unit/Controller/UserApiControllerTest.php @@ -33,7 +33,7 @@ class UserApiControllerTest extends TestCase private $user; private $file; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) @@ -59,7 +59,7 @@ protected function setUp() } - private function expectUser($uid, $displayName, $lastLogin) + private function expectUser($uid, $displayName, $lastLogin) { $this->userSession->expects($this->any()) ->method('getUser') @@ -75,7 +75,7 @@ private function expectUser($uid, $displayName, $lastLogin) ->will($this->returnValue($displayName)); } - private function expectImg($isJpg, $isPng, $user, $exists, $data) + private function expectImg($isJpg, $isPng, $user, $exists, $data) { $jpg = '/' . $user . '/' . 'avatar.jpg'; $png = '/' . $user . '/' . 'avatar.png'; @@ -98,7 +98,7 @@ private function expectImg($isJpg, $isPng, $user, $exists, $data) ->will($this->returnValue($data)); } - public function testGetJpeg() + public function testGetJpeg() { $this->expectUser('john', 'John', 123); $this->expectImg(true, false, 'john', true, 'hi'); @@ -117,7 +117,7 @@ public function testGetJpeg() $this->assertEquals($expected, $result); } - public function testGetPng() + public function testGetPng() { $this->expectUser('john', 'John', 123); $this->expectImg(false, true, 'john', false, 'hi'); @@ -136,7 +136,7 @@ public function testGetPng() $this->assertEquals($expected, $result); } - public function testNoAvatar() + public function testNoAvatar() { $this->expectUser('john', 'John', 123); $this->expectImg(false, false, 'john', false, 'hi'); diff --git a/tests/Unit/Controller/UtilityApiControllerTest.php b/tests/Unit/Controller/UtilityApiControllerTest.php index 37070b1609..32a66b2e81 100644 --- a/tests/Unit/Controller/UtilityApiControllerTest.php +++ b/tests/Unit/Controller/UtilityApiControllerTest.php @@ -37,7 +37,7 @@ class UtilityApiControllerTest extends TestCase private $appName; private $status; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->settings = $this->getMockBuilder(IConfig::class) diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index 11c411b5e6..f8544da650 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.php @@ -28,7 +28,7 @@ class FolderMapperTest extends MapperTestUtility /** @var string */ private $user; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/Db/ItemTest.php b/tests/Unit/Db/ItemTest.php index 6b63f86855..c9a353ea73 100644 --- a/tests/Unit/Db/ItemTest.php +++ b/tests/Unit/Db/ItemTest.php @@ -22,11 +22,11 @@ class ItemTest extends TestCase { /** - * @var Item + * @var Item */ private $item; - protected function setUp() + protected function setUp(): void { $this->item = new Item(); $this->item->setStatus(0); @@ -65,7 +65,7 @@ public function testSetUnstarred() } - public function testToAPI() + public function testToAPI() { $item = new Item(); $item->setId(3); @@ -117,7 +117,7 @@ public function testToAPI() } - public function testJSONSerialize() + public function testJSONSerialize() { $item = new Item(); $item->setId(3); @@ -167,7 +167,7 @@ public function testJSONSerialize() ); } - public function testToExport() + public function testToExport() { $item = new Item(); $item->setId(3); @@ -216,7 +216,7 @@ public function testToExport() } - private function createImportItem($isRead) + private function createImportItem($isRead) { $item = new Item(); $item->setGuid('guid'); @@ -242,7 +242,7 @@ private function createImportItem($isRead) } - public function testSearchIndex() + public function testSearchIndex() { $item = new Item(); $item->setBody('somEthäng'); @@ -255,7 +255,7 @@ public function testSearchIndex() } - public function testFromImport() + public function testFromImport() { $item = $this->createImportItem(false); @@ -282,7 +282,7 @@ public function testFromImport() } - public function testFromImportRead() + public function testFromImportRead() { $item = $this->createImportItem(true); @@ -315,7 +315,7 @@ public function testSetAuthor() $item = new Item(); $item->setAuthor('my link'); $this->assertEquals('my link', $item->getAuthor()); - $this->assertContains('author', $item->getUpdatedFields()); + $this->assertArrayHasKey('author', $item->getUpdatedFields()); } @@ -324,11 +324,11 @@ public function testSetTitle() $item = new Item(); $item->setTitle('my link'); $this->assertEquals('my link', $item->getTitle()); - $this->assertContains('title', $item->getUpdatedFields()); + $this->assertArrayHasKey('title', $item->getUpdatedFields()); } - public function testSetXSSUrl() + public function testSetXSSUrl() { $item = new Item(); $item->setUrl('javascript:alert()'); @@ -336,7 +336,7 @@ public function testSetXSSUrl() } - public function testSetMagnetUrl() + public function testSetMagnetUrl() { $item = new Item(); $item->setUrl('magnet://link.com'); @@ -344,7 +344,7 @@ public function testSetMagnetUrl() } - public function testMakeLinksInBodyOpenNewTab() + public function testMakeLinksInBodyOpenNewTab() { $item = new Item(); $item->setBody("ha"); @@ -354,7 +354,7 @@ public function testMakeLinksInBodyOpenNewTab() ); } - public function testComputeFingerPrint() + public function testComputeFingerPrint() { $title = 'a'; $body = 'b'; diff --git a/tests/Unit/Db/MapperFactoryTest.php b/tests/Unit/Db/MapperFactoryTest.php index 697a62beee..97680e20bb 100644 --- a/tests/Unit/Db/MapperFactoryTest.php +++ b/tests/Unit/Db/MapperFactoryTest.php @@ -29,26 +29,26 @@ class MapperFactoryTest extends TestCase private $db; private $settings; - public function setUp() + public function setUp(): void { $this->db = $this->getMockBuilder(IDBConnection::class) ->disableOriginalConstructor() ->getMock(); } - public function testGetItemMapperSqlite() + public function testGetItemMapperSqlite() { $factory = new MapperFactory($this->db, 'sqlite', new Time()); $this->assertTrue($factory->build() instanceof ItemMapper); } - public function testGetItemMapperPostgres() + public function testGetItemMapperPostgres() { $factory = new MapperFactory($this->db, 'pgsql', new Time()); $this->assertTrue($factory->build() instanceof ItemMapper); } - public function testGetItemMapperMysql() + public function testGetItemMapperMysql() { $factory = new MapperFactory($this->db, 'mysql', new Time()); $this->assertTrue($factory->build() instanceof MysqlMapper); diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php index 5417e16bc4..b414b43e3f 100644 --- a/tests/Unit/Db/MapperTestUtility.php +++ b/tests/Unit/Db/MapperTestUtility.php @@ -43,7 +43,7 @@ abstract class MapperTestUtility extends TestCase * Run this function before the actual test to either set or initialize the * db. After this the db can be accessed by using $this->db */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -64,7 +64,7 @@ protected function setUp() * @param array $array * @return bool true if associative */ - private function isAssocArray(array $array) + private function isAssocArray(array $array) { return array_values($array) !== $array; } @@ -75,7 +75,7 @@ private function isAssocArray(array $array) * @param $value * @return PDO constant */ - private function getPDOType($value) + private function getPDOType($value) { switch (gettype($value)) { case 'integer': diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php index f50912f49f..6360973de1 100644 --- a/tests/Unit/Fetcher/FeedFetcherTest.php +++ b/tests/Unit/Fetcher/FeedFetcherTest.php @@ -25,7 +25,9 @@ use OCA\News\Fetcher\FeedFetcher; use OCA\News\Utility\PsrLogger; +use OCP\ILogger; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; /** * Class FeedFetcherTest @@ -83,7 +85,7 @@ class FeedFetcherTest extends TestCase private $feed_mock; /** - * @var PsrLogger + * @var LoggerInterface */ private $logger; @@ -128,7 +130,7 @@ class FeedFetcherTest extends TestCase private $modified; private $location; - protected function setUp() + protected function setUp(): void { $this->l10n = $this->getMockBuilder(\OCP\IL10N::class) ->disableOriginalConstructor() @@ -161,8 +163,7 @@ protected function setUp() $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->logger = $this->getMockBuilder(PsrLogger::class) - ->disableOriginalConstructor() + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->getMock(); $this->scraper = $this->getMockBuilder(Scraper::class) ->disableOriginalConstructor() @@ -373,7 +374,7 @@ public function testNoFavicon() { $this->setUpReader($this->url); - $feed = $this->createFeed(false); + $feed = $this->createFeed('de-DE', false); $this->favicon->expects($this->never()) ->method('get'); diff --git a/tests/Unit/Fetcher/FetcherTest.php b/tests/Unit/Fetcher/FetcherTest.php index 2549ff6068..a90a2da049 100644 --- a/tests/Unit/Fetcher/FetcherTest.php +++ b/tests/Unit/Fetcher/FetcherTest.php @@ -34,7 +34,7 @@ class FetcherTest extends TestCase private $fetcher; - protected function setUp() + protected function setUp(): void { $this->fetcher = new Fetcher(); } diff --git a/tests/Unit/Fetcher/YoutubeFetcherTest.php b/tests/Unit/Fetcher/YoutubeFetcherTest.php index 1c0c4c8198..e08d35f169 100644 --- a/tests/Unit/Fetcher/YoutubeFetcherTest.php +++ b/tests/Unit/Fetcher/YoutubeFetcherTest.php @@ -35,7 +35,7 @@ class YoutubeFetcherTest extends TestCase */ private $feedFetcher; - public function setUp() + public function setUp(): void { $this->feedFetcher = $this->getMockBuilder(FeedFetcher::class) ->disableOriginalConstructor() diff --git a/tests/Unit/Http/TextDownloadResponseTest.php b/tests/Unit/Http/TextDownloadResponseTest.php index 4021d22aa9..be5f53ec12 100644 --- a/tests/Unit/Http/TextDownloadResponseTest.php +++ b/tests/Unit/Http/TextDownloadResponseTest.php @@ -22,7 +22,7 @@ class TextDownloadResponseTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->response = new TextDownloadResponse( 'sometext', 'file', 'content' @@ -30,7 +30,7 @@ protected function setUp() } - public function testRender() + public function testRender() { $this->assertEquals('sometext', $this->response->render()); } diff --git a/tests/Unit/Http/TextResponseTest.php b/tests/Unit/Http/TextResponseTest.php index 5de374a17b..eaad769b51 100644 --- a/tests/Unit/Http/TextResponseTest.php +++ b/tests/Unit/Http/TextResponseTest.php @@ -21,13 +21,13 @@ class TextResponseTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->response = new TextResponse('sometext'); } - public function testRender() + public function testRender() { $this->assertEquals('sometext', $this->response->render()); } diff --git a/tests/Unit/Migration/MigrateStatusFlagsTest.php b/tests/Unit/Migration/MigrateStatusFlagsTest.php index fb915ec94b..d71f1a54c7 100644 --- a/tests/Unit/Migration/MigrateStatusFlagsTest.php +++ b/tests/Unit/Migration/MigrateStatusFlagsTest.php @@ -22,15 +22,15 @@ class MigrateStatusFlagsTest extends TestCase { /** - * @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject + * @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */ protected $db; /** - * @var IConfig|\PHPUnit_Framework_MockObject_MockObject + * @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $config; /** - * @var IOutput|\PHPUnit_Framework_MockObject_MockObject + * @var IOutput|\PHPUnit_Framework_MockObject_MockObject */ protected $output; @@ -41,7 +41,7 @@ protected function setUp(): void $this->output = $this->createMock(IOutput::class); } - public function testRun() + public function testRun() { $statement = $this->createMock(Statement::class); $statement->expects($this->exactly(1)) @@ -67,11 +67,11 @@ public function testRun() $migration->run($this->output); } - /** - * @expectedException \Exception - */ - public function testRunException() + public function testRunException() { + $this->expectException('\Exception'); + $this->expectExceptionMessage('Could not migrate status'); + $statement = $this->createMock(Statement::class); $statement->expects($this->exactly(1)) ->method('execute') @@ -96,7 +96,7 @@ public function testRunException() $migration->run($this->output); } - public function testRunNewerVersion() + public function testRunNewerVersion() { $this->config->expects($this->exactly(1)) ->method('getAppValue') diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index 76c8f89f61..84c2121eda 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.php @@ -16,7 +16,7 @@ use FeedIo\Reader\ReadErrorException; -use OCA\News\Config\Config; +use OC\L10N\L10N; use OCA\News\Db\FeedMapper; use OCA\News\Db\ItemMapper; use OCA\News\Service\FeedService; @@ -28,6 +28,7 @@ use OCA\News\Db\Item; use OCA\News\Fetcher\Fetcher; use OCA\News\Fetcher\FetcherException; +use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -37,28 +38,60 @@ class FeedServiceTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FeedMapper + */ private $feedMapper; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper + */ + private $itemMapper; + /** @var FeedService */ private $feedService; + + /** + * @var string + */ private $user; - private $response; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|Fetcher + */ private $fetcher; - private $itemMapper; - private $threshold; + + /** + * @var int + */ private $time; - private $importParser; + + /** + * @var int + */ private $autoPurgeMinimumInterval; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|\HTMLPurifier + */ private $purifier; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ILogger + */ private $logger; - private $loggerParams; - protected function setUp() + protected function setUp(): void { $this->logger = $this->getMockBuilder(ILogger::class) ->disableOriginalConstructor() ->getMock(); - $this->loggerParams = ['hi']; + $loggerParams = ['hi']; $this->time = 222; $this->autoPurgeMinimumInterval = 10; $timeFactory = $this->getMockBuilder(Time::class) @@ -86,31 +119,34 @@ protected function setUp() ->getMockBuilder(\HTMLPurifier::class) ->disableOriginalConstructor() ->getMock(); - $config = $this->getMockBuilder(Config::class) + $config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) - ->method('getAutoPurgeMinimumInterval') + ->method('getAppValue') + ->with('news', 'autoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->feedService = new FeedService( $this->feedMapper, $this->fetcher, $this->itemMapper, $this->logger, $this->l10n, - $timeFactory, $config, $this->purifier, $this->loggerParams + $timeFactory, $config, $this->purifier, $loggerParams ); $this->user = 'jack'; } - + /** + * @covers \OCA\News\Service\FeedService::findAll + */ public function testFindAll() { $this->feedMapper->expects($this->once()) ->method('findAllFromUser') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($this->response)); + ->with($this->user) + ->will($this->returnValue([])); $result = $this->feedService->findAll($this->user); - $this->assertEquals($this->response, $result); + $this->assertEquals([], $result); } @@ -120,7 +156,7 @@ public function testCreateDoesNotFindFeed() $url = 'test'; $this->fetcher->expects($this->once()) ->method('fetch') - ->with($this->equalTo($url)) + ->with($url) ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); $this->feedService->create($url, 1, $this->user); @@ -1145,12 +1181,9 @@ public function testPatchEnableFullText() $this->feedService->patch(3, $this->user, ['fullTextEnabled' => true]); } - - /** - * @expectedException OCA\News\Service\ServiceNotFoundException - */ public function testPatchDoesNotExist() { + $this->expectException('OCA\News\Service\ServiceNotFoundException'); $feed = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->once()) ->method('find') diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 47c1c9a8d8..4086f55e1a 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -13,13 +13,14 @@ namespace OCA\News\Tests\Unit\Service; -use OCA\News\Config\Config; +use OC\L10N\L10N; use \OCA\News\Db\Folder; use OCA\News\Db\FolderMapper; use OCA\News\Service\FolderService; use OCA\News\Service\ServiceConflictException; use OCA\News\Service\ServiceValidationException; use OCA\News\Utility\Time; +use OCP\IConfig; use OCP\IL10N; use PHPUnit\Framework\TestCase; @@ -28,14 +29,37 @@ class FolderServiceTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FolderMapper + */ private $folderMapper; + + /** + * @var FolderService + */ private $folderService; + + /** + * @var int + */ private $time; + + /** + * @var string + */ private $user; + + /** + * @var int + */ private $autoPurgeMinimumInterval; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; - protected function setUp() + protected function setUp(): void { $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() @@ -51,11 +75,12 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); $this->autoPurgeMinimumInterval = 10; - $config = $this->getMockBuilder(Config::class) + $config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) - ->method('getAutoPurgeMinimumInterval') + ->method('getAppValue') + ->with('news', 'autoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->folderService = new FolderService( $this->folderMapper, $this->l10n, $timeFactory, $config @@ -119,11 +144,10 @@ public function testCreateThrowsExWhenFolderNameExists() $this->folderService->create($folderName, 'john', 3); } - /** - * @expectedException \OCA\News\Service\ServiceValidationException - */ public function testCreateThrowsExWhenFolderNameEmpty() { + $this->expectException('OCA\News\Service\ServiceValidationException'); + $folderName = ''; $this->folderMapper->expects($this->once()) @@ -211,7 +235,7 @@ public function testRenameThrowsExWhenFolderNameEmpty() } - public function testMarkDeleted() + public function testMarkDeleted() { $id = 3; $folder = new Folder(); @@ -230,7 +254,7 @@ public function testMarkDeleted() } - public function testUnmarkDeleted() + public function testUnmarkDeleted() { $id = 3; $folder = new Folder(); @@ -295,7 +319,7 @@ public function testPurgeDeletedNoInterval() } - public function testDeleteUser() + public function testDeleteUser() { $this->folderMapper->expects($this->once()) ->method('deleteUser') diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 9a89d2e1a3..e56add1527 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -13,7 +13,6 @@ namespace OCA\News\Tests\Unit\Service; -use OCA\News\Config\Config; use OCA\News\Db\ItemMapper; use OCA\News\Service\ItemService; use OCA\News\Service\ServiceNotFoundException; @@ -30,20 +29,26 @@ class ItemServiceTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper + */ private $mapper; /** - * @var ItemService + * @var ItemService */ private $itemService; - private $user; - private $response; - private $status; + + /** + * @var int + */ private $time; - private $newestItemId; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $config; - private $systemConfig; - protected function setUp() + protected function setUp(): void { $this->time = 222; $this->timeFactory = $this->getMockBuilder(Time::class) @@ -58,23 +63,10 @@ protected function setUp() $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->systemConfig = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->itemService = new ItemService( - $this->mapper, - $this->timeFactory, $this->config, $this->systemConfig - ); - $this->user = 'jack'; - $this->id = 3; - $this->updatedSince = 20333; - $this->showAll = true; - $this->offset = 5; - $this->limit = 20; - $this->newestItemId = 4; + $this->itemService = new ItemService($this->mapper, $this->timeFactory, $this->config); } @@ -84,18 +76,15 @@ public function testFindAllNewFeed() $this->mapper->expects($this->once()) ->method('findAllNewFeed') ->with( - $this->equalTo($this->id), - $this->equalTo($this->updatedSince), - $this->equalTo($this->showAll), - $this->equalTo($this->user) + $this->equalTo(3), + $this->equalTo(20333), + $this->equalTo(true), + $this->equalTo('jack') ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue([])); - $result = $this->itemService->findAllNew( - $this->id, $type, $this->updatedSince, $this->showAll, - $this->user - ); - $this->assertEquals($this->response, $result); + $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack'); + $this->assertEquals([], $result); } @@ -105,18 +94,15 @@ public function testFindAllNewFolder() $this->mapper->expects($this->once()) ->method('findAllNewFolder') ->with( - $this->equalTo($this->id), - $this->equalTo($this->updatedSince), - $this->equalTo($this->showAll), - $this->equalTo($this->user) + $this->equalTo(3), + $this->equalTo(20333), + $this->equalTo(true), + $this->equalTo('jack') ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); - $result = $this->itemService->findAllNew( - $this->id, $type, $this->updatedSince, $this->showAll, - $this->user - ); - $this->assertEquals($this->response, $result); + $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack'); + $this->assertEquals(['val'], $result); } @@ -126,18 +112,18 @@ public function testFindAllNew() $this->mapper->expects($this->once()) ->method('findAllNew') ->with( - $this->equalTo($this->updatedSince), + $this->equalTo(20333), $this->equalTo($type), - $this->equalTo($this->showAll), - $this->equalTo($this->user) + $this->equalTo(true), + $this->equalTo('jack') ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAllNew( - $this->id, $type, $this->updatedSince, $this->showAll, - $this->user + 3, $type, 20333, true, + 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -147,21 +133,21 @@ public function testFindAllFeed() $this->mapper->expects($this->once()) ->method('findAllFeed') ->with( - $this->equalTo($this->id), - $this->equalTo($this->limit), - $this->equalTo($this->offset), - $this->equalTo($this->showAll), + $this->equalTo(3), + $this->equalTo(20), + $this->equalTo(5), + $this->equalTo(true), $this->equalTo(false), - $this->equalTo($this->user), + $this->equalTo('jack'), $this->equalTo([]) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, false, $this->user + 3, $type, 20, 5, + true, false, 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -171,21 +157,21 @@ public function testFindAllFolder() $this->mapper->expects($this->once()) ->method('findAllFolder') ->with( - $this->equalTo($this->id), - $this->equalTo($this->limit), - $this->equalTo($this->offset), - $this->equalTo($this->showAll), + $this->equalTo(3), + $this->equalTo(20), + $this->equalTo(5), + $this->equalTo(true), $this->equalTo(true), - $this->equalTo($this->user), + $this->equalTo('jack'), $this->equalTo([]) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, true, $this->user + 3, $type, 20, 5, + true, true, 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -195,21 +181,21 @@ public function testFindAll() $this->mapper->expects($this->once()) ->method('findAll') ->with( - $this->equalTo($this->limit), - $this->equalTo($this->offset), + $this->equalTo(20), + $this->equalTo(5), $this->equalTo($type), - $this->equalTo($this->showAll), $this->equalTo(true), - $this->equalTo($this->user), + $this->equalTo(true), + $this->equalTo('jack'), $this->equalTo([]) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, true, $this->user + 3, $type, 20, 5, + true, true, 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -220,21 +206,21 @@ public function testFindAllSearch() $this->mapper->expects($this->once()) ->method('findAll') ->with( - $this->equalTo($this->limit), - $this->equalTo($this->offset), + $this->equalTo(20), + $this->equalTo(5), $this->equalTo($type), - $this->equalTo($this->showAll), $this->equalTo(true), - $this->equalTo($this->user), + $this->equalTo(true), + $this->equalTo('jack'), $this->equalTo($search) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, true, $this->user, $search + 3, $type, 20, 5, + true, true, 'jack', $search ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -260,7 +246,7 @@ public function testStar() ->with( $this->equalTo($guidHash), $this->equalTo($feedId), - $this->equalTo($this->user) + $this->equalTo('jack') ) ->will($this->returnValue($item)); @@ -268,7 +254,7 @@ public function testStar() ->method('update') ->with($this->equalTo($expectedItem)); - $this->itemService->star($feedId, $guidHash, true, $this->user); + $this->itemService->star($feedId, $guidHash, true, 'jack'); $this->assertTrue($item->isStarred()); } @@ -296,7 +282,7 @@ public function testUnstar() ->with( $this->equalTo($guidHash), $this->equalTo($feedId), - $this->equalTo($this->user) + $this->equalTo('jack') ) ->will($this->returnValue($item)); @@ -304,7 +290,7 @@ public function testUnstar() ->method('update') ->with($this->equalTo($expectedItem)); - $this->itemService->star($feedId, $guidHash, false, $this->user); + $this->itemService->star($feedId, $guidHash, false, 'jack'); $this->assertFalse($item->isStarred()); } @@ -329,11 +315,11 @@ public function testRead() $this->equalTo($itemId), $this->equalTo(true), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ) ->will($this->returnValue($item)); - $this->itemService->read($itemId, true, $this->user); + $this->itemService->read($itemId, true, 'jack'); } @@ -345,7 +331,7 @@ public function testReadDoesNotExist() ->method('readItem') ->will($this->throwException(new DoesNotExistException(''))); - $this->itemService->read(1, true, $this->user); + $this->itemService->read(1, true, 'jack'); } public function testStarDoesNotExist() @@ -356,7 +342,7 @@ public function testStarDoesNotExist() ->method('findByGuidHash') ->will($this->throwException(new DoesNotExistException(''))); - $this->itemService->star(1, 'hash', true, $this->user); + $this->itemService->star(1, 'hash', true, 'jack'); } @@ -369,10 +355,10 @@ public function testReadAll() ->with( $this->equalTo($highestItemId), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ); - $this->itemService->readAll($highestItemId, $this->user); + $this->itemService->readAll($highestItemId, 'jack'); } @@ -387,10 +373,10 @@ public function testReadFolder() $this->equalTo($folderId), $this->equalTo($highestItemId), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ); - $this->itemService->readFolder($folderId, $highestItemId, $this->user); + $this->itemService->readFolder($folderId, $highestItemId, 'jack'); } @@ -405,17 +391,18 @@ public function testReadFeed() $this->equalTo($feedId), $this->equalTo($highestItemId), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ); - $this->itemService->readFeed($feedId, $highestItemId, $this->user); + $this->itemService->readFeed($feedId, $highestItemId, 'jack'); } public function testAutoPurgeOldWillPurgeOld() { $this->config->expects($this->once()) - ->method('getAutoPurgeCount') + ->method('getAppValue') + ->with('news', 'autoPurgeCount') ->will($this->returnValue(2)); $this->mapper->expects($this->once()) ->method('deleteReadOlderThanThreshold') @@ -427,7 +414,8 @@ public function testAutoPurgeOldWillPurgeOld() public function testAutoPurgeOldWontPurgeOld() { $this->config->expects($this->once()) - ->method('getAutoPurgeCount') + ->method('getAppValue') + ->with('news', 'autoPurgeCount') ->will($this->returnValue(-1)); $this->mapper->expects($this->never()) ->method('deleteReadOlderThanThreshold'); @@ -436,23 +424,23 @@ public function testAutoPurgeOldWontPurgeOld() } - public function testGetNewestItemId() + public function testGetNewestItemId() { $this->mapper->expects($this->once()) ->method('getNewestItemId') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will($this->returnValue(12)); - $result = $this->itemService->getNewestItemId($this->user); + $result = $this->itemService->getNewestItemId('jack'); $this->assertEquals(12, $result); } - public function testGetNewestItemIdDoesNotExist() + public function testGetNewestItemIdDoesNotExist() { $this->mapper->expects($this->once()) ->method('getNewestItemId') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will( $this->throwException( new DoesNotExistException('There are no items') @@ -460,7 +448,7 @@ public function testGetNewestItemIdDoesNotExist() ); $this->expectException(ServiceNotFoundException::class); - $this->itemService->getNewestItemId($this->user); + $this->itemService->getNewestItemId('jack'); } @@ -470,10 +458,10 @@ public function testStarredCount() $this->mapper->expects($this->once()) ->method('starredCount') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will($this->returnValue($star)); - $result = $this->itemService->starredCount($this->user); + $result = $this->itemService->starredCount('jack'); $this->assertEquals($star, $result); } @@ -485,22 +473,22 @@ public function testGetUnreadOrStarred() $this->mapper->expects($this->once()) ->method('findAllUnreadOrStarred') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will($this->returnValue($star)); - $result = $this->itemService->getUnreadOrStarred($this->user); + $result = $this->itemService->getUnreadOrStarred('jack'); $this->assertEquals($star, $result); } - public function testDeleteUser() + public function testDeleteUser() { $this->mapper->expects($this->once()) ->method('deleteUser') - ->will($this->returnValue($this->user)); + ->will($this->returnValue('jack')); - $this->itemService->deleteUser($this->user); + $this->itemService->deleteUser('jack'); } diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index eb18982902..8f601be468 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.php @@ -37,7 +37,7 @@ class ServiceTest extends TestCase protected $mapper; protected $newsService; - protected function setUp() + protected function setUp(): void { $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php index 8c42997a02..ee2e196148 100644 --- a/tests/Unit/Service/StatusServiceTest.php +++ b/tests/Unit/Service/StatusServiceTest.php @@ -13,8 +13,6 @@ namespace OCA\News\Tests\Unit\Service; -use OCA\News\Config\Config; -use \OCA\News\Db\FeedType; use OCA\News\Service\StatusService; use OCP\IConfig; use OCP\IDBConnection; @@ -23,83 +21,174 @@ class StatusServiceTest extends TestCase { - + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $settings; - private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection + */ + private $connection; + + /** + * @var StatusService + */ private $service; - private $appName; - public function setUp() + public function setUp(): void { - $this->appName = 'news'; $this->settings = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); - $this->db = $this->getMockBuilder(IDBConnection::class) + $this->connection = $this->getMockBuilder(IDBConnection::class) ->disableOriginalConstructor() ->getMock(); - $this->service = new StatusService( - $this->settings, $this->db, - $this->config, $this->appName - ); - } - - private function beforeStatus($cronMode='cron', $cronEnabled=true, - $version='1.0' - ) { - $this->settings->expects($this->at(0)) - ->method('getAppValue') - ->with( - $this->equalTo($this->appName), - $this->equalTo('installed_version') - ) - ->will($this->returnValue($version)); - - $this->settings->expects($this->at(1)) - ->method('getAppValue') - ->with( - $this->equalTo('core'), - $this->equalTo('backgroundjobs_mode') - ) - ->will($this->returnValue($cronMode)); - - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($cronEnabled)); - + $this->service = new StatusService($this->settings, $this->connection, 'news'); } - + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ public function testGetStatus() { - $this->beforeStatus(); - + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, true], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('cron')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(true)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => false, + ], + ]; $response = $this->service->getStatus(); - $this->assertEquals('1.0', $response['version']); - $this->assertFalse($response['warnings']['improperlyConfiguredCron']); + $this->assertEquals($expected, $response); } - + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ public function testGetStatusNoCorrectCronAjax() { - $this->beforeStatus('ajax'); - + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, true], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('ajax')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(true)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => true, + 'incorrectDbCharset' => false, + ], + ]; $response = $this->service->getStatus(); - $this->assertTrue($response['warnings']['improperlyConfiguredCron']); + $this->assertEquals($expected, $response); } - - + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ public function testGetStatusNoCorrectCronTurnedOff() { - $this->beforeStatus('ajax', false); - + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, false], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('ajax')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(true)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => false, + ], + ]; $response = $this->service->getStatus(); - $this->assertFalse($response['warnings']['improperlyConfiguredCron']); + $this->assertEquals($expected, $response); } + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ + public function testGetStatusReportsNon4ByteText() + { + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, false], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('ajax')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(false)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => true, + ], + ]; + $response = $this->service->getStatus(); + $this->assertEquals($expected, $response); + } } \ No newline at end of file diff --git a/tests/Unit/Utility/OPMLExporterTest.php b/tests/Unit/Utility/OPMLExporterTest.php index 80cbaf9501..8c7c3c9236 100644 --- a/tests/Unit/Utility/OPMLExporterTest.php +++ b/tests/Unit/Utility/OPMLExporterTest.php @@ -32,7 +32,7 @@ class OPMLExporterTest extends TestCase /** @var Folder */ private $folder2; - protected function setUp() + protected function setUp(): void { $this->exporter = new OPMLExporter(); $this->folder1 = new Folder(); @@ -55,7 +55,7 @@ protected function setUp() } - private function getAttribute($item, $name) + private function getAttribute($item, $name) { // used to fix scrutinizer errors if ($item instanceof \DOMElement) { @@ -75,7 +75,7 @@ public function testBuildEmpty() } - public function testBuildReturnsFolders() + public function testBuildReturnsFolders() { $result = $this->exporter->build([$this->folder1, $this->folder2], []); $xpath = new \DOMXpath($result); @@ -101,7 +101,7 @@ public function testBuildReturnsFolders() } - public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() + public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() { $result = $this->exporter->build([], [$this->feed1, $this->feed2]); $xpath = new \DOMXpath($result); @@ -127,7 +127,7 @@ public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() } - public function testBuildReturnsFeedsAndFolders() + public function testBuildReturnsFeedsAndFolders() { $result = $this->exporter->build( [$this->folder1, $this->folder2], diff --git a/tests/Unit/Utility/UpdaterTest.php b/tests/Unit/Utility/UpdaterTest.php index 3a285ccfdd..3cd81de021 100644 --- a/tests/Unit/Utility/UpdaterTest.php +++ b/tests/Unit/Utility/UpdaterTest.php @@ -28,7 +28,7 @@ class UpdaterTest extends TestCase private $itemService; private $updater; - protected function setUp() + protected function setUp(): void { $this->folderService = $this->getMockBuilder(FolderService::class) ->disableOriginalConstructor() @@ -46,7 +46,7 @@ protected function setUp() ); } - public function testBeforeUpdate() + public function testBeforeUpdate() { $this->folderService->expects($this->once()) ->method('purgeDeleted'); @@ -56,14 +56,14 @@ public function testBeforeUpdate() } - public function testAfterUpdate() + public function testAfterUpdate() { $this->itemService->expects($this->once()) ->method('autoPurgeOld'); $this->updater->afterUpdate(); } - public function testUpdate() + public function testUpdate() { $this->feedService->expects($this->once()) ->method('updateAll');
- - t('Maximum feed page size')); ?> - -
- - t( - 'Maximum feed size in bytes. If the RSS/Atom page is ' . - 'bigger than this value, the update will be aborted.' - )); ?> - -
diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index 3d1ea71f4f..626b8f9a99 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -20,7 +20,7 @@ class FeedMapperTest extends IntegrationTest { - public function testFind() + public function testFind() { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -31,16 +31,14 @@ public function testFind() $this->assertEquals($feed->getLink(), $fetched->getLink()); } - /** - * @expectedException OCP\AppFramework\Db\DoesNotExistException - */ - public function testFindNotExisting() + public function testFindNotExisting() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->feedMapper->find(0, $this->user); } - public function testFindAll() + public function testFindAll() { $feeds = [ [ @@ -56,23 +54,23 @@ public function testFindAll() $fetched = $this->feedMapper->findAll(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testFindAllEmpty() + public function testFindAllEmpty() { $feeds = $this->feedMapper->findAll(); - $this->assertInternalType('array', $feeds); + $this->assertIsArray($feeds); $this->assertCount(0, $feeds); } - public function testFindAllFromUser() + public function testFindAllFromUser() { $feeds = [ [ @@ -88,7 +86,7 @@ public function testFindAllFromUser() $fetched = $this->feedMapper->findAllFromUser($this->user); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(1, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); @@ -96,16 +94,16 @@ public function testFindAllFromUser() } - public function testFindAllFromUserNotExisting() + public function testFindAllFromUserNotExisting() { $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(0, $fetched); } - public function testFindByUrlHash() + public function testFindByUrlHash() { $feed = new FeedFixture( [ @@ -124,8 +122,9 @@ public function testFindByUrlHash() /** * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException */ - public function testFindByUrlHashMoreThanOneResult() + public function testFindByUrlHashMoreThanOneResult() { + $this->expectException('OCP\AppFramework\Db\MultipleObjectsReturnedException'); $feed1 = $this->feedMapper->insert( new FeedFixture( [ @@ -148,13 +147,14 @@ public function testFindByUrlHashMoreThanOneResult() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindByUrlHashNotExisting() + public function testFindByUrlHashNotExisting() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->feedMapper->findByUrlHash('some random hash', $this->user); } - public function testDelete() + public function testDelete() { $this->loadFixtures('default'); @@ -178,7 +178,7 @@ public function testDelete() $this->assertCount(0, $items); } - public function testGetToDelete() + public function testGetToDelete() { $this->loadFeedFixtures( [ @@ -191,14 +191,14 @@ public function testGetToDelete() $fetched = $this->feedMapper->getToDelete(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(3, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteOlderThan() + public function testGetToDeleteOlderThan() { $this->loadFeedFixtures( [ @@ -211,14 +211,14 @@ public function testGetToDeleteOlderThan() $fetched = $this->feedMapper->getToDelete(1000); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteUser() + public function testGetToDeleteUser() { $this->loadFeedFixtures( [ @@ -231,22 +231,22 @@ public function testGetToDeleteUser() $fetched = $this->feedMapper->getToDelete(2000, $this->user); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteEmpty() + public function testGetToDeleteEmpty() { $fetched = $this->feedMapper->getToDelete(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(0, $fetched); } - public function testDeleteUser() + public function testDeleteUser() { $this->loadFixtures('default'); @@ -263,7 +263,10 @@ public function testDeleteUser() $this->assertCount(0, $items); } - public function testDeleteUserNotExisting() + /** + * @coversNothing + */ + public function testDeleteUserNotExisting() { $this->feedMapper->deleteUser('notexistinguser'); } diff --git a/tests/Integration/Db/FolderMapperTest.php b/tests/Integration/Db/FolderMapperTest.php deleted file mode 100644 index 889ac3e7c1..0000000000 --- a/tests/Integration/Db/FolderMapperTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - -namespace OCA\News\Tests\Integration\Db; - -use OCA\News\Tests\Integration\IntegrationTest; - -class FolderMapperTest extends IntegrationTest -{ - - - public function testFind() - { - - } - - - /* TBD - public function testFindByName () { - - } - - - public function testFindAllFromUser () { - - } - - - public function testDelete () { - - } - - - public function testGetToDelete () { - - } - - - public function testDeleteUser () { - - }*/ - - - -} diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index e510aab964..026834e6b1 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -18,7 +18,7 @@ class ItemMapperTest extends IntegrationTest { - public function testFind() + public function testFind() { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -38,7 +38,7 @@ public function testFind() * @param $title * @return mixed */ - private function whereTitleId($title) + private function whereTitleId($title) { return $this->findItemByTitle($title)->getId(); } @@ -46,8 +46,9 @@ private function whereTitleId($title) /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFeed() + public function testFindNotFoundWhenDeletedFeed() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('not found feed'); @@ -58,8 +59,9 @@ public function testFindNotFoundWhenDeletedFeed() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFolder() + public function testFindNotFoundWhenDeletedFolder() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); @@ -68,7 +70,7 @@ public function testFindNotFoundWhenDeletedFolder() } - private function deleteReadOlderThanThreshold() + private function deleteReadOlderThanThreshold() { $this->loadFixtures('default'); @@ -84,8 +86,9 @@ private function deleteReadOlderThanThreshold() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdOne() + public function testDeleteOlderThanThresholdOne() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('del1'); @@ -97,8 +100,9 @@ public function testDeleteOlderThanThresholdOne() /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdTwo() + public function testDeleteOlderThanThresholdTwo() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('del2'); @@ -108,7 +112,7 @@ public function testDeleteOlderThanThresholdTwo() } - public function testStarredCount() + public function testStarredCount() { $this->loadFixtures('default'); @@ -117,7 +121,7 @@ public function testStarredCount() } - public function testReadAll() + public function testReadAll() { $this->loadFixtures('default'); @@ -146,7 +150,7 @@ public function testReadAll() } - public function testReadFolder() + public function testReadFolder() { $this->loadFixtures('default'); @@ -178,7 +182,7 @@ public function testReadFolder() } - public function testReadFeed() + public function testReadFeed() { $this->loadFixtures('default'); @@ -209,7 +213,7 @@ public function testReadFeed() } - public function testDeleteUser() + public function testDeleteUser() { $this->loadFixtures('default'); @@ -219,7 +223,7 @@ public function testDeleteUser() $this->assertEquals(0, $id); } - public function testGetNewestItemId() + public function testGetNewestItemId() { $this->loadFixtures('default'); @@ -229,7 +233,7 @@ public function testGetNewestItemId() $this->assertEquals($itemId, $id); } - public function testFindAllUnreadOrStarred() + public function testFindAllUnreadOrStarred() { $this->loadFixtures('default'); @@ -238,7 +242,7 @@ public function testFindAllUnreadOrStarred() } - public function testReadItem() + public function testReadItem() { $this->loadFixtures('readitem'); // assert that all items are unread @@ -277,7 +281,7 @@ public function testReadItem() } } - public function testUnreadItem() + public function testUnreadItem() { $this->loadFixtures('readitem'); // unread an item diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php deleted file mode 100644 index 60a292afc3..0000000000 --- a/tests/Unit/Config/ConfigTest.php +++ /dev/null @@ -1,261 +0,0 @@ - - * @author Bernhard Posselt - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - */ - -namespace OCA\News\Tests\Unit\Config; - -use OCA\News\Config\Config; -use OCP\Files\File; -use OCP\Files\Folder; -use OCP\ILogger; -use PHPUnit\Framework\TestCase; - -class ConfigTest extends TestCase -{ - - private $fileSystem; - private $config; - private $configPath; - private $loggerParams; - - public function setUp() - { - $this->logger = $this->getMockBuilder('OCA\News\Utility\PsrLogger') - ->disableOriginalConstructor() - ->getMock(); - $this->fileSystem = $this->getMockBuilder(Folder::class)->getMock(); - $this->loggerParams = ['hi']; - $this->config = new Config( - $this->fileSystem, - $this->logger, - $this->loggerParams - ); - $this->configPath = 'config.json'; - } - - - public function testDefaults() - { - $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); - $this->assertEquals(200, $this->config->getAutoPurgeCount()); - $this->assertEquals(10, $this->config->getMaxRedirects()); - $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); - $this->assertEquals(3600, $this->config->getUpdateInterval()); - $this->assertEquals(true, $this->config->getUseCronUpdates()); - $this->assertEquals('', $this->config->getExploreUrl()); - $this->assertEquals(1024*1024*100, $this->config->getMaxSize()); - } - - - public function testRead() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will( - $this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' - ) - ); - - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(true, $this->config->getUseCronUpdates()); - } - - - public function testReadIgnoresVeryLowPurgeInterval() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('autoPurgeMinimumInterval = 59')); - - $this->config->read($this->configPath); - - $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); - } - - - - public function testReadBool() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will( - $this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false' - ) - ); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(false, $this->config->getUseCronUpdates()); - } - - - public function testReadLogsInvalidValue() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('autoPurgeCounts = 3')); - $this->logger->expects($this->once()) - ->method('warning') - ->with( - $this->equalTo( - 'Configuration value "autoPurgeCounts" ' . - 'does not exist. Ignored value.' - ), - $this->equalTo($this->loggerParams) - ); - - $this->config->read($this->configPath); - } - - - public function testReadLogsInvalidINI() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('')); - $this->logger->expects($this->once()) - ->method('warning') - ->with( - $this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams) - ); - - $this->config->read($this->configPath); - } - - - public function testWrite() - { - $json = 'autoPurgeMinimumInterval = 60' . "\n" . - 'autoPurgeCount = 3' . "\n" . - 'maxRedirects = 10' . "\n" . - 'maxSize = 399' . "\n" . - 'exploreUrl = http://google.de' . "\n" . - 'feedFetcherTimeout = 60' . "\n" . - 'updateInterval = 3600' . "\n" . - 'useCronUpdates = true'; - $this->config->setAutoPurgeCount(3); - $this->config->setMaxSize(399); - $this->config->setExploreUrl('http://google.de'); - - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('putContent') - ->with($this->equalTo($json)); - - $this->config->write($this->configPath); - } - - - - public function testReadingNonExistentConfigWillWriteDefaults() - { - $this->fileSystem->expects($this->once()) - ->method('nodeExists') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue(false)); - - $this->config->setUseCronUpdates(false); - - $json = 'autoPurgeMinimumInterval = 60' . "\n" . - 'autoPurgeCount = 200' . "\n" . - 'maxRedirects = 10' . "\n" . - 'maxSize = 104857600' . "\n" . - 'exploreUrl = ' . "\n" . - 'feedFetcherTimeout = 60' . "\n" . - 'updateInterval = 3600' . "\n" . - 'useCronUpdates = false'; - - $this->fileSystem->expects($this->once()) - ->method('newFile') - ->with($this->equalTo($this->configPath)); - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('putContent') - ->with($this->equalTo($json)); - - $this->config->read($this->configPath, true); - } - - - public function testNoLowMinimumAutoPurgeInterval() - { - $this->config->setAutoPurgeMinimumInterval(59); - $interval = $this->config->getAutoPurgeMinimumInterval(); - - $this->assertSame(60, $interval); - } - - - public function testMinimumAutoPurgeInterval() - { - $this->config->setAutoPurgeMinimumInterval(61); - $interval = $this->config->getAutoPurgeMinimumInterval(); - - $this->assertSame(61, $interval); - } - - public function testMaxRedirects() - { - $this->config->setMaxRedirects(21); - $redirects = $this->config->getMaxRedirects(); - - $this->assertSame(21, $redirects); - } - - public function testFeedFetcherTimeout() - { - $this->config->setFeedFetcherTimeout(2); - $timout = $this->config->getFeedFetcherTimeout(); - - $this->assertSame(2, $timout); - } -} diff --git a/tests/Unit/Controller/AdminControllerTest.php b/tests/Unit/Controller/AdminControllerTest.php index b0b5510068..81490bb6fa 100644 --- a/tests/Unit/Controller/AdminControllerTest.php +++ b/tests/Unit/Controller/AdminControllerTest.php @@ -13,82 +13,84 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; use OCA\News\Controller\AdminController; use OCA\News\Service\ItemService; +use OCP\IConfig; use OCP\IRequest; use PHPUnit\Framework\TestCase; class AdminControllerTest extends TestCase { - + /** + * @var string + */ private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var AdminController + */ private $controller; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $config; - private $configPath; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + */ private $itemService; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder(ItemService::class) ->disableOriginalConstructor() ->getMock(); - $this->configPath = 'my.ini'; - $this->controller = new AdminController( - $this->appName, $this->request, - $this->config, $this->itemService, $this->configPath - ); + $this->controller = new AdminController($this->appName, $this->request, $this->config, $this->itemService); } - - public function testIndex() + /** + * Test \OCA\News\Controller\AdminController::index + */ + public function testIndex() { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5, - 'maxSize' => 7, + 'useCronUpdates' => false, 'exploreUrl' => 'test', - 'updateInterval' => 3600 + 'updateInterval' => 3601 ]; - $this->config->expects($this->once()) - ->method('getAutoPurgeMinimumInterval') - ->will($this->returnValue($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('getMaxRedirects') - ->will($this->returnValue($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('getMaxSize') - ->will($this->returnValue($expected['maxSize'])); - $this->config->expects($this->once()) - ->method('getExploreUrl') - ->will($this->returnValue($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('getUpdateInterval') - ->will($this->returnValue($expected['updateInterval'])); + $map = [ + ['news','autoPurgeMinimumInterval', 60, 1], + ['news','autoPurgeCount', 200, 2], + ['news','maxRedirects', 10, 3], + ['news','feedFetcherTimeout', 60, 4], + ['news','useCronUpdates', true, false,], + ['news','exploreUrl', '', 'test'], + ['news','updateInterval', 3600, 3601] + ]; + $this->config->expects($this->exactly(count($map))) + ->method('getAppValue') + ->will($this->returnValueMap($map)); $response = $this->controller->index(); $data = $response->getParams(); @@ -101,75 +103,48 @@ public function testIndex() } - public function testUpdate() + public function testUpdate() { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5, - 'maxSize' => 7, + 'useCronUpdates' => false, 'exploreUrl' => 'test', - 'updateInterval' => 3600 + 'updateInterval' => 3601 ]; - $this->config->expects($this->once()) - ->method('setAutoPurgeMinimumInterval') - ->with($this->equalTo($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('setAutoPurgeCount') - ->with($this->equalTo($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('setMaxRedirects') - ->with($this->equalTo($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('setFeedFetcherTimeout') - ->with($this->equalTo($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('setUseCronUpdates') - ->with($this->equalTo($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('setExploreUrl') - ->with($this->equalTo($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('setUpdateInterval') - ->with($this->equalTo($expected['updateInterval'])); - $this->config->expects($this->once()) - ->method('write') - ->with($this->equalTo($this->configPath)); - - $this->config->expects($this->once()) - ->method('getAutoPurgeMinimumInterval') - ->will($this->returnValue($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('getMaxRedirects') - ->will($this->returnValue($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('getMaxSize') - ->will($this->returnValue($expected['maxSize'])); - $this->config->expects($this->once()) - ->method('getExploreUrl') - ->will($this->returnValue($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('getUpdateInterval') - ->will($this->returnValue($expected['updateInterval'])); + $this->config->expects($this->exactly(count($expected))) + ->method('setAppValue') + ->withConsecutive( + ['news','autoPurgeMinimumInterval', 1], + ['news','autoPurgeCount', 2], + ['news','maxRedirects', 3], + ['news','feedFetcherTimeout', 4], + ['news','useCronUpdates', false], + ['news','exploreUrl', 'test'], + ['news','updateInterval', 3601] + ); + + $map = [ + ['news','autoPurgeMinimumInterval', 60, 1], + ['news','autoPurgeCount', 200, 2], + ['news','maxRedirects', 10, 3], + ['news','feedFetcherTimeout', 60, 4], + ['news','useCronUpdates', true, false,], + ['news','exploreUrl', '', 'test'], + ['news','updateInterval', 3600, 3601] + ]; + $this->config->expects($this->exactly(count($map))) + ->method('getAppValue') + ->will($this->returnValueMap($map)); $response = $this->controller->update( $expected['autoPurgeMinimumInterval'], $expected['autoPurgeCount'], $expected['maxRedirects'], $expected['feedFetcherTimeout'], - $expected['maxSize'], $expected['useCronUpdates'], $expected['exploreUrl'], $expected['updateInterval'] diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 84ded5c6f3..94ffa1ed1a 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.php @@ -41,7 +41,7 @@ class ExportControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'john'; diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index cc387161d9..c889a54b3e 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -44,7 +44,7 @@ class FeedApiControllerTest extends TestCase private $logger; private $loggerParams; - protected function setUp() + protected function setUp(): void { $this->loggerParams = ['hi']; $this->logger = $this->getMockBuilder(ILogger::class) @@ -85,7 +85,7 @@ protected function setUp() } - public function testIndex() + public function testIndex() { $feeds = [new Feed()]; $starredCount = 3; @@ -116,7 +116,7 @@ public function testIndex() } - public function testIndexNoNewestItemId() + public function testIndexNoNewestItemId() { $feeds = [new Feed()]; $starredCount = 3; @@ -145,7 +145,7 @@ public function testIndexNoNewestItemId() } - public function testDelete() + public function testDelete() { $this->feedService->expects($this->once()) ->method('delete') @@ -158,7 +158,7 @@ public function testDelete() } - public function testDeleteDoesNotExist() + public function testDeleteDoesNotExist() { $this->feedService->expects($this->once()) ->method('delete') @@ -176,7 +176,7 @@ public function testDeleteDoesNotExist() } - public function testCreate() + public function testCreate() { $feeds = [new Feed()]; @@ -206,7 +206,7 @@ public function testCreate() } - public function testCreateNoItems() + public function testCreateNoItems() { $feeds = [new Feed()]; @@ -236,7 +236,7 @@ public function testCreateNoItems() - public function testCreateExists() + public function testCreateExists() { $this->feedService->expects($this->once()) ->method('purgeDeleted') @@ -255,7 +255,7 @@ public function testCreateExists() } - public function testCreateError() + public function testCreateError() { $this->feedService->expects($this->once()) ->method('create') @@ -271,7 +271,7 @@ public function testCreateError() } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('readFeed') @@ -285,7 +285,7 @@ public function testRead() } - public function testMove() + public function testMove() { $this->feedService->expects($this->once()) ->method('patch') @@ -299,7 +299,7 @@ public function testMove() } - public function testMoveDoesNotExist() + public function testMoveDoesNotExist() { $this->feedService->expects($this->once()) ->method('patch') @@ -315,7 +315,7 @@ public function testMoveDoesNotExist() } - public function testRename() + public function testRename() { $feedId = 3; $feedTitle = 'test'; @@ -332,7 +332,7 @@ public function testRename() } - public function testRenameError() + public function testRenameError() { $feedId = 3; $feedTitle = 'test'; @@ -370,7 +370,7 @@ public function testfromAllUsers() } - public function testUpdate() + public function testUpdate() { $feedId = 3; $userId = 'hi'; @@ -383,7 +383,7 @@ public function testUpdate() } - public function testUpdateError() + public function testUpdateError() { $feedId = 3; $userId = 'hi'; diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 4703d307af..9a3114da0d 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -45,7 +45,7 @@ class FeedControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jack'; @@ -398,7 +398,7 @@ public function testUpdateReturnsJSONError() } - public function testImport() + public function testImport() { $feed = new Feed(); @@ -426,7 +426,7 @@ public function testImport() } - public function testImportCreatesNoAdditionalFeed() + public function testImportCreatesNoAdditionalFeed() { $this->feedService->expects($this->once()) ->method('importArticles') @@ -467,7 +467,7 @@ public function testReadFeed() } - public function testRestore() + public function testRestore() { $this->feedService->expects($this->once()) ->method('unmarkDeleted') @@ -492,7 +492,7 @@ public function testRestoreDoesNotExist() $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } - public function testPatch() + public function testPatch() { $expected = [ 'pinned' => true, diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index 3a93a460a3..311212169e 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -44,7 +44,7 @@ class FolderApiControllerTest extends TestCase private $request; private $msg; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) @@ -79,7 +79,7 @@ protected function setUp() } - public function testIndex() + public function testIndex() { $folders = [new Folder()]; @@ -98,7 +98,7 @@ public function testIndex() } - public function testCreate() + public function testCreate() { $folderName = 'test'; $folder = new Folder(); @@ -122,7 +122,7 @@ public function testCreate() } - public function testCreateAlreadyExists() + public function testCreateAlreadyExists() { $msg = 'exists'; @@ -141,7 +141,7 @@ public function testCreateAlreadyExists() } - public function testCreateInvalidFolderName() + public function testCreateInvalidFolderName() { $msg = 'exists'; @@ -162,7 +162,7 @@ public function testCreateInvalidFolderName() } - public function testDelete() + public function testDelete() { $folderId = 23; $this->folderService->expects($this->once()) @@ -173,7 +173,7 @@ public function testDelete() } - public function testDeleteDoesNotExist() + public function testDeleteDoesNotExist() { $folderId = 23; @@ -193,7 +193,7 @@ public function testDeleteDoesNotExist() } - public function testUpdate() + public function testUpdate() { $folderId = 23; $folderName = 'test'; @@ -209,7 +209,7 @@ public function testUpdate() $this->folderAPI->update($folderId, $folderName); } - public function testUpdateDoesNotExist() + public function testUpdateDoesNotExist() { $folderId = 23; $folderName = 'test'; @@ -230,7 +230,7 @@ public function testUpdateDoesNotExist() } - public function testUpdateExists() + public function testUpdateExists() { $folderId = 23; $folderName = 'test'; @@ -251,7 +251,7 @@ public function testUpdateExists() } - public function testUpdateInvalidFolderName() + public function testUpdateInvalidFolderName() { $folderId = 23; $folderName = ''; @@ -274,7 +274,7 @@ public function testUpdateInvalidFolderName() } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('readFolder') diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php index b9e0485a4c..abe1ebd7ab 100644 --- a/tests/Unit/Controller/FolderControllerTest.php +++ b/tests/Unit/Controller/FolderControllerTest.php @@ -44,7 +44,7 @@ class FolderControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jack'; diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 5733a0c871..412b9dd517 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -39,7 +39,7 @@ class ItemApiControllerTest extends TestCase private $request; private $msg; - protected function setUp() + protected function setUp(): void { $this->user = 'tom'; $this->appName = 'news'; @@ -71,7 +71,7 @@ protected function setUp() } - public function testIndex() + public function testIndex() { $item = new Item(); $item->setId(5); @@ -102,7 +102,7 @@ public function testIndex() } - public function testIndexDefaultBatchSize() + public function testIndexDefaultBatchSize() { $item = new Item(); $item->setId(5); @@ -133,7 +133,7 @@ public function testIndexDefaultBatchSize() } - public function testUpdated() + public function testUpdated() { $item = new Item(); $item->setId(5); @@ -162,7 +162,7 @@ public function testUpdated() } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('read') @@ -176,7 +176,7 @@ public function testRead() } - public function testReadDoesNotExist() + public function testReadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') @@ -194,7 +194,7 @@ public function testReadDoesNotExist() } - public function testUnread() + public function testUnread() { $this->itemService->expects($this->once()) ->method('read') @@ -208,7 +208,7 @@ public function testUnread() } - public function testUnreadDoesNotExist() + public function testUnreadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') @@ -226,7 +226,7 @@ public function testUnreadDoesNotExist() } - public function testStar() + public function testStar() { $this->itemService->expects($this->once()) ->method('star') @@ -241,7 +241,7 @@ public function testStar() } - public function testStarDoesNotExist() + public function testStarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') @@ -259,7 +259,7 @@ public function testStarDoesNotExist() } - public function testUnstar() + public function testUnstar() { $this->itemService->expects($this->once()) ->method('star') @@ -274,7 +274,7 @@ public function testUnstar() } - public function testUnstarDoesNotExist() + public function testUnstarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') @@ -292,7 +292,7 @@ public function testUnstarDoesNotExist() } - public function testReadAll() + public function testReadAll() { $this->itemService->expects($this->once()) ->method('readAll') @@ -306,7 +306,7 @@ public function testReadAll() - public function testReadMultiple() + public function testReadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -326,7 +326,7 @@ public function testReadMultiple() } - public function testReadMultipleDoesntCareAboutException() + public function testReadMultipleDoesntCareAboutException() { $this->itemService->expects($this->at(0)) ->method('read') @@ -342,7 +342,7 @@ public function testReadMultipleDoesntCareAboutException() } - public function testUnreadMultiple() + public function testUnreadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -362,7 +362,7 @@ public function testUnreadMultiple() } - public function testStarMultiple() + public function testStarMultiple() { $ids = [ [ @@ -395,7 +395,7 @@ public function testStarMultiple() } - public function testStarMultipleDoesntCareAboutException() + public function testStarMultipleDoesntCareAboutException() { $ids = [ [ @@ -423,7 +423,7 @@ public function testStarMultipleDoesntCareAboutException() } - public function testUnstarMultiple() + public function testUnstarMultiple() { $ids = [ [ diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index b24d741487..9dbcf15ce8 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -43,7 +43,7 @@ class ItemControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jackob'; @@ -96,7 +96,7 @@ public function testReadDoesNotExist() } - public function testReadMultiple() + public function testReadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -116,7 +116,7 @@ public function testReadMultiple() } - public function testReadMultipleDontStopOnException() + public function testReadMultipleDontStopOnException() { $this->itemService->expects($this->at(0)) ->method('read') diff --git a/tests/Unit/Controller/JSONHttpErrorTest.php b/tests/Unit/Controller/JSONHttpErrorTest.php index bf043bf547..c02b60c9e3 100644 --- a/tests/Unit/Controller/JSONHttpErrorTest.php +++ b/tests/Unit/Controller/JSONHttpErrorTest.php @@ -26,7 +26,7 @@ class JSONHttpErrorTest extends TestCase { - public function testError() + public function testError() { $ex = new \Exception('hi'); $test = new Test(); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index ce7a3e73d0..69fed0d77b 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -13,7 +13,7 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; +use OC\L10N\L10N; use OCA\News\Controller\PageController; use \OCA\News\Db\FeedType; use OCA\News\Explore\RecommendedSites; @@ -28,26 +28,51 @@ class PageControllerTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $settings; - private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var PageController + */ private $controller; - private $user; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator + */ private $urlGenerator; - private $appConfig; + + /** + * @var array + */ private $configData; - private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|RecommendedSites + */ private $recommended; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|StatusService + */ private $status; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { - $this->appName = 'news'; - $this->user = 'becka'; $this->configData = [ 'name' => 'AppTest', 'id' => 'apptest', @@ -70,12 +95,6 @@ public function setUp() $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); - $this->appConfig = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); - $this->config = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); $this->recommended = $this->getMockBuilder(RecommendedSites::class) ->disableOriginalConstructor() ->getMock(); @@ -83,10 +102,14 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); $this->controller = new PageController( - $this->appName, $this->request, - $this->settings, $this->urlGenerator, $this->config, - $this->l10n, $this->recommended, $this->status, - $this->user + 'news', + $this->request, + $this->settings, + $this->urlGenerator, + $this->l10n, + $this->recommended, + $this->status, + 'becka' ); } @@ -95,15 +118,7 @@ public function testIndex() { $this->status->expects($this->once()) ->method('getStatus') - ->will( - $this->returnValue( - [ - 'warnings' => [ - 'improperlyConfiguredCron' => false - ] - ] - ) - ); + ->will($this->returnValue(['warnings' => ['improperlyConfiguredCron' => false]])); $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); @@ -130,8 +145,10 @@ public function testIndexNoCorrectCronAjax() $this->assertEquals(true, $response->getParams()['warnings']['improperlyConfiguredCron']); } - - public function testSettings() + /** + * @covers \OCA\News\Controller\PageController::settings + */ + public function testSettings() { $result = [ 'settings' => [ @@ -148,55 +165,23 @@ public function testSettings() $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue(' ')); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') - ->with( - $this->equalTo('news.page.explore'), - $this->equalTo(['lang' => 'en']) - ) + ->with('news.page.explore', ['lang' => 'en']) ->will($this->returnValue('test')); @@ -205,7 +190,7 @@ public function testSettings() } - public function testSettingsExploreUrlSet() + public function testSettingsExploreUrlSet() { $result = [ 'settings' => [ @@ -222,48 +207,19 @@ public function testSettingsExploreUrlSet() $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue('abc')); $this->urlGenerator->expects($this->never()) ->method('getAbsoluteURL'); @@ -273,83 +229,50 @@ public function testSettingsExploreUrlSet() $this->assertEquals($result, $response); } - public function testUpdateSettings() + /** + * @covers \OCA\News\Controller\PageController::updateSettings + */ + public function testUpdateSettings() { $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'showAll', '1'); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'compact', '1'); $this->settings->expects($this->at(2)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll'), - $this->equalTo('0') - ); + ->with('becka', 'news', 'preventReadOnScroll', '0'); $this->settings->expects($this->at(3)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'oldestFirst', '1'); $this->settings->expects($this->at(4)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand'), - $this->equalTo('1') - ); - $this->controller->updateSettings(true, true, false, true, true); + ->with('becka', 'news', 'compactExpand', '1'); + $this->controller->updateSettings(true, true, false, true, true); } - public function testExplore() { $in = 'test'; $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId'), - $this->equalTo(0) - ); + ->with('becka', 'news', 'lastViewedFeedId', 0); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType'), - $this->equalTo(FeedType::EXPLORE) - ); + ->with('becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE); $this->recommended->expects($this->once()) ->method('forLanguage') - ->with($this->equalTo('en')) + ->with('en') ->will($this->returnValue($in)); - $out = $this->controller->explore('en'); $this->assertEquals($in, $out); + } } diff --git a/tests/Unit/Controller/UserApiControllerTest.php b/tests/Unit/Controller/UserApiControllerTest.php index d9df73fe73..dd0140c81e 100644 --- a/tests/Unit/Controller/UserApiControllerTest.php +++ b/tests/Unit/Controller/UserApiControllerTest.php @@ -33,7 +33,7 @@ class UserApiControllerTest extends TestCase private $user; private $file; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) @@ -59,7 +59,7 @@ protected function setUp() } - private function expectUser($uid, $displayName, $lastLogin) + private function expectUser($uid, $displayName, $lastLogin) { $this->userSession->expects($this->any()) ->method('getUser') @@ -75,7 +75,7 @@ private function expectUser($uid, $displayName, $lastLogin) ->will($this->returnValue($displayName)); } - private function expectImg($isJpg, $isPng, $user, $exists, $data) + private function expectImg($isJpg, $isPng, $user, $exists, $data) { $jpg = '/' . $user . '/' . 'avatar.jpg'; $png = '/' . $user . '/' . 'avatar.png'; @@ -98,7 +98,7 @@ private function expectImg($isJpg, $isPng, $user, $exists, $data) ->will($this->returnValue($data)); } - public function testGetJpeg() + public function testGetJpeg() { $this->expectUser('john', 'John', 123); $this->expectImg(true, false, 'john', true, 'hi'); @@ -117,7 +117,7 @@ public function testGetJpeg() $this->assertEquals($expected, $result); } - public function testGetPng() + public function testGetPng() { $this->expectUser('john', 'John', 123); $this->expectImg(false, true, 'john', false, 'hi'); @@ -136,7 +136,7 @@ public function testGetPng() $this->assertEquals($expected, $result); } - public function testNoAvatar() + public function testNoAvatar() { $this->expectUser('john', 'John', 123); $this->expectImg(false, false, 'john', false, 'hi'); diff --git a/tests/Unit/Controller/UtilityApiControllerTest.php b/tests/Unit/Controller/UtilityApiControllerTest.php index 37070b1609..32a66b2e81 100644 --- a/tests/Unit/Controller/UtilityApiControllerTest.php +++ b/tests/Unit/Controller/UtilityApiControllerTest.php @@ -37,7 +37,7 @@ class UtilityApiControllerTest extends TestCase private $appName; private $status; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->settings = $this->getMockBuilder(IConfig::class) diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index 11c411b5e6..f8544da650 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.php @@ -28,7 +28,7 @@ class FolderMapperTest extends MapperTestUtility /** @var string */ private $user; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/Db/ItemTest.php b/tests/Unit/Db/ItemTest.php index 6b63f86855..c9a353ea73 100644 --- a/tests/Unit/Db/ItemTest.php +++ b/tests/Unit/Db/ItemTest.php @@ -22,11 +22,11 @@ class ItemTest extends TestCase { /** - * @var Item + * @var Item */ private $item; - protected function setUp() + protected function setUp(): void { $this->item = new Item(); $this->item->setStatus(0); @@ -65,7 +65,7 @@ public function testSetUnstarred() } - public function testToAPI() + public function testToAPI() { $item = new Item(); $item->setId(3); @@ -117,7 +117,7 @@ public function testToAPI() } - public function testJSONSerialize() + public function testJSONSerialize() { $item = new Item(); $item->setId(3); @@ -167,7 +167,7 @@ public function testJSONSerialize() ); } - public function testToExport() + public function testToExport() { $item = new Item(); $item->setId(3); @@ -216,7 +216,7 @@ public function testToExport() } - private function createImportItem($isRead) + private function createImportItem($isRead) { $item = new Item(); $item->setGuid('guid'); @@ -242,7 +242,7 @@ private function createImportItem($isRead) } - public function testSearchIndex() + public function testSearchIndex() { $item = new Item(); $item->setBody('somEthäng'); @@ -255,7 +255,7 @@ public function testSearchIndex() } - public function testFromImport() + public function testFromImport() { $item = $this->createImportItem(false); @@ -282,7 +282,7 @@ public function testFromImport() } - public function testFromImportRead() + public function testFromImportRead() { $item = $this->createImportItem(true); @@ -315,7 +315,7 @@ public function testSetAuthor() $item = new Item(); $item->setAuthor('my link'); $this->assertEquals('my link', $item->getAuthor()); - $this->assertContains('author', $item->getUpdatedFields()); + $this->assertArrayHasKey('author', $item->getUpdatedFields()); } @@ -324,11 +324,11 @@ public function testSetTitle() $item = new Item(); $item->setTitle('my link'); $this->assertEquals('my link', $item->getTitle()); - $this->assertContains('title', $item->getUpdatedFields()); + $this->assertArrayHasKey('title', $item->getUpdatedFields()); } - public function testSetXSSUrl() + public function testSetXSSUrl() { $item = new Item(); $item->setUrl('javascript:alert()'); @@ -336,7 +336,7 @@ public function testSetXSSUrl() } - public function testSetMagnetUrl() + public function testSetMagnetUrl() { $item = new Item(); $item->setUrl('magnet://link.com'); @@ -344,7 +344,7 @@ public function testSetMagnetUrl() } - public function testMakeLinksInBodyOpenNewTab() + public function testMakeLinksInBodyOpenNewTab() { $item = new Item(); $item->setBody("ha"); @@ -354,7 +354,7 @@ public function testMakeLinksInBodyOpenNewTab() ); } - public function testComputeFingerPrint() + public function testComputeFingerPrint() { $title = 'a'; $body = 'b'; diff --git a/tests/Unit/Db/MapperFactoryTest.php b/tests/Unit/Db/MapperFactoryTest.php index 697a62beee..97680e20bb 100644 --- a/tests/Unit/Db/MapperFactoryTest.php +++ b/tests/Unit/Db/MapperFactoryTest.php @@ -29,26 +29,26 @@ class MapperFactoryTest extends TestCase private $db; private $settings; - public function setUp() + public function setUp(): void { $this->db = $this->getMockBuilder(IDBConnection::class) ->disableOriginalConstructor() ->getMock(); } - public function testGetItemMapperSqlite() + public function testGetItemMapperSqlite() { $factory = new MapperFactory($this->db, 'sqlite', new Time()); $this->assertTrue($factory->build() instanceof ItemMapper); } - public function testGetItemMapperPostgres() + public function testGetItemMapperPostgres() { $factory = new MapperFactory($this->db, 'pgsql', new Time()); $this->assertTrue($factory->build() instanceof ItemMapper); } - public function testGetItemMapperMysql() + public function testGetItemMapperMysql() { $factory = new MapperFactory($this->db, 'mysql', new Time()); $this->assertTrue($factory->build() instanceof MysqlMapper); diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php index 5417e16bc4..b414b43e3f 100644 --- a/tests/Unit/Db/MapperTestUtility.php +++ b/tests/Unit/Db/MapperTestUtility.php @@ -43,7 +43,7 @@ abstract class MapperTestUtility extends TestCase * Run this function before the actual test to either set or initialize the * db. After this the db can be accessed by using $this->db */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -64,7 +64,7 @@ protected function setUp() * @param array $array * @return bool true if associative */ - private function isAssocArray(array $array) + private function isAssocArray(array $array) { return array_values($array) !== $array; } @@ -75,7 +75,7 @@ private function isAssocArray(array $array) * @param $value * @return PDO constant */ - private function getPDOType($value) + private function getPDOType($value) { switch (gettype($value)) { case 'integer': diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php index f50912f49f..6360973de1 100644 --- a/tests/Unit/Fetcher/FeedFetcherTest.php +++ b/tests/Unit/Fetcher/FeedFetcherTest.php @@ -25,7 +25,9 @@ use OCA\News\Fetcher\FeedFetcher; use OCA\News\Utility\PsrLogger; +use OCP\ILogger; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; /** * Class FeedFetcherTest @@ -83,7 +85,7 @@ class FeedFetcherTest extends TestCase private $feed_mock; /** - * @var PsrLogger + * @var LoggerInterface */ private $logger; @@ -128,7 +130,7 @@ class FeedFetcherTest extends TestCase private $modified; private $location; - protected function setUp() + protected function setUp(): void { $this->l10n = $this->getMockBuilder(\OCP\IL10N::class) ->disableOriginalConstructor() @@ -161,8 +163,7 @@ protected function setUp() $timeFactory->expects($this->any()) ->method('getTime') ->will($this->returnValue($this->time)); - $this->logger = $this->getMockBuilder(PsrLogger::class) - ->disableOriginalConstructor() + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->getMock(); $this->scraper = $this->getMockBuilder(Scraper::class) ->disableOriginalConstructor() @@ -373,7 +374,7 @@ public function testNoFavicon() { $this->setUpReader($this->url); - $feed = $this->createFeed(false); + $feed = $this->createFeed('de-DE', false); $this->favicon->expects($this->never()) ->method('get'); diff --git a/tests/Unit/Fetcher/FetcherTest.php b/tests/Unit/Fetcher/FetcherTest.php index 2549ff6068..a90a2da049 100644 --- a/tests/Unit/Fetcher/FetcherTest.php +++ b/tests/Unit/Fetcher/FetcherTest.php @@ -34,7 +34,7 @@ class FetcherTest extends TestCase private $fetcher; - protected function setUp() + protected function setUp(): void { $this->fetcher = new Fetcher(); } diff --git a/tests/Unit/Fetcher/YoutubeFetcherTest.php b/tests/Unit/Fetcher/YoutubeFetcherTest.php index 1c0c4c8198..e08d35f169 100644 --- a/tests/Unit/Fetcher/YoutubeFetcherTest.php +++ b/tests/Unit/Fetcher/YoutubeFetcherTest.php @@ -35,7 +35,7 @@ class YoutubeFetcherTest extends TestCase */ private $feedFetcher; - public function setUp() + public function setUp(): void { $this->feedFetcher = $this->getMockBuilder(FeedFetcher::class) ->disableOriginalConstructor() diff --git a/tests/Unit/Http/TextDownloadResponseTest.php b/tests/Unit/Http/TextDownloadResponseTest.php index 4021d22aa9..be5f53ec12 100644 --- a/tests/Unit/Http/TextDownloadResponseTest.php +++ b/tests/Unit/Http/TextDownloadResponseTest.php @@ -22,7 +22,7 @@ class TextDownloadResponseTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->response = new TextDownloadResponse( 'sometext', 'file', 'content' @@ -30,7 +30,7 @@ protected function setUp() } - public function testRender() + public function testRender() { $this->assertEquals('sometext', $this->response->render()); } diff --git a/tests/Unit/Http/TextResponseTest.php b/tests/Unit/Http/TextResponseTest.php index 5de374a17b..eaad769b51 100644 --- a/tests/Unit/Http/TextResponseTest.php +++ b/tests/Unit/Http/TextResponseTest.php @@ -21,13 +21,13 @@ class TextResponseTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->response = new TextResponse('sometext'); } - public function testRender() + public function testRender() { $this->assertEquals('sometext', $this->response->render()); } diff --git a/tests/Unit/Migration/MigrateStatusFlagsTest.php b/tests/Unit/Migration/MigrateStatusFlagsTest.php index fb915ec94b..d71f1a54c7 100644 --- a/tests/Unit/Migration/MigrateStatusFlagsTest.php +++ b/tests/Unit/Migration/MigrateStatusFlagsTest.php @@ -22,15 +22,15 @@ class MigrateStatusFlagsTest extends TestCase { /** - * @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject + * @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */ protected $db; /** - * @var IConfig|\PHPUnit_Framework_MockObject_MockObject + * @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $config; /** - * @var IOutput|\PHPUnit_Framework_MockObject_MockObject + * @var IOutput|\PHPUnit_Framework_MockObject_MockObject */ protected $output; @@ -41,7 +41,7 @@ protected function setUp(): void $this->output = $this->createMock(IOutput::class); } - public function testRun() + public function testRun() { $statement = $this->createMock(Statement::class); $statement->expects($this->exactly(1)) @@ -67,11 +67,11 @@ public function testRun() $migration->run($this->output); } - /** - * @expectedException \Exception - */ - public function testRunException() + public function testRunException() { + $this->expectException('\Exception'); + $this->expectExceptionMessage('Could not migrate status'); + $statement = $this->createMock(Statement::class); $statement->expects($this->exactly(1)) ->method('execute') @@ -96,7 +96,7 @@ public function testRunException() $migration->run($this->output); } - public function testRunNewerVersion() + public function testRunNewerVersion() { $this->config->expects($this->exactly(1)) ->method('getAppValue') diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index 76c8f89f61..84c2121eda 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.php @@ -16,7 +16,7 @@ use FeedIo\Reader\ReadErrorException; -use OCA\News\Config\Config; +use OC\L10N\L10N; use OCA\News\Db\FeedMapper; use OCA\News\Db\ItemMapper; use OCA\News\Service\FeedService; @@ -28,6 +28,7 @@ use OCA\News\Db\Item; use OCA\News\Fetcher\Fetcher; use OCA\News\Fetcher\FetcherException; +use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -37,28 +38,60 @@ class FeedServiceTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FeedMapper + */ private $feedMapper; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper + */ + private $itemMapper; + /** @var FeedService */ private $feedService; + + /** + * @var string + */ private $user; - private $response; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|Fetcher + */ private $fetcher; - private $itemMapper; - private $threshold; + + /** + * @var int + */ private $time; - private $importParser; + + /** + * @var int + */ private $autoPurgeMinimumInterval; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|\HTMLPurifier + */ private $purifier; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ILogger + */ private $logger; - private $loggerParams; - protected function setUp() + protected function setUp(): void { $this->logger = $this->getMockBuilder(ILogger::class) ->disableOriginalConstructor() ->getMock(); - $this->loggerParams = ['hi']; + $loggerParams = ['hi']; $this->time = 222; $this->autoPurgeMinimumInterval = 10; $timeFactory = $this->getMockBuilder(Time::class) @@ -86,31 +119,34 @@ protected function setUp() ->getMockBuilder(\HTMLPurifier::class) ->disableOriginalConstructor() ->getMock(); - $config = $this->getMockBuilder(Config::class) + $config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) - ->method('getAutoPurgeMinimumInterval') + ->method('getAppValue') + ->with('news', 'autoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->feedService = new FeedService( $this->feedMapper, $this->fetcher, $this->itemMapper, $this->logger, $this->l10n, - $timeFactory, $config, $this->purifier, $this->loggerParams + $timeFactory, $config, $this->purifier, $loggerParams ); $this->user = 'jack'; } - + /** + * @covers \OCA\News\Service\FeedService::findAll + */ public function testFindAll() { $this->feedMapper->expects($this->once()) ->method('findAllFromUser') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($this->response)); + ->with($this->user) + ->will($this->returnValue([])); $result = $this->feedService->findAll($this->user); - $this->assertEquals($this->response, $result); + $this->assertEquals([], $result); } @@ -120,7 +156,7 @@ public function testCreateDoesNotFindFeed() $url = 'test'; $this->fetcher->expects($this->once()) ->method('fetch') - ->with($this->equalTo($url)) + ->with($url) ->will($this->throwException($ex)); $this->expectException(ServiceNotFoundException::class); $this->feedService->create($url, 1, $this->user); @@ -1145,12 +1181,9 @@ public function testPatchEnableFullText() $this->feedService->patch(3, $this->user, ['fullTextEnabled' => true]); } - - /** - * @expectedException OCA\News\Service\ServiceNotFoundException - */ public function testPatchDoesNotExist() { + $this->expectException('OCA\News\Service\ServiceNotFoundException'); $feed = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->once()) ->method('find') diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 47c1c9a8d8..4086f55e1a 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -13,13 +13,14 @@ namespace OCA\News\Tests\Unit\Service; -use OCA\News\Config\Config; +use OC\L10N\L10N; use \OCA\News\Db\Folder; use OCA\News\Db\FolderMapper; use OCA\News\Service\FolderService; use OCA\News\Service\ServiceConflictException; use OCA\News\Service\ServiceValidationException; use OCA\News\Utility\Time; +use OCP\IConfig; use OCP\IL10N; use PHPUnit\Framework\TestCase; @@ -28,14 +29,37 @@ class FolderServiceTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|FolderMapper + */ private $folderMapper; + + /** + * @var FolderService + */ private $folderService; + + /** + * @var int + */ private $time; + + /** + * @var string + */ private $user; + + /** + * @var int + */ private $autoPurgeMinimumInterval; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; - protected function setUp() + protected function setUp(): void { $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() @@ -51,11 +75,12 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); $this->autoPurgeMinimumInterval = 10; - $config = $this->getMockBuilder(Config::class) + $config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) - ->method('getAutoPurgeMinimumInterval') + ->method('getAppValue') + ->with('news', 'autoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->folderService = new FolderService( $this->folderMapper, $this->l10n, $timeFactory, $config @@ -119,11 +144,10 @@ public function testCreateThrowsExWhenFolderNameExists() $this->folderService->create($folderName, 'john', 3); } - /** - * @expectedException \OCA\News\Service\ServiceValidationException - */ public function testCreateThrowsExWhenFolderNameEmpty() { + $this->expectException('OCA\News\Service\ServiceValidationException'); + $folderName = ''; $this->folderMapper->expects($this->once()) @@ -211,7 +235,7 @@ public function testRenameThrowsExWhenFolderNameEmpty() } - public function testMarkDeleted() + public function testMarkDeleted() { $id = 3; $folder = new Folder(); @@ -230,7 +254,7 @@ public function testMarkDeleted() } - public function testUnmarkDeleted() + public function testUnmarkDeleted() { $id = 3; $folder = new Folder(); @@ -295,7 +319,7 @@ public function testPurgeDeletedNoInterval() } - public function testDeleteUser() + public function testDeleteUser() { $this->folderMapper->expects($this->once()) ->method('deleteUser') diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php index 9a89d2e1a3..e56add1527 100644 --- a/tests/Unit/Service/ItemServiceTest.php +++ b/tests/Unit/Service/ItemServiceTest.php @@ -13,7 +13,6 @@ namespace OCA\News\Tests\Unit\Service; -use OCA\News\Config\Config; use OCA\News\Db\ItemMapper; use OCA\News\Service\ItemService; use OCA\News\Service\ServiceNotFoundException; @@ -30,20 +29,26 @@ class ItemServiceTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemMapper + */ private $mapper; /** - * @var ItemService + * @var ItemService */ private $itemService; - private $user; - private $response; - private $status; + + /** + * @var int + */ private $time; - private $newestItemId; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $config; - private $systemConfig; - protected function setUp() + protected function setUp(): void { $this->time = 222; $this->timeFactory = $this->getMockBuilder(Time::class) @@ -58,23 +63,10 @@ protected function setUp() $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->systemConfig = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->itemService = new ItemService( - $this->mapper, - $this->timeFactory, $this->config, $this->systemConfig - ); - $this->user = 'jack'; - $this->id = 3; - $this->updatedSince = 20333; - $this->showAll = true; - $this->offset = 5; - $this->limit = 20; - $this->newestItemId = 4; + $this->itemService = new ItemService($this->mapper, $this->timeFactory, $this->config); } @@ -84,18 +76,15 @@ public function testFindAllNewFeed() $this->mapper->expects($this->once()) ->method('findAllNewFeed') ->with( - $this->equalTo($this->id), - $this->equalTo($this->updatedSince), - $this->equalTo($this->showAll), - $this->equalTo($this->user) + $this->equalTo(3), + $this->equalTo(20333), + $this->equalTo(true), + $this->equalTo('jack') ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue([])); - $result = $this->itemService->findAllNew( - $this->id, $type, $this->updatedSince, $this->showAll, - $this->user - ); - $this->assertEquals($this->response, $result); + $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack'); + $this->assertEquals([], $result); } @@ -105,18 +94,15 @@ public function testFindAllNewFolder() $this->mapper->expects($this->once()) ->method('findAllNewFolder') ->with( - $this->equalTo($this->id), - $this->equalTo($this->updatedSince), - $this->equalTo($this->showAll), - $this->equalTo($this->user) + $this->equalTo(3), + $this->equalTo(20333), + $this->equalTo(true), + $this->equalTo('jack') ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); - $result = $this->itemService->findAllNew( - $this->id, $type, $this->updatedSince, $this->showAll, - $this->user - ); - $this->assertEquals($this->response, $result); + $result = $this->itemService->findAllNew(3, $type, 20333, true, 'jack'); + $this->assertEquals(['val'], $result); } @@ -126,18 +112,18 @@ public function testFindAllNew() $this->mapper->expects($this->once()) ->method('findAllNew') ->with( - $this->equalTo($this->updatedSince), + $this->equalTo(20333), $this->equalTo($type), - $this->equalTo($this->showAll), - $this->equalTo($this->user) + $this->equalTo(true), + $this->equalTo('jack') ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAllNew( - $this->id, $type, $this->updatedSince, $this->showAll, - $this->user + 3, $type, 20333, true, + 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -147,21 +133,21 @@ public function testFindAllFeed() $this->mapper->expects($this->once()) ->method('findAllFeed') ->with( - $this->equalTo($this->id), - $this->equalTo($this->limit), - $this->equalTo($this->offset), - $this->equalTo($this->showAll), + $this->equalTo(3), + $this->equalTo(20), + $this->equalTo(5), + $this->equalTo(true), $this->equalTo(false), - $this->equalTo($this->user), + $this->equalTo('jack'), $this->equalTo([]) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, false, $this->user + 3, $type, 20, 5, + true, false, 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -171,21 +157,21 @@ public function testFindAllFolder() $this->mapper->expects($this->once()) ->method('findAllFolder') ->with( - $this->equalTo($this->id), - $this->equalTo($this->limit), - $this->equalTo($this->offset), - $this->equalTo($this->showAll), + $this->equalTo(3), + $this->equalTo(20), + $this->equalTo(5), + $this->equalTo(true), $this->equalTo(true), - $this->equalTo($this->user), + $this->equalTo('jack'), $this->equalTo([]) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, true, $this->user + 3, $type, 20, 5, + true, true, 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -195,21 +181,21 @@ public function testFindAll() $this->mapper->expects($this->once()) ->method('findAll') ->with( - $this->equalTo($this->limit), - $this->equalTo($this->offset), + $this->equalTo(20), + $this->equalTo(5), $this->equalTo($type), - $this->equalTo($this->showAll), $this->equalTo(true), - $this->equalTo($this->user), + $this->equalTo(true), + $this->equalTo('jack'), $this->equalTo([]) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, true, $this->user + 3, $type, 20, 5, + true, true, 'jack' ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -220,21 +206,21 @@ public function testFindAllSearch() $this->mapper->expects($this->once()) ->method('findAll') ->with( - $this->equalTo($this->limit), - $this->equalTo($this->offset), + $this->equalTo(20), + $this->equalTo(5), $this->equalTo($type), - $this->equalTo($this->showAll), $this->equalTo(true), - $this->equalTo($this->user), + $this->equalTo(true), + $this->equalTo('jack'), $this->equalTo($search) ) - ->will($this->returnValue($this->response)); + ->will($this->returnValue(['val'])); $result = $this->itemService->findAll( - $this->id, $type, $this->limit, $this->offset, - $this->showAll, true, $this->user, $search + 3, $type, 20, 5, + true, true, 'jack', $search ); - $this->assertEquals($this->response, $result); + $this->assertEquals(['val'], $result); } @@ -260,7 +246,7 @@ public function testStar() ->with( $this->equalTo($guidHash), $this->equalTo($feedId), - $this->equalTo($this->user) + $this->equalTo('jack') ) ->will($this->returnValue($item)); @@ -268,7 +254,7 @@ public function testStar() ->method('update') ->with($this->equalTo($expectedItem)); - $this->itemService->star($feedId, $guidHash, true, $this->user); + $this->itemService->star($feedId, $guidHash, true, 'jack'); $this->assertTrue($item->isStarred()); } @@ -296,7 +282,7 @@ public function testUnstar() ->with( $this->equalTo($guidHash), $this->equalTo($feedId), - $this->equalTo($this->user) + $this->equalTo('jack') ) ->will($this->returnValue($item)); @@ -304,7 +290,7 @@ public function testUnstar() ->method('update') ->with($this->equalTo($expectedItem)); - $this->itemService->star($feedId, $guidHash, false, $this->user); + $this->itemService->star($feedId, $guidHash, false, 'jack'); $this->assertFalse($item->isStarred()); } @@ -329,11 +315,11 @@ public function testRead() $this->equalTo($itemId), $this->equalTo(true), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ) ->will($this->returnValue($item)); - $this->itemService->read($itemId, true, $this->user); + $this->itemService->read($itemId, true, 'jack'); } @@ -345,7 +331,7 @@ public function testReadDoesNotExist() ->method('readItem') ->will($this->throwException(new DoesNotExistException(''))); - $this->itemService->read(1, true, $this->user); + $this->itemService->read(1, true, 'jack'); } public function testStarDoesNotExist() @@ -356,7 +342,7 @@ public function testStarDoesNotExist() ->method('findByGuidHash') ->will($this->throwException(new DoesNotExistException(''))); - $this->itemService->star(1, 'hash', true, $this->user); + $this->itemService->star(1, 'hash', true, 'jack'); } @@ -369,10 +355,10 @@ public function testReadAll() ->with( $this->equalTo($highestItemId), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ); - $this->itemService->readAll($highestItemId, $this->user); + $this->itemService->readAll($highestItemId, 'jack'); } @@ -387,10 +373,10 @@ public function testReadFolder() $this->equalTo($folderId), $this->equalTo($highestItemId), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ); - $this->itemService->readFolder($folderId, $highestItemId, $this->user); + $this->itemService->readFolder($folderId, $highestItemId, 'jack'); } @@ -405,17 +391,18 @@ public function testReadFeed() $this->equalTo($feedId), $this->equalTo($highestItemId), $this->equalTo($this->time), - $this->equalTo($this->user) + $this->equalTo('jack') ); - $this->itemService->readFeed($feedId, $highestItemId, $this->user); + $this->itemService->readFeed($feedId, $highestItemId, 'jack'); } public function testAutoPurgeOldWillPurgeOld() { $this->config->expects($this->once()) - ->method('getAutoPurgeCount') + ->method('getAppValue') + ->with('news', 'autoPurgeCount') ->will($this->returnValue(2)); $this->mapper->expects($this->once()) ->method('deleteReadOlderThanThreshold') @@ -427,7 +414,8 @@ public function testAutoPurgeOldWillPurgeOld() public function testAutoPurgeOldWontPurgeOld() { $this->config->expects($this->once()) - ->method('getAutoPurgeCount') + ->method('getAppValue') + ->with('news', 'autoPurgeCount') ->will($this->returnValue(-1)); $this->mapper->expects($this->never()) ->method('deleteReadOlderThanThreshold'); @@ -436,23 +424,23 @@ public function testAutoPurgeOldWontPurgeOld() } - public function testGetNewestItemId() + public function testGetNewestItemId() { $this->mapper->expects($this->once()) ->method('getNewestItemId') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will($this->returnValue(12)); - $result = $this->itemService->getNewestItemId($this->user); + $result = $this->itemService->getNewestItemId('jack'); $this->assertEquals(12, $result); } - public function testGetNewestItemIdDoesNotExist() + public function testGetNewestItemIdDoesNotExist() { $this->mapper->expects($this->once()) ->method('getNewestItemId') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will( $this->throwException( new DoesNotExistException('There are no items') @@ -460,7 +448,7 @@ public function testGetNewestItemIdDoesNotExist() ); $this->expectException(ServiceNotFoundException::class); - $this->itemService->getNewestItemId($this->user); + $this->itemService->getNewestItemId('jack'); } @@ -470,10 +458,10 @@ public function testStarredCount() $this->mapper->expects($this->once()) ->method('starredCount') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will($this->returnValue($star)); - $result = $this->itemService->starredCount($this->user); + $result = $this->itemService->starredCount('jack'); $this->assertEquals($star, $result); } @@ -485,22 +473,22 @@ public function testGetUnreadOrStarred() $this->mapper->expects($this->once()) ->method('findAllUnreadOrStarred') - ->with($this->equalTo($this->user)) + ->with($this->equalTo('jack')) ->will($this->returnValue($star)); - $result = $this->itemService->getUnreadOrStarred($this->user); + $result = $this->itemService->getUnreadOrStarred('jack'); $this->assertEquals($star, $result); } - public function testDeleteUser() + public function testDeleteUser() { $this->mapper->expects($this->once()) ->method('deleteUser') - ->will($this->returnValue($this->user)); + ->will($this->returnValue('jack')); - $this->itemService->deleteUser($this->user); + $this->itemService->deleteUser('jack'); } diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index eb18982902..8f601be468 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.php @@ -37,7 +37,7 @@ class ServiceTest extends TestCase protected $mapper; protected $newsService; - protected function setUp() + protected function setUp(): void { $this->mapper = $this->getMockBuilder(ItemMapper::class) ->disableOriginalConstructor() diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php index 8c42997a02..ee2e196148 100644 --- a/tests/Unit/Service/StatusServiceTest.php +++ b/tests/Unit/Service/StatusServiceTest.php @@ -13,8 +13,6 @@ namespace OCA\News\Tests\Unit\Service; -use OCA\News\Config\Config; -use \OCA\News\Db\FeedType; use OCA\News\Service\StatusService; use OCP\IConfig; use OCP\IDBConnection; @@ -23,83 +21,174 @@ class StatusServiceTest extends TestCase { - + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $settings; - private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IDBConnection + */ + private $connection; + + /** + * @var StatusService + */ private $service; - private $appName; - public function setUp() + public function setUp(): void { - $this->appName = 'news'; $this->settings = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); - $this->db = $this->getMockBuilder(IDBConnection::class) + $this->connection = $this->getMockBuilder(IDBConnection::class) ->disableOriginalConstructor() ->getMock(); - $this->service = new StatusService( - $this->settings, $this->db, - $this->config, $this->appName - ); - } - - private function beforeStatus($cronMode='cron', $cronEnabled=true, - $version='1.0' - ) { - $this->settings->expects($this->at(0)) - ->method('getAppValue') - ->with( - $this->equalTo($this->appName), - $this->equalTo('installed_version') - ) - ->will($this->returnValue($version)); - - $this->settings->expects($this->at(1)) - ->method('getAppValue') - ->with( - $this->equalTo('core'), - $this->equalTo('backgroundjobs_mode') - ) - ->will($this->returnValue($cronMode)); - - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($cronEnabled)); - + $this->service = new StatusService($this->settings, $this->connection, 'news'); } - + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ public function testGetStatus() { - $this->beforeStatus(); - + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, true], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('cron')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(true)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => false, + ], + ]; $response = $this->service->getStatus(); - $this->assertEquals('1.0', $response['version']); - $this->assertFalse($response['warnings']['improperlyConfiguredCron']); + $this->assertEquals($expected, $response); } - + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ public function testGetStatusNoCorrectCronAjax() { - $this->beforeStatus('ajax'); - + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, true], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('ajax')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(true)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => true, + 'incorrectDbCharset' => false, + ], + ]; $response = $this->service->getStatus(); - $this->assertTrue($response['warnings']['improperlyConfiguredCron']); + $this->assertEquals($expected, $response); } - - + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ public function testGetStatusNoCorrectCronTurnedOff() { - $this->beforeStatus('ajax', false); - + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, false], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('ajax')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(true)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => false, + ], + ]; $response = $this->service->getStatus(); - $this->assertFalse($response['warnings']['improperlyConfiguredCron']); + $this->assertEquals($expected, $response); } + /** + * @covers \OCA\News\Service\StatusService::getStatus + */ + public function testGetStatusReportsNon4ByteText() + { + $this->settings->expects($this->exactly(2)) + ->method('getAppValue') + ->withConsecutive( + ['news', 'installed_version'], + ['news', 'useCronUpdates'] + ) + ->will($this->returnValueMap([ + ['news', 'installed_version', '', '1.0'], + ['news', 'useCronUpdates', true, false], + ])); + + $this->settings->expects($this->exactly(1)) + ->method('getSystemValue') + ->with('backgroundjobs_mode') + ->will($this->returnValue('ajax')); + + $this->connection->expects($this->exactly(1)) + ->method('supports4ByteText') + ->will($this->returnValue(false)); + + $expected = [ + 'version' => '1.0', + 'warnings' => [ + 'improperlyConfiguredCron' => false, + 'incorrectDbCharset' => true, + ], + ]; + $response = $this->service->getStatus(); + $this->assertEquals($expected, $response); + } } \ No newline at end of file diff --git a/tests/Unit/Utility/OPMLExporterTest.php b/tests/Unit/Utility/OPMLExporterTest.php index 80cbaf9501..8c7c3c9236 100644 --- a/tests/Unit/Utility/OPMLExporterTest.php +++ b/tests/Unit/Utility/OPMLExporterTest.php @@ -32,7 +32,7 @@ class OPMLExporterTest extends TestCase /** @var Folder */ private $folder2; - protected function setUp() + protected function setUp(): void { $this->exporter = new OPMLExporter(); $this->folder1 = new Folder(); @@ -55,7 +55,7 @@ protected function setUp() } - private function getAttribute($item, $name) + private function getAttribute($item, $name) { // used to fix scrutinizer errors if ($item instanceof \DOMElement) { @@ -75,7 +75,7 @@ public function testBuildEmpty() } - public function testBuildReturnsFolders() + public function testBuildReturnsFolders() { $result = $this->exporter->build([$this->folder1, $this->folder2], []); $xpath = new \DOMXpath($result); @@ -101,7 +101,7 @@ public function testBuildReturnsFolders() } - public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() + public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() { $result = $this->exporter->build([], [$this->feed1, $this->feed2]); $xpath = new \DOMXpath($result); @@ -127,7 +127,7 @@ public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() } - public function testBuildReturnsFeedsAndFolders() + public function testBuildReturnsFeedsAndFolders() { $result = $this->exporter->build( [$this->folder1, $this->folder2], diff --git a/tests/Unit/Utility/UpdaterTest.php b/tests/Unit/Utility/UpdaterTest.php index 3a285ccfdd..3cd81de021 100644 --- a/tests/Unit/Utility/UpdaterTest.php +++ b/tests/Unit/Utility/UpdaterTest.php @@ -28,7 +28,7 @@ class UpdaterTest extends TestCase private $itemService; private $updater; - protected function setUp() + protected function setUp(): void { $this->folderService = $this->getMockBuilder(FolderService::class) ->disableOriginalConstructor() @@ -46,7 +46,7 @@ protected function setUp() ); } - public function testBeforeUpdate() + public function testBeforeUpdate() { $this->folderService->expects($this->once()) ->method('purgeDeleted'); @@ -56,14 +56,14 @@ public function testBeforeUpdate() } - public function testAfterUpdate() + public function testAfterUpdate() { $this->itemService->expects($this->once()) ->method('autoPurgeOld'); $this->updater->afterUpdate(); } - public function testUpdate() + public function testUpdate() { $this->feedService->expects($this->once()) ->method('updateAll');