From 6e86000c06c979de3c3448379db39b7899177902 Mon Sep 17 00:00:00 2001 From: Benedict Date: Tue, 19 Mar 2024 12:56:26 +0100 Subject: [PATCH 01/19] Add action to run tests on push --- .github/workflows/php.yml | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..511fd53 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,42 @@ +name: PHP Composer + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" + # Docs: https://getcomposer.org/doc/articles/scripts.md + + - name: Install dev tools + run: composer run-script tools install + + - name: Run test suite + run: composer run-script test From 89680c00b2a53a3ed74ba17d5c3c776e71242e53 Mon Sep 17 00:00:00 2001 From: Benedict Date: Tue, 19 Mar 2024 12:57:24 +0100 Subject: [PATCH 02/19] Fix script name in PHP workflow --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 511fd53..cfb1234 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -39,4 +39,4 @@ jobs: run: composer run-script tools install - name: Run test suite - run: composer run-script test + run: composer run-script tests From 45ff8fbe03dd51ee1301adc8164684ec98d8ab05 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 13:06:36 +0100 Subject: [PATCH 03/19] Install Symfony CLI in PHP action --- .github/.gitkeep | 0 .github/workflows/php.yml | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 .github/.gitkeep diff --git a/.github/.gitkeep b/.github/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index cfb1234..1bcaeff 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,4 +1,4 @@ -name: PHP Composer +name: Tests on: push: @@ -10,7 +10,7 @@ permissions: contents: read jobs: - build: + test: runs-on: ubuntu-latest @@ -29,12 +29,12 @@ jobs: restore-keys: | ${{ runner.os }}-php- + - name: Install Symfony CLI + run: curl -sS https://get.symfony.com/cli/installer | bash + - name: Install dependencies run: composer install --prefer-dist --no-progress - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md - - name: Install dev tools run: composer run-script tools install From 3d13f237a92f9a00870bb160ce6ea25fa46ebe40 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 13:10:05 +0100 Subject: [PATCH 04/19] Move Symfony binary to /usr/local/bin --- .github/workflows/php.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1bcaeff..e0bb330 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -30,7 +30,9 @@ jobs: ${{ runner.os }}-php- - name: Install Symfony CLI - run: curl -sS https://get.symfony.com/cli/installer | bash + run: | + curl -sS https://get.symfony.com/cli/installer | bash + mv /home/runner/.symfony5/bin/symfony /usr/local/bin/symfony - name: Install dependencies run: composer install --prefer-dist --no-progress From 11f26fad45c824a34194825b4bb63c0ee1b42861 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 13:13:08 +0100 Subject: [PATCH 05/19] Use shivammathur/setup-php and setup PHP versions --- .github/workflows/php.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index e0bb330..9e2a56d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,10 +13,18 @@ jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.2', '8.3' ] steps: - uses: actions/checkout@v3 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + - name: Validate composer.json and composer.lock run: composer validate --strict From cb7fe98d0c915431d706ccc8748660daf5eacbaf Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 13:14:22 +0100 Subject: [PATCH 06/19] Update dev tools --- tools/kirby/composer.lock | 2 +- tools/phpcs/composer.lock | 24 ++++++++++++------------ tools/phpmd/composer.lock | 12 ++++++------ tools/psalm/composer.lock | 26 +++++++++++++------------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tools/kirby/composer.lock b/tools/kirby/composer.lock index 7948558..bf812b9 100644 --- a/tools/kirby/composer.lock +++ b/tools/kirby/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": "ca894294ba5db04356a9fc93d8d82a4c", + "content-hash": "8b44da9edaee85e395d61f7642cecbe9", "packages": [ { "name": "christian-riesen/base32", diff --git a/tools/phpcs/composer.lock b/tools/phpcs/composer.lock index f5fb149..f38df1d 100644 --- a/tools/phpcs/composer.lock +++ b/tools/phpcs/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "composer/pcre", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace" + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace", + "url": "https://api.github.com/repos/composer/pcre/zipball/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", "shasum": "" }, "require": { @@ -59,7 +59,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.2" + "source": "https://github.com/composer/pcre/tree/3.1.3" }, "funding": [ { @@ -75,7 +75,7 @@ "type": "tidelift" } ], - "time": "2024-03-07T15:38:35+00:00" + "time": "2024-03-19T10:26:25+00:00" }, { "name": "composer/semver", @@ -226,16 +226,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.51.0", + "version": "v3.52.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "127fa74f010da99053e3f5b62672615b72dd6efd" + "reference": "a3564bd66f4bce9bc871ef18b690e2dc67a7f969" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/127fa74f010da99053e3f5b62672615b72dd6efd", - "reference": "127fa74f010da99053e3f5b62672615b72dd6efd", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/a3564bd66f4bce9bc871ef18b690e2dc67a7f969", + "reference": "a3564bd66f4bce9bc871ef18b690e2dc67a7f969", "shasum": "" }, "require": { @@ -306,7 +306,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.51.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.52.0" }, "funding": [ { @@ -314,7 +314,7 @@ "type": "github" } ], - "time": "2024-02-28T19:50:06+00:00" + "time": "2024-03-18T18:40:11+00:00" }, { "name": "psr/container", diff --git a/tools/phpmd/composer.lock b/tools/phpmd/composer.lock index ee9ec32..b7dee96 100644 --- a/tools/phpmd/composer.lock +++ b/tools/phpmd/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "composer/pcre", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace" + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace", + "url": "https://api.github.com/repos/composer/pcre/zipball/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", "shasum": "" }, "require": { @@ -59,7 +59,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.2" + "source": "https://github.com/composer/pcre/tree/3.1.3" }, "funding": [ { @@ -75,7 +75,7 @@ "type": "tidelift" } ], - "time": "2024-03-07T15:38:35+00:00" + "time": "2024-03-19T10:26:25+00:00" }, { "name": "composer/xdebug-handler", diff --git a/tools/psalm/composer.lock b/tools/psalm/composer.lock index 9fb75b0..845855b 100644 --- a/tools/psalm/composer.lock +++ b/tools/psalm/composer.lock @@ -174,16 +174,16 @@ }, { "name": "composer/pcre", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace" + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace", + "url": "https://api.github.com/repos/composer/pcre/zipball/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", "shasum": "" }, "require": { @@ -225,7 +225,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.2" + "source": "https://github.com/composer/pcre/tree/3.1.3" }, "funding": [ { @@ -241,7 +241,7 @@ "type": "tidelift" } ], - "time": "2024-03-07T15:38:35+00:00" + "time": "2024-03-19T10:26:25+00:00" }, { "name": "composer/semver", @@ -689,21 +689,21 @@ }, { "name": "nikic/php-parser", - "version": "v4.18.0", + "version": "v4.19.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999" + "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bcbb2179f97633e98bbbc87044ee2611c7d7999", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b", + "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.1" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", @@ -739,9 +739,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.18.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1" }, - "time": "2023-12-10T21:03:43+00:00" + "time": "2024-03-17T08:10:35+00:00" }, { "name": "phpdocumentor/reflection-common", From 88e8ccfdb0c7f541ef6d064512c10d7cac195126 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 13:47:27 +0100 Subject: [PATCH 07/19] Rename workflow file --- .github/workflows/{php.yml => tests.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{php.yml => tests.yml} (100%) diff --git a/.github/workflows/php.yml b/.github/workflows/tests.yml similarity index 100% rename from .github/workflows/php.yml rename to .github/workflows/tests.yml From f1c1374de676e632eda39e7f299730da9c8e33ef Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:02:21 +0100 Subject: [PATCH 08/19] Update tools script and remove Symfony CLI --- .github/workflows/tests.yml | 5 ----- tools/tools.php | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9e2a56d..f77e762 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,11 +37,6 @@ jobs: restore-keys: | ${{ runner.os }}-php- - - name: Install Symfony CLI - run: | - curl -sS https://get.symfony.com/cli/installer | bash - mv /home/runner/.symfony5/bin/symfony /usr/local/bin/symfony - - name: Install dependencies run: composer install --prefer-dist --no-progress diff --git a/tools/tools.php b/tools/tools.php index f1122d7..cf94f29 100644 --- a/tools/tools.php +++ b/tools/tools.php @@ -15,6 +15,6 @@ } chdir($tool->getPathname()); - exec(sprintf('symfony composer %s --ansi', $command)); + exec(sprintf('%s %s %s --ansi', PHP_BINARY, '/usr/local/bin/composer', $command)); chdir($toolsDir); } From 0ffb7eaa5ca25fc3d550eebc924399c31a56abc7 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:35:50 +0100 Subject: [PATCH 09/19] Fix editorconfig for composer.json --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index a1ef997..804a3a0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,4 +14,4 @@ trim_trailing_whitespace = false insert_final_newline = false [composer.json] -indent_size = 4 \ No newline at end of file +indent_size = 2 From 4a4c305ef24a254f8144e63b2a94bbcf027f94a7 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:36:02 +0100 Subject: [PATCH 10/19] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abc41ee..b5ca76e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This plugin automatically assigns file templates to your uploaded files, based on the respective file type. This way it does not matter, which file type you upload from which field or section – the template assigned will always be the same. This is especially handy, when you use a single files section per page, that stores all the different file types used on the page. -## How to use +## 🚀 How to use Set up your configuration (see next section) first. The plugin will then run after each uploaded file (`file.create:after` hook) and assign the configured template automatically. From 5e54f0cec9e377e2bce10d960080f7787aee0b38 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:36:36 +0100 Subject: [PATCH 11/19] Fix some Psalm infos --- classes/AutoFileTemplates.php | 13 +++++++++---- extensions/commands/auto-templates.php | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/classes/AutoFileTemplates.php b/classes/AutoFileTemplates.php index 52c6553..f498c91 100644 --- a/classes/AutoFileTemplates.php +++ b/classes/AutoFileTemplates.php @@ -31,7 +31,7 @@ public function autoAssign(File $file): ?string // Virtual admin user $this->kirby->impersonate('kirby'); - if ($template = $this->getTemplateForFile($file)) { + if (($template = $this->getTemplateForFile($file)) !== null) { $file->update(['template' => $template]); } @@ -41,13 +41,18 @@ public function autoAssign(File $file): ?string private function getTemplateForFile(File $file): ?string { $template = null; + $type = $file->type(); - if ($this->templateMap[$file->type()] ?? null) { - $option = $this->templateMap[$file->type()] ?? null; + if (is_null($type)) { + return null; + } + + if (($this->templateMap[$type] ?? null) !== null) { + $option = $this->templateMap[$type]; // Use file type as template name if ($option === true) { - $template = $file->type(); + $template = $type; } // Use specified templates diff --git a/extensions/commands/auto-templates.php b/extensions/commands/auto-templates.php index 270ba0b..3d86b9c 100644 --- a/extensions/commands/auto-templates.php +++ b/extensions/commands/auto-templates.php @@ -19,6 +19,11 @@ 'command' => function (CLI $cli) { $kirby = $cli->kirby(); + if (is_null($kirby)) { + $cli->climate()->error('No Kirby instance – something\'s wrong here.'); + return; + } + // Virtual admin user $kirby->impersonate('kirby'); @@ -36,7 +41,7 @@ foreach ($page->files() as $file) { $template = $autoTemplates->autoAssign($file); - if (!$template) { + if (is_null($template)) { continue; } From a21ba7e46c995f239bc81fa03f4ebfa7adf4cdcc Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:37:06 +0100 Subject: [PATCH 12/19] Add script to validate composer.json --- composer.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/composer.json b/composer.json index 847a509..5892263 100644 --- a/composer.json +++ b/composer.json @@ -29,11 +29,13 @@ }, "scripts": { "analyze": [ + "@composer-validate", "@tests", "@psalm", "@phpmd" ], "csfix": "@php tools/phpcs/vendor/bin/php-cs-fixer fix", + "composer-validate": "composer validate --strict --no-check-version --no-check-all", "psalm": "@php tools/psalm/vendor/bin/psalm", "phpmd": "@php tools/phpmd/vendor/bin/phpmd . ansi phpmd.xml --exclude tools/*,tests/*,vendor/", "tests": "@php tools/phpunit/vendor/bin/phpunit --bootstrap=tests/bootstrap.php", From 65a5040946032911bd35d419607538abde6df2b6 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:37:40 +0100 Subject: [PATCH 13/19] Load tests/bootstrap.php for Psalm, too --- psalm.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/psalm.xml b/psalm.xml index 9100540..52b4063 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,6 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config tools/psalm/vendor/vimeo/psalm/config.xsd" + autoloader="tests/bootstrap.php" > From 2fc4a9cb0d4f704239a26ce33599b6dbcd4780a0 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:37:59 +0100 Subject: [PATCH 14/19] Require getkirby/cli for development --- tools/kirby/composer.json | 3 +- tools/kirby/composer.lock | 717 +++++++++++++++++++++++++++++++++++++- 2 files changed, 718 insertions(+), 2 deletions(-) diff --git a/tools/kirby/composer.json b/tools/kirby/composer.json index 1a8d74f..a5fe0ff 100644 --- a/tools/kirby/composer.json +++ b/tools/kirby/composer.json @@ -1,6 +1,7 @@ { "require": { - "getkirby/cms": "^4.0" + "getkirby/cms": "^4.0", + "getkirby/cli": "^1.4" }, "config": { "allow-plugins": { diff --git a/tools/kirby/composer.lock b/tools/kirby/composer.lock index bf812b9..7d86054 100644 --- a/tools/kirby/composer.lock +++ b/tools/kirby/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": "8b44da9edaee85e395d61f7642cecbe9", + "content-hash": "48ec0d39646c7f892ae7ee4dc7368f4a", "packages": [ { "name": "christian-riesen/base32", @@ -270,6 +270,72 @@ ], "time": "2023-11-03T12:00:00+00:00" }, + { + "name": "getkirby/cli", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/getkirby/cli.git", + "reference": "8cb347764de108f257c1a6f9ded456c8dd13c6f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/getkirby/cli/zipball/8cb347764de108f257c1a6f9ded456c8dd13c6f7", + "reference": "8cb347764de108f257c1a6f9ded456c8dd13c6f7", + "shasum": "" + }, + "require": { + "composer-runtime-api": "^2.2", + "ext-zip": "*", + "guzzlehttp/guzzle": "^7.8", + "league/climate": "^3.8.2", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0" + }, + "bin": [ + "bin/kirby" + ], + "type": "library", + "autoload": { + "psr-4": { + "Kirby\\": [ + "src/", + "tests/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kirby Team", + "email": "support@getkirby.com", + "homepage": "https://getkirby.com" + } + ], + "description": "Kirby command line interface", + "homepage": "https://getkirby.com", + "keywords": [ + "cli", + "cms", + "command", + "kirby" + ], + "support": { + "email": "support@getkirby.com", + "forum": "https://forum.getkirby.com", + "issues": "https://github.com/getkirby/cli/issues", + "source": "https://github.com/getkirby/cli" + }, + "funding": [ + { + "url": "https://getkirby.com/buy", + "type": "custom" + } + ], + "time": "2024-02-29T15:18:04+00:00" + }, { "name": "getkirby/cms", "version": "4.1.2", @@ -420,6 +486,331 @@ ], "time": "2020-12-28T12:54:39+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "7.8.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "41042bc7ab002487b876a0683fc8dce04ddce104" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/41042bc7ab002487b876a0683fc8dce04ddce104", + "reference": "41042bc7ab002487b876a0683fc8dce04ddce104", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.1", + "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-curl": "*", + "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.36 || ^9.6.15", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.8.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2023-12-03T20:35:24+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bbff78d96034045e58e13dedd6ad91b5d1253223", + "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.36 || ^9.6.15" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2023-12-03T20:19:20+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.6.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/45b30f99ac27b5ca93cb4831afe16285f57b8221", + "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.36 || ^9.6.15" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.6.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2023-12-03T20:05:35+00:00" + }, { "name": "laminas/laminas-escaper", "version": "2.13.0", @@ -482,6 +873,71 @@ ], "time": "2023-10-10T08:35:13+00:00" }, + { + "name": "league/climate", + "version": "3.8.2", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/climate.git", + "reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/climate/zipball/a785a3ac8f584eed4abd45e4e16fe64c46659a28", + "reference": "a785a3ac8f584eed4abd45e4e16fe64c46659a28", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "seld/cli-prompt": "^1.0" + }, + "require-dev": { + "mikey179/vfsstream": "^1.6.10", + "mockery/mockery": "^1.4.2", + "phpunit/phpunit": "^9.5.10" + }, + "suggest": { + "ext-mbstring": "If ext-mbstring is not available you MUST install symfony/polyfill-mbstring" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\CLImate\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joe Tannenbaum", + "email": "hey@joe.codes", + "homepage": "http://joe.codes/", + "role": "Developer" + }, + { + "name": "Craig Duncan", + "email": "git@duncanc.co.uk", + "homepage": "https://github.com/duncan3dc", + "role": "Developer" + } + ], + "description": "PHP's best friend for the terminal. CLImate allows you to easily output colored text, special formats, and more.", + "keywords": [ + "cli", + "colors", + "command", + "php", + "terminal" + ], + "support": { + "issues": "https://github.com/thephpleague/climate/issues", + "source": "https://github.com/thephpleague/climate/tree/3.8.2" + }, + "time": "2022-06-18T14:42:08+00:00" + }, { "name": "league/color-extractor", "version": "0.4.0", @@ -678,6 +1134,166 @@ ], "time": "2023-11-25T22:23:28+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "e616d01114759c4c489f93b099585439f795fe35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + }, + "time": "2023-04-10T20:10:41+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, { "name": "psr/log", "version": "3.0.0", @@ -728,6 +1344,105 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "seld/cli-prompt", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/cli-prompt.git", + "reference": "b8dfcf02094b8c03b40322c229493bb2884423c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/cli-prompt/zipball/b8dfcf02094b8c03b40322c229493bb2884423c5", + "reference": "b8dfcf02094b8c03b40322c229493bb2884423c5", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.63" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Seld\\CliPrompt\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + } + ], + "description": "Allows you to prompt for user input on the command line, and optionally hide the characters they type", + "keywords": [ + "cli", + "console", + "hidden", + "input", + "prompt" + ], + "support": { + "issues": "https://github.com/Seldaek/cli-prompt/issues", + "source": "https://github.com/Seldaek/cli-prompt/tree/1.0.4" + }, + "time": "2020-12-15T21:32:01+00:00" + }, { "name": "symfony/deprecation-contracts", "version": "v3.4.0", From c4346ec1e1f1640d2ca8f89416d5e97b149bbf94 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:40:50 +0100 Subject: [PATCH 15/19] Add script to check test coverage --- .gitignore | 5 ++++- composer.json | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a7c6bf2..d64de0d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,10 @@ /vendor/**/php4/* /vendor/getkirby/composer-installer +# Tests +/tests/coverage +/.phpunit.cache + # Tools /tools/**/vendor /.php-cs-fixer.cache -/.phpunit.cache diff --git a/composer.json b/composer.json index 5892263..dedd841 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "psalm": "@php tools/psalm/vendor/bin/psalm", "phpmd": "@php tools/phpmd/vendor/bin/phpmd . ansi phpmd.xml --exclude tools/*,tests/*,vendor/", "tests": "@php tools/phpunit/vendor/bin/phpunit --bootstrap=tests/bootstrap.php", + "tests:coverage": "XDEBUG_MODE=coverage tools/phpunit/vendor/bin/phpunit --bootstrap=tests/bootstrap.php --coverage-html=tests/coverage", "tools": "@php tools/tools.php" } } From 40a6d662f4e2dbea3ae916b083a7e8665f814b3c Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:45:31 +0100 Subject: [PATCH 16/19] Normalize composer.json --- composer.json | 4 ++-- vendor/composer/installed.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index dedd841..34b9508 100644 --- a/composer.json +++ b/composer.json @@ -34,10 +34,10 @@ "@psalm", "@phpmd" ], - "csfix": "@php tools/phpcs/vendor/bin/php-cs-fixer fix", "composer-validate": "composer validate --strict --no-check-version --no-check-all", - "psalm": "@php tools/psalm/vendor/bin/psalm", + "csfix": "@php tools/phpcs/vendor/bin/php-cs-fixer fix", "phpmd": "@php tools/phpmd/vendor/bin/phpmd . ansi phpmd.xml --exclude tools/*,tests/*,vendor/", + "psalm": "@php tools/psalm/vendor/bin/psalm", "tests": "@php tools/phpunit/vendor/bin/phpunit --bootstrap=tests/bootstrap.php", "tests:coverage": "XDEBUG_MODE=coverage tools/phpunit/vendor/bin/phpunit --bootstrap=tests/bootstrap.php --coverage-html=tests/coverage", "tools": "@php tools/tools.php" diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index d2d596f..56545f6 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'presprog/kirby-auto-file-templates', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '1b60800f5eddbeda23433d7fff53a75a7774d749', + 'reference' => 'c4346ec1e1f1640d2ca8f89416d5e97b149bbf94', 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -22,7 +22,7 @@ 'presprog/kirby-auto-file-templates' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '1b60800f5eddbeda23433d7fff53a75a7774d749', + 'reference' => 'c4346ec1e1f1640d2ca8f89416d5e97b149bbf94', 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), From e9e808175c7c53dbaa944c854aa6537390b97b01 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 14:51:22 +0100 Subject: [PATCH 17/19] Add test for case when file type could not be determined --- tests/AutoFileTemplatesTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/AutoFileTemplatesTest.php b/tests/AutoFileTemplatesTest.php index c22986b..32b73a7 100644 --- a/tests/AutoFileTemplatesTest.php +++ b/tests/AutoFileTemplatesTest.php @@ -209,6 +209,27 @@ public function testOverwriteTemplateIfOptionIsSet(): void $this->assertEquals('image', $service->autoAssign($image)); } + public function testFileTypeCannotBeDetermined(): void + { + $options = [ + 'autoAssign' => true, + ]; + + $kirby = new App([ + 'roots' => [ + 'index' => self::$tmpDir, + ], + 'options' => [ + 'presprog.auto-file-templates' => $options, + ], + ]); + + $service = new AutoFileTemplates($kirby, PluginOptions::createFromOptions($kirby->options())); + $image = new File(['type' => 'sometype', 'filename' => 'file', 'parent' => self::page()]); + + $this->assertEquals(null, $service->autoAssign($image)); + } + public static function files(): \Generator { $page = self::page(); From e41ec9dfe5634ba6b1d57386202d328d8363d47a Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Tue, 19 Mar 2024 15:41:55 +0100 Subject: [PATCH 18/19] Add test case to check whether 'update' is actually called --- tests/AutoFileTemplatesTest.php | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/AutoFileTemplatesTest.php b/tests/AutoFileTemplatesTest.php index 32b73a7..57866e7 100644 --- a/tests/AutoFileTemplatesTest.php +++ b/tests/AutoFileTemplatesTest.php @@ -55,6 +55,69 @@ public function testSetsTemplateBasedOnCoreFileTypes(File $file, ?string $expect $this->assertEquals($expected, $template); } + public function testFileUpdatedMethodIsCalledOnce(): void + { + $kirby = new App([ + 'roots' => [ + 'index' => self::$tmpDir, + ], + 'options' => [ + 'presprog.auto-file-templates' => [ + 'autoAssign' => true, + ], + ], + ]); + + $service = new AutoFileTemplates($kirby, PluginOptions::createFromOptions($kirby->options())); + + // File One: An image file without a template + $fileOneProps = ['type' => 'image', 'filename' => 'image.png', 'parent' => self::page()]; + + $fileOne = $this->getMockBuilder(File::class) + ->disableOriginalConstructor() + ->setConstructorArgs($fileOneProps) + ->getMock() + ; + + $fileOne->expects($this->once()) + ->method('update') + ->with(['template' => 'image']) + ; + + $fileOne->method('type') + ->willReturn($fileOneProps['type']) + ; + + + $templateOne = $service->autoAssign($fileOne); + $this->assertEquals('image', $templateOne); + + // File Two An image file with template `photo` (will not be updated) + + $fileTwoProps = ['type' => 'image', 'filename' => 'image.png', 'parent' => self::page(), 'template' => 'photo']; + + $fileTwo = $this->getMockBuilder(File::class) + ->disableOriginalConstructor() + ->setConstructorArgs($fileTwoProps) + ->getMock() + ; + + $fileTwo->method('template') + ->willReturn($fileTwoProps['template']) + ; + + $fileTwo->expects($this->never()) + ->method('update') + ; + + $fileTwo->method('type') + ->willReturn($fileTwoProps['type']) + ; + + $templateTwo = $service->autoAssign($fileTwo); + $this->assertEquals(null, $templateTwo); + } + public function testDoesNothingIfTurnedOffByOption(): void { $options = [ From 2dbabd06737d2984e6af26bdf2662f09b1046d61 Mon Sep 17 00:00:00 2001 From: Benedict Massolle Date: Fri, 22 Mar 2024 08:21:06 +0100 Subject: [PATCH 19/19] Add test case for custom types --- tests/AutoFileTemplatesTest.php | 41 ++++++++++++++++++- .../site/blueprints/files/custom-type.yml | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/site/blueprints/files/custom-type.yml diff --git a/tests/AutoFileTemplatesTest.php b/tests/AutoFileTemplatesTest.php index 57866e7..aedefac 100644 --- a/tests/AutoFileTemplatesTest.php +++ b/tests/AutoFileTemplatesTest.php @@ -37,7 +37,7 @@ protected function tearDown(): void } #[DataProvider('files')] - public function testSetsTemplateBasedOnCoreFileTypes(File $file, ?string $expected): void + public function testSetsTemplateForCoreFileTypes(File $file, ?string $expected): void { $kirby = new App([ 'roots' => [ @@ -55,7 +55,44 @@ public function testSetsTemplateBasedOnCoreFileTypes(File $file, ?string $expect $this->assertEquals($expected, $template); } - public function testFileUpdatedMethodIsCalledOnce(): void + public function testSetsTemplateForCustomFileTypes(): void + { + $kirby = new App([ + 'roots' => [ + 'index' => self::$tmpDir, + ], + 'options' => [ + 'presprog.auto-file-templates' => [ + 'autoAssign' => true, + ], + ], + ]); + + F::$types['custom-type'] = ['custom']; + + $props = ['type' => 'custom-type', 'filename' => 'image.custom', 'parent' => self::page()]; + + $file = $this->getMockBuilder(File::class) + ->disableOriginalConstructor() + ->setConstructorArgs($props) + ->getMock() + ; + + $file->expects($this->once()) + ->method('update') + ->with(['template' => 'custom-type']) + ; + + $file->method('type') + ->willReturn($props['type']) + ; + + $service = new AutoFileTemplates($kirby, PluginOptions::createFromOptions($kirby->options())); + $template = $service->autoAssign($file); + $this->assertEquals('custom-type', $template); + } + + public function testFileIsUpdated(): void { $kirby = new App([ 'roots' => [ diff --git a/tests/fixtures/site/blueprints/files/custom-type.yml b/tests/fixtures/site/blueprints/files/custom-type.yml new file mode 100644 index 0000000..ac61fb8 --- /dev/null +++ b/tests/fixtures/site/blueprints/files/custom-type.yml @@ -0,0 +1 @@ +Title: Custom Type