From 6f574ea41de7c0caaf758cfc84eb1acd4d924218 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 29 Aug 2024 22:53:57 +0200 Subject: [PATCH] updated named functions and tests --- phpcs-rulesets/plugin-review.xml | 6 +++++ .../test-plugin-review-phpcs-errors/load.php | 5 ++++ .../Plugin_Review_PHPCS_Check_Tests.php | 26 ++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/phpcs-rulesets/plugin-review.xml b/phpcs-rulesets/plugin-review.xml index ac42a2c91..b132c2c9c 100644 --- a/phpcs-rulesets/plugin-review.xml +++ b/phpcs-rulesets/plugin-review.xml @@ -90,8 +90,14 @@ + + + + + error + 7 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 7a599f40c..81a18c8c8 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 @@ -13,3 +13,8 @@ $the_author_email = ob_get_clean(); $var_post_not_sanitized = $_POST['not_sanitized']; + +set_time_limit( 20 ); +ini_set( 'max_execution_time', 20 ); +ini_alter( 'max_execution_time', 20 ); +dl( 'plugin-check.so' ); 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 c969c6d8a..d63b7e134 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 @@ -22,7 +22,7 @@ public function test_run_with_errors() { $this->assertNotEmpty( $errors ); $this->assertArrayHasKey( 'load.php', $errors ); - $this->assertEquals( 5, $check_result->get_error_count() ); + $this->assertEquals( 9, $check_result->get_error_count() ); // Check for Generic.PHP.DisallowShortOpenTag.Found error on Line no 6 and column no at 1. $this->assertArrayHasKey( 6, $errors['load.php'] ); @@ -41,6 +41,30 @@ public function test_run_with_errors() { $this->assertArrayHasKey( 27, $errors['load.php'][15] ); $this->assertArrayHasKey( 'code', $errors['load.php'][15][27][0] ); $this->assertEquals( 'WordPress.Security.ValidatedSanitizedInput.InputNotValidated', $errors['load.php'][15][27][0]['code'] ); + + // Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 17 and column no at 1. + $this->assertArrayHasKey( 17, $errors['load.php'] ); + $this->assertArrayHasKey( 1, $errors['load.php'][17] ); + $this->assertArrayHasKey( 'code', $errors['load.php'][17][1][0] ); + $this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][17][1][0]['code'] ); + + // Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 18 and column no at 1. + $this->assertArrayHasKey( 18, $errors['load.php'] ); + $this->assertArrayHasKey( 1, $errors['load.php'][18] ); + $this->assertArrayHasKey( 'code', $errors['load.php'][18][1][0] ); + $this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][18][1][0]['code'] ); + + // Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 19 and column no at 1. + $this->assertArrayHasKey( 19, $errors['load.php'] ); + $this->assertArrayHasKey( 1, $errors['load.php'][19] ); + $this->assertArrayHasKey( 'code', $errors['load.php'][19][1][0] ); + $this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][19][1][0]['code'] ); + + // Check for WordPress.Security.Generic.PHP.ForbiddenFunctions.Found error on Line no 20 and column no at 1. + $this->assertArrayHasKey( 20, $errors['load.php'] ); + $this->assertArrayHasKey( 1, $errors['load.php'][20] ); + $this->assertArrayHasKey( 'code', $errors['load.php'][20][1][0] ); + $this->assertEquals( 'Generic.PHP.ForbiddenFunctions.Found', $errors['load.php'][20][1][0]['code'] ); } public function test_run_without_errors() {