From 5e7bca5ec5e2033068af2cf601b931a7efcd1ffa Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 25 Jan 2024 17:22:19 +0545 Subject: [PATCH] Add tests for multiple parser warnings --- .../load.php | 16 +++++++++ .../readme.txt | 12 +++++++ .../readme.txt | 2 +- .../Checks/Plugin_Readme_Check_Tests.php | 33 ++++++++++++++++--- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-multiple-parser-warnings/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-multiple-parser-warnings/readme.txt diff --git a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-multiple-parser-warnings/load.php b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-multiple-parser-warnings/load.php new file mode 100644 index 000000000..22c15009d --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-multiple-parser-warnings/load.php @@ -0,0 +1,16 @@ +assertNotEmpty( $warnings ); $this->assertArrayHasKey( 'readme.txt', $warnings ); - $this->assertEquals( 2, $check_result->get_warning_count() ); + $this->assertEquals( 1, $check_result->get_warning_count() ); - // Check for parser warnings. + // Check for parser warning. $this->assertArrayHasKey( 0, $warnings['readme.txt'] ); $this->assertArrayHasKey( 0, $warnings['readme.txt'][0] ); $this->assertArrayHasKey( 'code', $warnings['readme.txt'][0][0][0] ); $this->assertEquals( 'readme_parser_warnings', $warnings['readme.txt'][0][0][0]['code'] ); - $this->assertArrayHasKey( 'code', $warnings['readme.txt'][0][0][1] ); - $this->assertEquals( 'readme_parser_warnings', $warnings['readme.txt'][0][0][1]['code'] ); + } + + public function test_run_with_errors_multiple_parser_warnings() { + $readme_check = new Plugin_Readme_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-multiple-parser-warnings/load.php' ); + $check_result = new Check_Result( $check_context ); + + $readme_check->run( $check_result ); + + $errors = $check_result->get_errors(); + $warnings = $check_result->get_warnings(); + + $this->assertNotEmpty( $warnings ); + $this->assertArrayHasKey( 'readme.txt', $warnings ); + $this->assertEquals( 6, $check_result->get_warning_count() ); + $this->assertEmpty( $errors ); + $this->assertEquals( 0, $check_result->get_error_count() ); + + // Check for parser warnings. + $this->assertArrayHasKey( 0, $warnings['readme.txt'] ); + $this->assertArrayHasKey( 0, $warnings['readme.txt'][0] ); + + for ( $i = 0; $i < 6; ++$i ) { + $this->assertArrayHasKey( 'code', $warnings['readme.txt'][0][0][ $i ] ); + $this->assertEquals( 'readme_parser_warnings', $warnings['readme.txt'][0][0][ $i ]['code'] ); + } } public function test_filter_readme_warnings_ignored() { @@ -277,7 +301,6 @@ public function test_filter_wp_plugin_check_ignored_readme_warnings_will_return_ $custom_ignores = array( 'requires_php_header_ignored', 'contributor_ignored', - 'tested_header_ignored', ); // Create a mock filter that will return our custom ignores.