Skip to content
Prev Previous commit
Next Next commit
Update regexes, add Behat tests
  • Loading branch information
swissspidy committed Apr 30, 2025
commit da9ee193f3a7d75b4064bc2a49a4ff2bb9ec83dc
24 changes: 24 additions & 0 deletions features/upgradables.feature
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,27 @@ Feature: Manage WordPress themes and plugins
| type | type_name | item | item_title | version | zip_file | file_to_check |
| theme | Theme | moina | Moina | 1.1.2 | https://wordpress.org/themes/download/moina.1.1.2.zip | {CONTENT_DIR}/moina/style.css |
| plugin | Plugin | category-checklist-tree | Category Checklist Tree | 1.2 | https://downloads.wordpress.org/plugin/category-checklist-tree.1.2.zip | {CONTENT_DIR}/category-checklist-tree/category-checklist-tree.php |

@require-wp-4.5
Scenario Outline: Caches certain GitHub URLs
Given a WP install
And I run `wp plugin delete --all`

When I run `wp plugin install <zip_file>`
Then STDOUT should contain:
"""
Plugin installed successfully
"""

When I run `wp plugin delete --all`
And I run `wp plugin install <zip_file>`
Then STDOUT should contain:
"""
Using cached file '{SUITE_CACHE_DIR}/plugin/<item>-<version>
"""

Examples:
| item | version | zip_file |
| one-time-login | 0.4.0 | https://github.com/danielbachhuber/one-time-login/releases/latest |
| preferred-languages | 2.4.0 | https://github.com/swissspidy/preferred-languages/releases/download/2.4.0/preferred-languages.zip |
| generic-example-plugin | 0.1.1 | https://github.com/wp-cli-test/generic-example-plugin/archive/v0.1.1.zip |
9 changes: 5 additions & 4 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,13 @@
$matches = [];

// cache release URLs like `https://github.com/wp-cli-test/generic-example-plugin/releases/download/v0.1.0/generic-example-plugin.0.1.0.zip`
if ( preg_match( '#github\.com/[^/]+/([^/]+)/releases/download/tags/([^/]+)/(.+)\.zip#', $url, $matches ) ) {
WP_CLI::get_http_cache_manager()->whitelist_package( $url, $item_type, $matches[2], $matches[3] );
if ( preg_match( '#github\.com/[^/]+/([^/]+)/releases/download/v?([^/]+)/.+\.zip#', $url, $matches ) ) {
WP_CLI::get_http_cache_manager()->whitelist_package( $url, $item_type, $matches[1], $matches[2] );
// cache archive URLs like `https://github.com/wp-cli-test/generic-example-plugin/archive/v0.1.0.zip`

Check failure on line 858 in src/WP_CLI/CommandWithUpgrade.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Line indented incorrectly; expected at least 3 tabs, found 2
} elseif ( preg_match( '#github\.com/[^/]+/([^/]+)/archive/(version/|)([^/]+)\.zip#', $url, $matches ) ) {
} elseif ( preg_match( '#github\.com/[^/]+/([^/]+)/archive/(version/|)v?([^/]+)\.zip#', $url, $matches ) ) {
WP_CLI::get_http_cache_manager()->whitelist_package( $url, $item_type, $matches[1], $matches[3] );
} elseif ( preg_match( '#api\.github\.com/repos/[^/]+/([^/]+)/zipball/([^/]+)#', $url, $matches ) ) {
// cache release URLs like `https://api.github.com/repos/danielbachhuber/one-time-login/zipball/v0.4.0`

Check failure on line 861 in src/WP_CLI/CommandWithUpgrade.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Line indented incorrectly; expected at least 3 tabs, found 2
} elseif ( preg_match( '#api\.github\.com/repos/[^/]+/([^/]+)/zipball/v?([^/]+)#', $url, $matches ) ) {
WP_CLI::get_http_cache_manager()->whitelist_package( $url, $item_type, $matches[1], $matches[2] );
}
}
Expand Down
Loading