From f785bae72e751828529c1e809f74149f62ef02a4 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 27 Oct 2024 12:15:38 +0100 Subject: [PATCH 1/3] Added support for MPL-2.0 SPDX license. Fixes #719 --- .../Checks/Plugin_Repo/Plugin_Readme_Check.php | 2 +- .../load.php | 16 ++++++++++++++++ .../readme.txt | 13 +++++++++++++ .../Checker/Checks/Plugin_Readme_Check_Tests.php | 12 ++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/readme.txt diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index 8e9ea0898..71ee0e530 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -354,7 +354,7 @@ private function check_license( Check_Result $result, string $readme_file, Parse } // Checks for a valid license in Plugin Header. - if ( ! empty( $plugin_license ) && ! preg_match( '/GPL|GNU|MIT|FreeBSD|New BSD|BSD-3-Clause|BSD 3 Clause|OpenLDAP|Expat|Apache/im', $plugin_license ) ) { + if ( ! empty( $plugin_license ) && ! preg_match( '/GPL|GNU|MIT|FreeBSD|New BSD|BSD-3-Clause|BSD 3 Clause|OpenLDAP|Expat|Apache|MPL20/im', $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' ), diff --git a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php new file mode 100644 index 000000000..e3d89837f --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php @@ -0,0 +1,16 @@ +assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'no_license' ) ) ); } + public function test_run_pass_with_mpl2_license() { + $readme_check = new Plugin_Readme_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-pass-mpl2-license/load.php' ); + $check_result = new Check_Result( $check_context ); + + $readme_check->run( $check_result ); + + $errors = $check_result->get_errors(); + + $this->assertEmpty( $errors ); + } + 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' ); From f56be6d01915deb945be2c01388e0ce4ad725e29 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 27 Oct 2024 12:40:56 +0100 Subject: [PATCH 2/3] Improved plugin path name --- .../load.php | 6 +++--- .../readme.txt | 0 .../tests/Checker/Checks/Plugin_Readme_Check_Tests.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename tests/phpunit/testdata/plugins/{test-plugin-plugin-readme-pass-mpl2-license => test-plugin-plugin-readme-mpl2-license-without-errors}/load.php (64%) rename tests/phpunit/testdata/plugins/{test-plugin-plugin-readme-pass-mpl2-license => test-plugin-plugin-readme-mpl2-license-without-errors}/readme.txt (100%) diff --git a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl2-license-without-errors/load.php similarity index 64% rename from tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php rename to tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl2-license-without-errors/load.php index e3d89837f..d92bdcb57 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-pass-mpl2-license/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl2-license-without-errors/load.php @@ -1,6 +1,6 @@ assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'no_license' ) ) ); } - public function test_run_pass_with_mpl2_license() { + public function test_run_without_error_mpl2_license() { $readme_check = new Plugin_Readme_Check(); - $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-pass-mpl2-license/load.php' ); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-mpl2-license-without-errors/load.php' ); $check_result = new Check_Result( $check_context ); $readme_check->run( $check_result ); From 5a102a4598acc81670ff29a0d7bc2ffaba338a32 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 27 Oct 2024 12:51:40 +0100 Subject: [PATCH 3/3] Make MPL-1.0 tests (it should not pass) --- .../load.php | 16 ++++++++++++++++ .../readme.txt | 13 +++++++++++++ .../Checks/Plugin_Readme_Check_Tests.php | 18 ++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl1-license-with-errors/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl1-license-with-errors/readme.txt diff --git a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl1-license-with-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl1-license-with-errors/load.php new file mode 100644 index 000000000..34a6c3c6a --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-mpl1-license-with-errors/load.php @@ -0,0 +1,16 @@ +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' );