From fbca4cc4cb5bdb83661a63a5c8eb12e8bf7fa82c Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 12 Nov 2024 14:15:54 +0545 Subject: [PATCH] Add unit test for added checks --- .../load.php | 1 - .../test-plugin-late-escaping-errors/load.php | 5 ++--- .../Checks/Plugin_Header_Fields_Check_Tests.php | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) 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 d2cf4b93e..6cd19caac 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 @@ -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 diff --git a/tests/phpunit/testdata/plugins/test-plugin-late-escaping-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-late-escaping-errors/load.php index cef8b3a59..2a2a0444c 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-late-escaping-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-late-escaping-errors/load.php @@ -2,12 +2,11 @@ /** * 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 diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php index 54ef73e85..6c4d8af8d 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php @@ -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' ) ) ); @@ -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' ) ) ); + } }