Skip to content

Commit

Permalink
Merge pull request #755 from syrusakbary/support-mpl2-license
Browse files Browse the repository at this point in the history
Added support for MPL-2.0 SPDX license. Fixes #719
  • Loading branch information
davidperezgar authored Oct 29, 2024
2 parents 77827cb + 5a102a4 commit d186c69
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
__( '<strong>Your plugin has an invalid license declared in Plugin Header.</strong><br>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' ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Test Plugin MPL-1.0 (license) with errors
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin for the Readme check.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: MPL-1.0
* License URI: https://www.mozilla.org/en-US/MPL/2.0/FAQ/
* Text Domain: test-plugin-plugin-readme-mpl1-license-with-errors
*
* @package test-plugin-plugin-readme-mpl1-license-with-errors
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

=== Test Plugin with readme and MPL 1.0 license ===

Contributors: plugin-check
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 5.6
Stable tag: 1.0.0
License: MPL-1.0
License URI: https://www.mozilla.org/en-US/MPL/1.0/FAQ/
Tags: testing, security

Plugin description.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Test Plugin MPL-2.0 (license) without errors
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin for the Readme check.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: MPL-2.0
* License URI: https://www.mozilla.org/en-US/MPL/2.0/FAQ/
* Text Domain: test-plugin-plugin-readme-mpl2-license-without-errors
*
* @package test-plugin-plugin-readme-mpl2-license-without-errors
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

=== Test Plugin with readme and MPL 2.0 license ===

Contributors: plugin-check
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 5.6
Stable tag: 1.0.0
License: MPL-2.0
License URI: https://www.mozilla.org/en-US/MPL/2.0/FAQ/
Tags: testing, security

Plugin description.
30 changes: 30 additions & 0 deletions tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,36 @@ public function test_run_with_errors_no_license() {
$this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'no_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-mpl2-license-without-errors/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_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' );
Expand Down

0 comments on commit d186c69

Please sign in to comment.