Skip to content

Commit

Permalink
Add unit test for added checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Nov 19, 2024
1 parent 8e0bbbe commit 4493432
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Description: Here is a short description of the plugin.
* Requires at least: Recent version
* Requires PHP: Latest version
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: This is not a valid URL
* Text Domain: test-mismathed-textdomain-here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/**
* Plugin Name: Test Plugin escape output with Errors for Plugin Check
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Some plugin description.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 1.0.0
* Version: 1.0.0-Beta
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* Author URI: https://github.com/wordpress/plugin-check/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-check-errors
* Domain Path: /languages
*
* @package test-plugin-check-errors
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function test_run_with_errors() {
$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( $errors['load.php'][0][0], array( 'code' => 'plugin_header_missing_plugin_version' ) ) );
$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' ) ) );
Expand Down Expand Up @@ -73,4 +74,20 @@ public function test_run_with_invalid_mpl1_license() {
// Check for invalid license.
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_license' ) ) );
}

public function test_run_with_invalid_header_fields() {
$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-late-escaping-errors/load.php' );
$check_result = new Check_Result( $check_context );

$check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertNotEmpty( $errors );

$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_missing_plugin_description' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_plugin_version' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_same_plugin_author_uri' ) ) );
}
}

0 comments on commit 4493432

Please sign in to comment.