Skip to content

Commit

Permalink
Add test for invalid license
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Oct 25, 2024
1 parent 6a64737 commit c7b680b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Plugin Name: Test Plugin Readme Errors (invalid license)
* 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: Oculus VR Inc. Software Development Kit License
* Text Domain: test-plugin-check-errors-invalid-license
*
* @package test-plugin-check-errors-invalid-license
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== Test Plugin with readme ===

Contributors: plugin-check
Requires at least: 6.0
Tested up to: 6.6
Requires PHP: 5.6
Stable tag: 1.0.0
Tags: testing, security
License: Oculus VR Inc. Software Development Kit License

Plugin description.
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,19 @@ public function test_run_with_errors_mismatched_license() {

$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'license_mismatch' ) ) );
}

public function test_run_with_errors_invalid_license() {
$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-invalid-license/load.php' );
$check_result = new Check_Result( $check_context );

$check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( 'load.php', $errors );

$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_license' ) ) );
}
}
15 changes: 15 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 @@ -177,6 +177,21 @@ 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_with_errors_invalid_license() {
$readme_check = new Plugin_Readme_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-invalid-license/load.php' );
$check_result = new Check_Result( $check_context );

$readme_check->run( $check_result );

$warnings = $check_result->get_warnings();

$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'readme.txt', $warnings );

$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][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 c7b680b

Please sign in to comment.