From c9d0d238a5bf03ddcb0178e72664253a1259e58a Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 17 Dec 2024 09:19:51 +0545 Subject: [PATCH] Add unit test for the updated rules --- .../testdata/plugins/test-plugin-review-phpcs-errors/load.php | 2 ++ .../tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php index 9e59cf503..faaccd7b7 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php @@ -33,3 +33,5 @@ parse_str( 'first=value&arr[]=foo+bar&arr[]=baz' ); +$encoded_value = json_encode( array( 'key' => 'value' ) ); + diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php index 22e67c78b..cf1f8561c 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php @@ -44,6 +44,9 @@ public function test_run_with_errors() { // Check for PluginCheck.CodeAnalysis.RequiredFunctionParameters.parse_str_resultMissing error on Line no 34 and column no at 1. $this->assertSame( 'PluginCheck.CodeAnalysis.RequiredFunctionParameters.parse_str_resultMissing', $errors['load.php'][34][1][0]['code'] ); + // There should not be WordPress.WP.AlternativeFunctions.json_encode_json_encode error on Line no 36 and column no at 18. + $this->assertCount( 0, wp_list_filter( $errors['load.php'][36][18], array( 'code' => 'WordPress.WP.AlternativeFunctions.json_encode_json_encode' ) ) ); + // Check for WordPress.Security.ValidatedSanitizedInput warnings on Line no 15 and column no at 27. $this->assertCount( 1, wp_list_filter( $warnings['load.php'][15][27], array( 'code' => 'WordPress.Security.ValidatedSanitizedInput.InputNotValidated' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][15][27], array( 'code' => 'WordPress.Security.ValidatedSanitizedInput.MissingUnslash' ) ) );