diff --git a/.github/workflows/behat-test.yml b/.github/workflows/behat-test.yml index de9b8c633..4f045338f 100644 --- a/.github/workflows/behat-test.yml +++ b/.github/workflows/behat-test.yml @@ -60,8 +60,6 @@ jobs: fail-fast: true matrix: php: - - '7.2' - - '7.3' - '7.4' - '8.0' - '8.1' @@ -70,7 +68,7 @@ jobs: - php: '8.2' wordpress: 'latest' coverage: true - - php: '7.2' + - php: '7.4' wordpress: '6.3' - php: '8.3' wordpress: 'trunk' @@ -157,7 +155,7 @@ jobs: - name: Upload code coverage report if: ${{ matrix.coverage }} - uses: codecov/codecov-action@v4.6.0 + uses: codecov/codecov-action@v5.0.2 with: files: ${{ steps.coverage_files.outputs.files }} flags: feature diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index bb7d48eec..42aaefff9 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -48,13 +48,12 @@ jobs: fail-fast: true matrix: php: - - '7.3' - '7.4' - '8.0' - '8.1' wordpress: [ 'latest' ] include: - - php: '7.2' + - php: '7.4' wordpress: '6.3' - php: '8.2' wordpress: 'latest' @@ -101,7 +100,7 @@ jobs: - name: Upload code coverage report if: ${{ matrix.coverage }} - uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6 + uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a with: file: build/logs/*.xml flags: unit @@ -115,8 +114,6 @@ jobs: fail-fast: true matrix: php: - - '7.2' - - '7.3' - '7.4' - '8.0' - '8.1' @@ -149,7 +146,7 @@ jobs: - name: Upload code coverage report if: ${{ matrix.coverage }} - uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6 + uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a with: file: build/logs/*.xml flags: phpcs-sniffs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 41a9bd898..f6ec40341 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ Thank you for your interest in contributing to the Plugin Check plugin! In general, all code must follow the [WordPress Coding Standards and best practices](https://developer.wordpress.org/coding-standards/). All code in the Plugin Check plugin must follow these requirements: - **WordPress**: The plugin's minimum WordPress version requirement is 6.3. -- **PHP**: Always match the latest WordPress version. The minimum required version right now is 7.2.24. +- **PHP**: The minimum required version right now is 7.4. ## Guidelines diff --git a/composer.json b/composer.json index e654e06db..d23f2c8a7 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": "GPL-2.0-or-later", "type": "wordpress-plugin", "require": { - "php": ">=7.2.24", + "php": ">=7.4", "ext-json": "*", "afragen/wordpress-plugin-readme-parser": "dev-master#67fba498d0b112acf84386b95e4905c539a33f0b", "automattic/vipwpcs": "^3.0.0", @@ -56,7 +56,7 @@ "phpstan/extension-installer": true }, "platform": { - "php": "7.2.24" + "php": "7.4" } }, "scripts": { diff --git a/composer.lock b/composer.lock index f90aa24b8..2a01919ba 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": "e1f6b4abdc63a16d7d5a7609f6df578a", + "content-hash": "3aab6089bbe13e7a4c81438da8f72ad6", "packages": [ { "name": "afragen/wordpress-plugin-readme-parser", @@ -6489,12 +6489,12 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2.24", + "php": ">=7.4", "ext-json": "*" }, "platform-dev": [], "platform-overrides": { - "php": "7.2.24" + "php": "7.4" }, "plugin-api-version": "2.6.0" } diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 255af27c3..0529611be 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -111,6 +111,12 @@ public function __construct( Plugin_Context $plugin_context ) { * [--warning-severity=] * : Warning severity level. * + * [--include-low-severity-errors] + * : Include errors with lower severity than the threshold as other type. + * + * [--include-low-severity-warnings] + * : Include warnings with lower severity than the threshold as other type. + * * [--slug=] * : Slug to override the default. * @@ -138,15 +144,17 @@ public function check( $args, $assoc_args ) { $options = $this->get_options( $assoc_args, array( - 'checks' => '', - 'format' => 'table', - 'ignore-warnings' => false, - 'ignore-errors' => false, - 'include-experimental' => false, - 'severity' => '', - 'error-severity' => '', - 'warning-severity' => '', - 'slug' => '', + 'checks' => '', + 'format' => 'table', + 'ignore-warnings' => false, + 'ignore-errors' => false, + 'include-experimental' => false, + 'severity' => '', + 'error-severity' => '', + 'warning-severity' => '', + 'include-low-severity-errors' => false, + 'include-low-severity-warnings' => false, + 'slug' => '', ) ); @@ -235,8 +243,10 @@ static function ( $dirs ) use ( $excluded_files ) { $formatter = $this->get_formatter( $assoc_args, $default_fields ); // Severity. - $error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity']; - $warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity']; + $error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity']; + $warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity']; + $include_low_severity_errors = ! empty( $options['include-low-severity-errors'] ) ? true : false; + $include_low_severity_warnings = ! empty( $options['include-low-severity-warnings'] ) ? true : false; // Print the formatted results. // Go over all files with errors first and print them, combined with any warnings in the same file. @@ -249,7 +259,7 @@ static function ( $dirs ) use ( $excluded_files ) { $file_results = $this->flatten_file_results( $file_errors, $file_warnings ); if ( '' !== $error_severity || '' !== $warning_severity ) { - $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) ); + $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings ); } if ( ! empty( $file_results ) ) { @@ -262,7 +272,7 @@ static function ( $dirs ) use ( $excluded_files ) { $file_results = $this->flatten_file_results( array(), $file_warnings ); if ( '' !== $error_severity || '' !== $warning_severity ) { - $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) ); + $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings ); } if ( ! empty( $file_results ) ) { @@ -626,25 +636,32 @@ private function display_results( $formatter, $file_name, $file_results ) { * * @since 1.1.0 * - * @param array $results Check results. - * @param int $error_severity Error severity level. - * @param int $warning_severity Warning severity level. + * @param array $results Check results. + * @param int $error_severity Error severity level. + * @param int $warning_severity Warning severity level. + * @param bool $include_low_severity_errors Include less level of severity issues as warning. + * @param bool $include_low_severity_warnings Include less level of severity issues as warning. + * + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) * @return array Filtered results. */ - private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) { - $errors = array_filter( - $results, - function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); - } - ); + private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false, $include_low_severity_warnings = false ) { + $errors = array(); + $warnings = array(); - $warnings = array_filter( - $results, - function ( $item ) use ( $warning_severity ) { - return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); + foreach ( $results as $item ) { + if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { + $errors[] = $item; + } elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) { + $item['type'] = 'ERRORS_LOW_SEVERITY'; + $errors[] = $item; + } elseif ( $include_low_severity_warnings && 'WARNING' === $item['type'] && $item['severity'] < $warning_severity ) { + $item['type'] = 'WARNINGS_LOW_SEVERITY'; + $warnings[] = $item; + } elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) { + $warnings[] = $item; } - ); + } return array_merge( $errors, $warnings ); } diff --git a/includes/Checker/Checks/General/I18n_Usage_Check.php b/includes/Checker/Checks/General/I18n_Usage_Check.php index 4521ba2a1..eaba6541e 100644 --- a/includes/Checker/Checks/General/I18n_Usage_Check.php +++ b/includes/Checker/Checks/General/I18n_Usage_Check.php @@ -103,6 +103,31 @@ protected function add_result_message_for_file( Check_Result $result, $error, $m $error = false; } + // Add documentation link. + switch ( $code ) { + case 'WordPress.WP.I18n.NonSingularStringLiteralDomain': + case 'WordPress.WP.I18n.NonSingularStringLiteralText': + case 'WordPress.WP.I18n.TooManyFunctionArgs': + $docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#basic-strings', 'plugin-check' ); + break; + + case 'WordPress.WP.I18n.NonSingularStringLiteralContext': + $docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#disambiguation-by-context', 'plugin-check' ); + break; + + case 'WordPress.WP.I18n.MissingTranslatorsComment': + $docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#descriptions', 'plugin-check' ); + break; + + case 'WordPress.WP.I18n.UnorderedPlaceholdersText': + $docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#variables', 'plugin-check' ); + break; + + default: + $docs = __( 'https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/', 'plugin-check' ); + break; + } + parent::add_result_message_for_file( $result, $error, $message, $code, $file, $line, $column, $docs, $severity ); } } diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php index 5f5be7c29..363ec5d60 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php @@ -12,6 +12,7 @@ use WordPress\Plugin_Check\Checker\Check_Result; use WordPress\Plugin_Check\Checker\Static_Check; use WordPress\Plugin_Check\Traits\Amend_Check_Result; +use WordPress\Plugin_Check\Traits\License_Utils; use WordPress\Plugin_Check\Traits\Stable_Check; /** @@ -22,6 +23,7 @@ class Plugin_Header_Fields_Check implements Static_Check { use Amend_Check_Result; + use License_Utils; use Stable_Check; /** @@ -67,6 +69,8 @@ public function run( Check_Result $result ) { 'RequiresPHP' => 'Requires PHP', 'UpdateURI' => 'Update URI', 'RequiresPlugins' => 'Requires Plugins', + 'License' => 'License', + 'LicenseURI' => 'License URI', ); $restricted_labels = array( @@ -249,6 +253,42 @@ public function run( Check_Result $result ) { } } + if ( empty( $plugin_header['License'] ) ) { + $this->add_result_error_for_file( + $result, + sprintf( + /* translators: %s: plugin header field */ + __( 'Missing "%s" in Plugin Header.
Please update your Plugin Header with a valid GPLv2 (or later) compatible license.', 'plugin-check' ), + esc_html( $labels['License'] ) + ), + 'plugin_header_no_license', + $plugin_main_file, + 0, + 0, + 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared', + 9 + ); + } else { + $plugin_license = $this->get_normalized_license( $plugin_header['License'] ); + if ( ! $this->is_license_gpl_compatible( $plugin_license ) ) { + $this->add_result_error_for_file( + $result, + sprintf( + /* translators: 1: plugin header field, 2: license */ + __( 'Invalid %1$s: %2$s.
Please update your Plugin Header with a valid GPLv2 (or later) compatible license.', 'plugin-check' ), + esc_html( $labels['License'] ), + esc_html( $plugin_header['License'] ) + ), + 'plugin_header_invalid_license', + $plugin_main_file, + 0, + 0, + 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared', + 9 + ); + } + } + $found_headers = array(); foreach ( $restricted_labels as $restricted_key => $restricted_label ) { diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index f3f91218e..ba9c7b859 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -326,7 +326,7 @@ private function check_license( Check_Result $result, string $readme_file, Parse // Test for a valid SPDX license identifier. if ( ! $this->is_license_valid_identifier( $license ) ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, __( 'Your plugin has an invalid license declared.
Please update your readme with a valid SPDX license identifier.', 'plugin-check' ), 'invalid_license', @@ -338,40 +338,18 @@ private function check_license( Check_Result $result, string $readme_file, Parse ); } + $plugin_license = ''; + $pattern = preg_quote( 'License', '/' ); $has_license = self::file_preg_match( "/(*ANYCRLF)^.*$pattern\s*:\s*(.*)$/im", array( $plugin_main_file ), $matches_license ); - if ( ! $has_license ) { - $this->add_result_error_for_file( - $result, - __( 'Your plugin has no license declared in Plugin Header.
Please update your plugin header with a GPLv2 (or later) compatible license. It is necessary to declare the license of this plugin. You can do this by using the fields available both in the plugin readme and in the plugin headers.', 'plugin-check' ), - 'no_license', - $plugin_main_file, - 0, - 0, - 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared', - 9 - ); - } else { - $plugin_license = $this->get_normalized_license( $matches_license[1] ); - } - // Checks for a valid license in Plugin Header. - if ( ! empty( $plugin_license ) && ! $this->is_license_gpl_compatible( $plugin_license ) ) { - $this->add_result_error_for_file( - $result, - __( 'Your plugin has an invalid license declared in Plugin Header.
Please update your readme with a valid GPL license identifier. It is necessary to declare the license of this plugin. You can do this by using the fields available both in the plugin readme and in the plugin headers.', 'plugin-check' ), - 'invalid_license', - $plugin_main_file, - 0, - 0, - 'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared', - 9 - ); + if ( $has_license ) { + $plugin_license = $this->get_normalized_license( $matches_license[1] ); } // Check different license types. if ( ! empty( $plugin_license ) && ! empty( $license ) && $license !== $plugin_license ) { - $this->add_result_warning_for_file( + $this->add_result_error_for_file( $result, __( 'Your plugin has a different license declared in the readme file and plugin header.
Please update your readme with a valid GPL license identifier.', 'plugin-check' ), 'license_mismatch', diff --git a/includes/Checker/Checks/Plugin_Repo/Trademarks_Check.php b/includes/Checker/Checks/Plugin_Repo/Trademarks_Check.php index c08e955b8..cf181fa03 100644 --- a/includes/Checker/Checks/Plugin_Repo/Trademarks_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Trademarks_Check.php @@ -137,7 +137,8 @@ class Trademarks_Check extends Abstract_File_Check { 'wordpress', 'wordpess', 'wpress', - 'wp-', + 'wp', // it's allowed, but shows a warning. + 'wc', // it's allowed, but shows a warning. 'wp-mail-smtp-', 'yandex-', 'yahoo-', @@ -146,6 +147,18 @@ class Trademarks_Check extends Abstract_File_Check { 'you-tube-', ); + /** + * Lists of allowed acronyms of trademarks. + * + * @since 1.3.0 + * + * @var string[] + */ + const ALLOWED_ACRONYMS = array( + 'wp', + 'wc', + ); + /** * Lists of trademarks that are allowed as 'for-whatever' ONLY. * @@ -348,6 +361,17 @@ private function validate_name_has_no_trademarks( $plugin_name ) { esc_html( $plugin_name ), esc_html( trim( $check, '-' ) ) ); + } elseif ( + trim( $check, '-' ) === $check + && in_array( $check, self::ALLOWED_ACRONYMS, true ) + ) { + // Trademarks that are allowed to use as an acronym. + $message = sprintf( + /* translators: 1: plugin slug, 2: found trademarked term */ + __( 'The plugin name includes a restricted term. Your plugin name - "%1$s" - contains the restricted term "%2$s" which can be used , as long as you don\'t change it to the full name. For example: You can use WP but not WordPress.', 'plugin-check' ), + esc_html( $plugin_name ), + esc_html( trim( $check, '-' ) ) + ); } elseif ( trim( $check, '-' ) === $check ) { // Trademarks that do NOT end in "-" indicate slug cannot contain term at all. $message = sprintf( @@ -395,6 +419,17 @@ private function validate_slug_has_no_trademarks( $plugin_slug ) { esc_html( $plugin_slug ), esc_html( trim( $check, '-' ) ) ); + } elseif ( + trim( $check, '-' ) === $check + && in_array( $check, self::ALLOWED_ACRONYMS, true ) + ) { + // Trademarks that are allowed to use with Acronym. + $message = sprintf( + /* translators: 1: plugin slug, 2: found trademarked term */ + __( 'The plugin slug includes a restricted term. Your plugin slug - "%1$s" - contains the restricted term "%2$s" which can be used within the plugin slug, as long as you don\'t use the full name in the plugin name. For example: You can use WP but not WordPress.', 'plugin-check' ), + esc_html( $plugin_slug ), + esc_html( trim( $check, '-' ) ) + ); } elseif ( trim( $check, '-' ) === $check ) { // Trademarks that do NOT end in "-" indicate slug cannot contain term at all. $message = sprintf( diff --git a/package-lock.json b/package-lock.json index cef620567..d32c52aa6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,8 +8,8 @@ "hasInstallScript": true, "license": "GPL-2.0-or-later", "devDependencies": { - "@wordpress/env": "^10.11.0", - "@wordpress/scripts": "^30.4.0", + "@wordpress/env": "^10.12.0", + "@wordpress/scripts": "^30.5.1", "gherkin-lint": "^4.2.4", "patch-package": "^8.0.0" }, @@ -4448,10 +4448,11 @@ } }, "node_modules/@wordpress/env": { - "version": "10.11.0", - "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-10.11.0.tgz", - "integrity": "sha512-Sd31oiYxy9/pNMfYw7XgtCBoD4PpvcK1UQ/FVFP+DsTTuo55Ma4UAHMKfg2NhnZWqhJTgPC6XXzicGpr/lK4RQ==", + "version": "10.12.0", + "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-10.12.0.tgz", + "integrity": "sha512-+tsdVfngQYcysxdVonXRSwuJjqoqTSv7wwrcThCYXR1OBCMQ/xT2Ywfvf9a/yItJs5uicO9Vx8B5aIuvXiGVqg==", "dev": true, + "license": "GPL-2.0-or-later", "dependencies": { "chalk": "^4.0.0", "copy-dir": "^1.3.0", @@ -4639,9 +4640,9 @@ } }, "node_modules/@wordpress/scripts": { - "version": "30.4.0", - "resolved": "https://registry.npmjs.org/@wordpress/scripts/-/scripts-30.4.0.tgz", - "integrity": "sha512-hAX8XB8hWlxAyktT4KkBpGttRwSynmtkpLvbVKeKnj+BjABFs4TGb/HCF9hFpUK3huCAg8Ft/sjjczW+5tqspQ==", + "version": "30.5.1", + "resolved": "https://registry.npmjs.org/@wordpress/scripts/-/scripts-30.5.1.tgz", + "integrity": "sha512-VM5NViNfdQR69MWxLnptB8svvnrEV+oUVgWL8icsLdCt2CENgPwUIk/Gs0wzeAVK05cGjrCESapJnEgIXp5lzA==", "dev": true, "dependencies": { "@babel/core": "7.25.7", @@ -4686,7 +4687,6 @@ "npm-package-json-lint": "^6.4.0", "npm-packlist": "^3.0.0", "postcss": "^8.4.5", - "postcss-import": "^16.1.0", "postcss-loader": "^6.2.1", "prettier": "npm:wp-prettier@3.0.3", "puppeteer-core": "^23.1.0", @@ -14777,23 +14777,6 @@ "postcss": "^8.4.31" } }, - "node_modules/postcss-import": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-16.1.0.tgz", - "integrity": "sha512-7hsAZ4xGXl4MW+OKEWCnF6T5jqBw80/EE9aXg1r2yyn1RsVEU8EtKXbijEODa+rg7iih4bKf7vlvTGYR4CnPNg==", - "dev": true, - "dependencies": { - "postcss-value-parser": "^4.0.0", - "read-cache": "^1.0.0", - "resolve": "^1.1.7" - }, - "engines": { - "node": ">=18.0.0" - }, - "peerDependencies": { - "postcss": "^8.0.0" - } - }, "node_modules/postcss-loader": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/postcss-loader/-/postcss-loader-6.2.1.tgz", @@ -15771,24 +15754,6 @@ "node": ">=0.10.0" } }, - "node_modules/read-cache": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", - "integrity": "sha512-Owdv/Ft7IjOgm/i0xvNDZ1LrRANRfew4b2prF3OWMQLxLfu3bS8FVhCsrSCMK4lR56Y9ya+AThoTpDCTxCmpRA==", - "dev": true, - "dependencies": { - "pify": "^2.3.0" - } - }, - "node_modules/read-cache/node_modules/pify": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", - "integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/read-pkg": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", @@ -22941,9 +22906,9 @@ } }, "@wordpress/env": { - "version": "10.11.0", - "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-10.11.0.tgz", - "integrity": "sha512-Sd31oiYxy9/pNMfYw7XgtCBoD4PpvcK1UQ/FVFP+DsTTuo55Ma4UAHMKfg2NhnZWqhJTgPC6XXzicGpr/lK4RQ==", + "version": "10.12.0", + "resolved": "https://registry.npmjs.org/@wordpress/env/-/env-10.12.0.tgz", + "integrity": "sha512-+tsdVfngQYcysxdVonXRSwuJjqoqTSv7wwrcThCYXR1OBCMQ/xT2Ywfvf9a/yItJs5uicO9Vx8B5aIuvXiGVqg==", "dev": true, "requires": { "chalk": "^4.0.0", @@ -23060,9 +23025,9 @@ "requires": {} }, "@wordpress/scripts": { - "version": "30.4.0", - "resolved": "https://registry.npmjs.org/@wordpress/scripts/-/scripts-30.4.0.tgz", - "integrity": "sha512-hAX8XB8hWlxAyktT4KkBpGttRwSynmtkpLvbVKeKnj+BjABFs4TGb/HCF9hFpUK3huCAg8Ft/sjjczW+5tqspQ==", + "version": "30.5.1", + "resolved": "https://registry.npmjs.org/@wordpress/scripts/-/scripts-30.5.1.tgz", + "integrity": "sha512-VM5NViNfdQR69MWxLnptB8svvnrEV+oUVgWL8icsLdCt2CENgPwUIk/Gs0wzeAVK05cGjrCESapJnEgIXp5lzA==", "dev": true, "requires": { "@babel/core": "7.25.7", @@ -23107,7 +23072,6 @@ "npm-package-json-lint": "^6.4.0", "npm-packlist": "^3.0.0", "postcss": "^8.4.5", - "postcss-import": "^16.1.0", "postcss-loader": "^6.2.1", "prettier": "npm:wp-prettier@3.0.3", "puppeteer-core": "^23.1.0", @@ -30491,17 +30455,6 @@ "dev": true, "requires": {} }, - "postcss-import": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-16.1.0.tgz", - "integrity": "sha512-7hsAZ4xGXl4MW+OKEWCnF6T5jqBw80/EE9aXg1r2yyn1RsVEU8EtKXbijEODa+rg7iih4bKf7vlvTGYR4CnPNg==", - "dev": true, - "requires": { - "postcss-value-parser": "^4.0.0", - "read-cache": "^1.0.0", - "resolve": "^1.1.7" - } - }, "postcss-loader": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/postcss-loader/-/postcss-loader-6.2.1.tgz", @@ -31158,23 +31111,6 @@ "integrity": "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==", "dev": true }, - "read-cache": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", - "integrity": "sha512-Owdv/Ft7IjOgm/i0xvNDZ1LrRANRfew4b2prF3OWMQLxLfu3bS8FVhCsrSCMK4lR56Y9ya+AThoTpDCTxCmpRA==", - "dev": true, - "requires": { - "pify": "^2.3.0" - }, - "dependencies": { - "pify": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", - "integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==", - "dev": true - } - } - }, "read-pkg": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", diff --git a/package.json b/package.json index e0477b1e8..4e7460cfb 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "npm": ">=10.2.3" }, "devDependencies": { - "@wordpress/env": "^10.11.0", - "@wordpress/scripts": "^30.4.0", + "@wordpress/env": "^10.12.0", + "@wordpress/scripts": "^30.5.1", "gherkin-lint": "^4.2.4", "patch-package": "^8.0.0" }, diff --git a/patches/@wordpress+env+10.10.0.patch b/patches/@wordpress+env+10.12.0.patch similarity index 100% rename from patches/@wordpress+env+10.10.0.patch rename to patches/@wordpress+env+10.12.0.patch diff --git a/phpcs-sniffs/composer.json b/phpcs-sniffs/composer.json index 321eea251..7258b4dba 100644 --- a/phpcs-sniffs/composer.json +++ b/phpcs-sniffs/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2.24", + "php": ">=7.4", "ext-libxml": "*", "ext-tokenizer": "*", "ext-xmlreader": "*", @@ -38,7 +38,7 @@ "dealerdirect/phpcodesniffer-composer-installer": true }, "platform": { - "php": "7.2.24" + "php": "7.4" } }, "scripts": { @@ -67,4 +67,4 @@ "lint": "Lint PHP files against parse errors.", "run-tests": "Run all the unit tests for the Plugin Check Coding Standards sniffs." } -} \ No newline at end of file +} diff --git a/phpcs-sniffs/composer.lock b/phpcs-sniffs/composer.lock index 4f32ab0cb..b76221c75 100644 --- a/phpcs-sniffs/composer.lock +++ b/phpcs-sniffs/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": "e3f2033f9c52ac5eab10852c851d3007", + "content-hash": "49ca6c46b9685eb474d91448a1b9444f", "packages": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -2050,14 +2050,14 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2.24", + "php": ">=7.4", "ext-libxml": "*", "ext-tokenizer": "*", "ext-xmlreader": "*" }, "platform-dev": [], "platform-overrides": { - "php": "7.2.24" + "php": "7.4" }, "plugin-api-version": "2.6.0" } diff --git a/phpcs-sniffs/phpcs.xml.dist b/phpcs-sniffs/phpcs.xml.dist index 337d86812..9f61b589c 100644 --- a/phpcs-sniffs/phpcs.xml.dist +++ b/phpcs-sniffs/phpcs.xml.dist @@ -37,7 +37,7 @@ - + diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 178470c80..436717cd8 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -3,7 +3,7 @@ Sniffs for WordPress plugins, with minor modifications for Performance - + diff --git a/plugin.php b/plugin.php index 8de444180..a905b6c3d 100644 --- a/plugin.php +++ b/plugin.php @@ -4,7 +4,7 @@ * Plugin URI: https://github.com/WordPress/plugin-check * Description: Plugin Check is a WordPress.org tool which provides checks to help plugins meet the directory requirements and follow various best practices. * Requires at least: 6.3 - * Requires PHP: 7.2.24 + * Requires PHP: 7.4 * Version: 1.2.0 * Author: WordPress Performance Team and Plugin Review Team * License: GPLv2 or later @@ -17,7 +17,7 @@ use WordPress\Plugin_Check\Plugin_Main; define( 'WP_PLUGIN_CHECK_VERSION', '1.2.0' ); -define( 'WP_PLUGIN_CHECK_MINIMUM_PHP', '7.2.24' ); +define( 'WP_PLUGIN_CHECK_MINIMUM_PHP', '7.4' ); define( 'WP_PLUGIN_CHECK_MAIN_FILE', __FILE__ ); define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH', plugin_dir_path( WP_PLUGIN_CHECK_MAIN_FILE ) ); define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_URL', plugin_dir_url( WP_PLUGIN_CHECK_MAIN_FILE ) ); diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 824e10515..3e82d13f9 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -192,5 +192,33 @@ Feature: Test that the severity level in plugin check works. upgrade_notice_limit,WARNING,5 """ + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --error-severity=7 --include-low-severity-errors` + Then STDOUT should contain: + """ + allow_unfiltered_uploads_detected,ERROR,7 + """ + And STDOUT should contain: + """ + WordPress.WP.AlternativeFunctions.rand_mt_rand,ERRORS_LOW_SEVERITY,5 + """ + And STDOUT should contain: + """ + WordPress.Security.EscapeOutput.OutputNotEscaped,ERRORS_LOW_SEVERITY,5 + """ + + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --warning-severity=7 --include-low-severity-warnings` + Then STDOUT should contain: + """ + allow_unfiltered_uploads_detected,ERROR,7 + """ + And STDOUT should contain: + """ + upgrade_notice_limit,WARNINGS_LOW_SEVERITY,5 + """ + And STDOUT should contain: + """ + default_readme_text,ERROR,7 + """ + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` Then STDOUT should be empty diff --git a/tests/phpunit/testdata/plugins/test-plugin-header-fields-with-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-header-fields-with-errors/load.php index ce261dd5e..d2cf4b93e 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-header-fields-with-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-header-fields-with-errors/load.php @@ -8,8 +8,6 @@ * Version: 1.0.0 * Author: WordPress Performance Team * Author URI: This is not a valid URL - * License: GPLv2 or later - * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html * Text Domain: test-mismathed-textdomain-here * Domain Path: /nonexistent-folder * Network: random-value diff --git a/tests/phpunit/testdata/plugins/test-trademarks-plugin-header-acronym/load.php b/tests/phpunit/testdata/plugins/test-trademarks-plugin-header-acronym/load.php new file mode 100644 index 000000000..ad7aa092f --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-trademarks-plugin-header-acronym/load.php @@ -0,0 +1,16 @@ +assertCount( 0, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_restricted_fields' ) ) ); $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_wp' ) ) ); $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_php' ) ) ); + $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_no_license' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_uri_domain' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_description' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_author_uri' ) ) ); @@ -57,4 +58,19 @@ public function test_run_with_valid_requires_plugins_header() { $this->assertCount( 0, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) ); } } + + public function test_run_with_invalid_mpl1_license() { + $check = new Plugin_Header_Fields_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-mpl1-license-with-errors/load.php' ); + $check_result = new Check_Result( $check_context ); + + $check->run( $check_result ); + + $errors = $check_result->get_errors(); + + $this->assertNotEmpty( $errors ); + + // Check for invalid license. + $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_license' ) ) ); + } } diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php index 6bbb60c63..275da69c0 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php @@ -148,18 +148,18 @@ public function test_run_with_errors_license() { $readme_check->run( $check_result ); - $warnings = $check_result->get_warnings(); + $errors = $check_result->get_errors(); - $this->assertNotEmpty( $warnings ); - $this->assertArrayHasKey( 'readme.txt', $warnings ); + $this->assertNotEmpty( $errors ); + $this->assertArrayHasKey( 'readme.txt', $errors ); - // Check for invalid license warning. - $this->assertArrayHasKey( 0, $warnings['readme.txt'] ); - $this->assertArrayHasKey( 0, $warnings['readme.txt'][0] ); - $this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license' ) ) ); + // Check for invalid license. + $this->assertArrayHasKey( 0, $errors['readme.txt'] ); + $this->assertArrayHasKey( 0, $errors['readme.txt'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'invalid_license' ) ) ); - // Check for not same license warning. - $this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'license_mismatch' ) ) ); + // Check for not same license. + $this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'license_mismatch' ) ) ); } public function test_run_with_errors_no_license() { @@ -192,24 +192,6 @@ public function test_run_without_error_mpl2_license() { $this->assertEmpty( $errors ); } - public function test_run_with_errors_mpl1_license() { - $readme_check = new Plugin_Readme_Check(); - $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-mpl1-license-with-errors/load.php' ); - $check_result = new Check_Result( $check_context ); - - $readme_check->run( $check_result ); - - $errors = $check_result->get_errors(); - - $this->assertNotEmpty( $errors ); - $this->assertArrayHasKey( 'load.php', $errors ); - - // Check for invalid license. - $this->assertArrayHasKey( 0, $errors['load.php'] ); - $this->assertArrayHasKey( 0, $errors['load.php'][0] ); - $this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'invalid_license' ) ) ); - } - public function test_run_with_errors_tested_upto() { $readme_check = new Plugin_Readme_Check(); $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-tested-upto/load.php' ); @@ -244,12 +226,12 @@ public function test_run_md_with_errors() { $this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'trunk_stable_tag' ) ) ); $this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'outdated_tested_upto_header' ) ) ); $this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'default_readme_text' ) ) ); + $this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'invalid_license' ) ) ); + $this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'license_mismatch' ) ) ); $this->assertNotEmpty( $warnings ); $this->assertArrayHasKey( 'readme.md', $warnings ); - $this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'invalid_license' ) ) ); - $this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'license_mismatch' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'mismatched_plugin_name' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'readme_invalid_contributors' ) ) ); } diff --git a/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php index 0f0a95a64..1470b2d3b 100644 --- a/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Trademarks_Check_Tests.php @@ -75,6 +75,12 @@ public function data_trademarks_check() { 'load.php', 'The plugin name includes a restricted term. Your chosen plugin name - "WooCommerce Example String" - contains the restricted term "woocommerce" which cannot be used within in your plugin name, unless your plugin name ends with "for woocommerce". The term must still not appear anywhere else in your name.', ), + 'Plugin headers - WP Example String' => array( + Trademarks_Check::TYPE_NAME, + 'test-trademarks-plugin-header-acronym/load.php', + 'load.php', + 'The plugin name includes a restricted term. Your plugin name - "WP Example String" - contains the restricted term "wp" which can be used , as long as you don\'t change it to the full name. For example: You can use WP but not WordPress.', + ), 'Plugin headers - WooCommerce String for WooCommerce' => array( Trademarks_Check::TYPE_NAME, 'test-trademarks-plugin-header-woocommerce-string-for-woocommerce/load.php', diff --git a/tests/phpunit/tests/Checker/Preparations/Universal_Runtime_Preparation_Tests.php b/tests/phpunit/tests/Checker/Preparations/Universal_Runtime_Preparation_Tests.php index c805b0e21..0cd416c96 100644 --- a/tests/phpunit/tests/Checker/Preparations/Universal_Runtime_Preparation_Tests.php +++ b/tests/phpunit/tests/Checker/Preparations/Universal_Runtime_Preparation_Tests.php @@ -9,16 +9,43 @@ use WordPress\Plugin_Check\Checker\Check_Context; use WordPress\Plugin_Check\Checker\Preparations\Universal_Runtime_Preparation; +use WordPress\Plugin_Check\Checker\Runtime_Environment_Setup; use WP_UnitTestCase; class Universal_Runtime_Preparation_Tests extends WP_UnitTestCase { + /** + * Storage for preparation cleanups that need to be run after a test. + * + * @var array + */ + private $cleanups = array(); + + public function tear_down() { + if ( count( $this->cleanups ) > 0 ) { + $this->cleanups = array_reverse( $this->cleanups ); + foreach ( $this->cleanups as $cleanup ) { + $cleanup(); + } + $this->cleanups = array(); + } + parent::tear_down(); + } + public function test_prepare() { $check_context = new Check_Context( plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ) ); + // The runtime environment must be prepared manually before regular runtime preparations. + $runtime = new Runtime_Environment_Setup(); + $runtime->set_up(); + $this->cleanups[] = function () use ( $runtime ) { + $runtime->clean_up(); + }; + $universal_runtime_preparation = new Universal_Runtime_Preparation( $check_context ); - $cleanup = $universal_runtime_preparation->prepare(); + $cleanup = $universal_runtime_preparation->prepare(); + $this->cleanups[] = $cleanup; $this->assertTrue( has_filter( 'option_active_plugins' ) ); $this->assertTrue( has_filter( 'default_option_active_plugins' ) ); @@ -32,6 +59,9 @@ public function test_prepare() { $cleanup(); + // If this is reached, the universal runtime preparation cleanup was already done, so we can remove it again. + array_pop( $this->cleanups ); + $this->assertFalse( has_filter( 'option_active_plugins' ) ); $this->assertFalse( has_filter( 'default_option_active_plugins' ) ); $this->assertFalse( has_filter( 'stylesheet' ) ); diff --git a/tests/phpunit/tests/Traits/License_Utils_Tests.php b/tests/phpunit/tests/Traits/License_Utils_Tests.php new file mode 100644 index 000000000..1fb256639 --- /dev/null +++ b/tests/phpunit/tests/Traits/License_Utils_Tests.php @@ -0,0 +1,115 @@ +get_normalized_license( $raw ); + + $this->assertSame( $normalized, $result ); + } + + /** + * @dataProvider data_license_identifiers + */ + public function test_license_identifier( $license, $validity ) { + $result = $this->is_license_valid_identifier( $license ); + + $this->assertSame( $validity, $result ); + } + + /** + * @dataProvider data_license_gpl_compatibility + */ + public function test_license_gpl_compatibility( $license, $validity ) { + $result = $this->is_license_gpl_compatible( $license ); + + $this->assertSame( $validity, $result ); + } + + public function data_licenses_for_normalization() { + return array( + array( 'GPLv2', 'GPL2' ), + array( 'GPLv2 or later', 'GPL2' ), + array( 'GPLv2 or later', 'GPL2' ), + array( 'GPLv2-or-later', 'GPL2' ), + array( 'GPL v2 or later', 'GPL2' ), + array( 'GPL-2.0', 'GPL2' ), + array( 'GPL-2.0-or-later', 'GPL2' ), + array( 'GNU General Public License v2.0 or later', 'GPL2' ), + array( 'GPL-2.0+', 'GPL2' ), + array( 'GNU General Public License (GPL) 2.0', 'GPL2' ), + array( 'GPL version 2', 'GPL2' ), + array( 'GPL version 2 or later', 'GPL2' ), + + array( 'GPLv3', 'GPL3' ), + array( 'GPLv3 or later', 'GPL3' ), + array( 'GPLv3 or later', 'GPL3' ), + array( 'GPLv3-or-later', 'GPL3' ), + array( 'GPL v3 or later', 'GPL3' ), + array( 'GPL-3.0', 'GPL3' ), + array( 'GPL-3.0-or-later', 'GPL3' ), + array( 'GNU General Public License v3.0 or later', 'GPL3' ), + array( 'GPL-3.0+', 'GPL3' ), + array( 'GNU General Public License (GPL) 3.0', 'GPL3' ), + array( 'GPL version 3', 'GPL3' ), + array( 'GPL version 3 or later', 'GPL3' ), + + array( 'MPL-1.0', 'MPL10' ), + array( 'MPL-2.0', 'MPL20' ), + ); + } + + public function data_license_identifiers() { + return array( + array( 'GPLv2', true ), + array( 'GPL3', true ), + array( 'mpl-2.0', true ), + array( 'lgpl-3.0-or-later', true ), + array( 'artistic-license-2.0 or MIT', true ), + array( 'cc-by-sa-4.0 or cc-by-nc-4.0', true ), + array( 'public-domain or unlicense', true ), + array( 'eupl-1.1+', true ), + array( 'AGPL-3.0-only', true ), + + array( 'MIT License', false ), + array( 'GPL (v3)', false ), + array( 'my_custom_license', false ), + array( 'LGPL 3.0 or later', false ), + array( 'GPL-2.0+ with font exception', false ), + ); + } + + public function data_license_gpl_compatibility() { + return array( + array( 'GPL2', true ), + array( 'GPL3', true ), + array( 'MPL20', true ), + array( 'MIT', true ), + array( 'Apache', true ), + array( 'FreeBSD', true ), + array( 'New BSD', true ), + array( 'BSD-3-Clause', true ), + array( 'BSD 3 Clause', true ), + array( 'OpenLDAP', true ), + array( 'Expat', true ), + + array( 'EPL', false ), + array( 'EUPL', false ), + array( 'MPL10', false ), + array( 'YPL', false ), + array( 'ZPL', false ), + ); + } +} diff --git a/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php b/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php index fc760ca26..80a36513d 100644 --- a/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php +++ b/tests/phpunit/tests/Utilities/Plugin_Request_Utility_Tests.php @@ -11,6 +11,7 @@ use WordPress\Plugin_Check\Checker\Checks; use WordPress\Plugin_Check\Checker\Checks\General\I18n_Usage_Check; use WordPress\Plugin_Check\Checker\CLI_Runner; +use WordPress\Plugin_Check\Checker\Runtime_Environment_Setup; use WordPress\Plugin_Check\Test_Data\Runtime_Check; use WordPress\Plugin_Check\Test_Utils\Traits\With_Mock_Filesystem; use WordPress\Plugin_Check\Utilities\Plugin_Request_Utility; @@ -90,6 +91,16 @@ public function test_initialize_runner_with_ajax() { $_REQUEST['action'] = 'plugin_check_run_checks'; $_REQUEST['plugin'] = 'plugin-check'; + /* + * The runtime environment must be prepared manually before regular runtime preparations. + * This is necessary because in reality it happens in a separate AJAX request before. + */ + $runtime = new Runtime_Environment_Setup(); + $runtime->set_up(); + $this->cleanups[] = function () use ( $runtime ) { + $runtime->clean_up(); + }; + Plugin_Request_Utility::initialize_runner(); $this->cleanups[] = function () { Plugin_Request_Utility::destroy_runner(); @@ -109,7 +120,7 @@ public function test_initialize_runner_with_ajax() { public function test_destroy_runner_with_cli() { define( 'WP_CLI', true ); - global $wpdb, $table_prefix, $wp_actions; + global $wp_actions; $this->set_up_mock_filesystem(); @@ -151,7 +162,6 @@ function ( $checks ) { unset( $_SERVER['argv'] ); $wp_actions['muplugins_loaded'] = $muplugins_loaded; - $wpdb->set_prefix( $table_prefix ); $this->assertTrue( $prepared ); $this->assertTrue( $cleanup ); @@ -159,7 +169,7 @@ function ( $checks ) { } public function test_destroy_runner_with_ajax() { - global $wpdb, $table_prefix, $wp_actions; + global $wp_actions; $this->set_up_mock_filesystem(); @@ -168,6 +178,16 @@ public function test_destroy_runner_with_ajax() { $_REQUEST['plugin'] = 'plugin-check'; $_REQUEST['checks'] = array( 'runtime_check' ); + /* + * The runtime environment must be prepared manually before regular runtime preparations. + * This is necessary because in reality it happens in a separate AJAX request before. + */ + $runtime = new Runtime_Environment_Setup(); + $runtime->set_up(); + $this->cleanups[] = function () use ( $runtime ) { + $runtime->clean_up(); + }; + add_filter( 'wp_plugin_check_checks', function ( $checks ) { @@ -196,7 +216,6 @@ function ( $checks ) { $cleanup = ! has_filter( 'option_active_plugins' ); $runner = Plugin_Request_Utility::get_runner(); - $wpdb->set_prefix( $table_prefix ); $wp_actions['muplugins_loaded'] = $muplugins_loaded; $this->assertTrue( $prepared );