Skip to content

Commit

Permalink
Add tests for multiple parser warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 25, 2024
1 parent 6fd1a9e commit 5e7bca5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Test Plugin Readme Errors (Multiple Parser Warnings)
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin for the Readme check.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-check-errors-multiple-parser-warnings
*
* @package test-plugin-check-errors-multiple-parser-warnings
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Test Plugin Readme Errors Multiple Parser Warnings ===

Contributors: plugin-check, first name
Requires at least: Previous
Tested up to: Latest
Requires PHP: PHP 5.6
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: testing, security, plugin, readme, validation, enhancement, performance

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vulputate nunc velit, vitae sollicitudin tortor viverra sed. Morbi sed nibh ex. Nulla vel augue velit. Maecenas vel lobortis orci. In eget metus dui. Vivamus eleifend volutpat diam. Duis viverra leo non eros auctor, nec placerat elit placerat. Nulla blandit odio risus. In eu dui non erat congue sagittis. Donec luctus tincidunt dolor, nec tempus erat pretium eu. Nunc a dictum odio. Vivamus vel faucibus lorem, eu finibus sem. Sed et vehicula ante, vel sodales augue. Donec tincidunt bibendum libero, ac tristique tellus rutrum nec. Curabitur viverra tincidunt eros non laoreet. Sed vitae consequat diam.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Contributors: plugin-check
Requires at least: 6.0
Tested up to: Latest
Tested up to: 6.1
Requires PHP: PHP 5.6
Stable tag: 1.0.0
License: GPLv2 or later
Expand Down
33 changes: 28 additions & 5 deletions tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,39 @@ public function test_run_with_errors_parser_warnings() {

$this->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() {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5e7bca5

Please sign in to comment.