Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning for invalid Tested up to value #613

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ private function check_headers( Check_Result $result, string $readme_file, Parse
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
7
);
} elseif ( version_compare( $parser->{$field_key}, number_format( (float) $latest_wordpress_version + 0.1, 1 ), '>' ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: 1: currently used version, 2: 'Tested up to' */
__( '<strong>Tested up to: %1$s.</strong><br>The "%2$s" value in your plugin is not valid. This version of WordPress does not exist (yet).', 'plugin-check' ),
$parser->{$field_key},
'Tested up to'
),
'nonexistent_tested_upto_header',
$readme_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
7
);
}
} else {
if ( empty( $parser->{$field_key} ) ) {
Expand Down
60 changes: 60 additions & 0 deletions tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,64 @@ public function test_run_with_errors_upgrade_notice() {
$this->assertArrayHasKey( 'code', $warnings['readme.txt'][0][0][1] );
$this->assertEquals( 'upgrade_notice_limit', $warnings['readme.txt'][0][0][1]['code'] );
}

public function test_run_with_errors_tested_up_to_latest_plus_two_version() {
$version = '5.9'; // Target plugin has "6.1" is readme.

set_transient( 'wp_plugin_check_latest_wp_version', $version );

$readme_check = new Plugin_Readme_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
$check_result = new Check_Result( $check_context );

$readme_check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertNotEmpty( $errors );

$filtered_items = wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) );

$this->assertCount( 1, $filtered_items );
$this->assertStringContainsString( 'Tested up to: 6.1', $filtered_items[0]['message'] );
$this->assertStringContainsString( 'This version of WordPress does not exist (yet).', $filtered_items[0]['message'] );

delete_transient( 'wp_plugin_check_latest_wp_version' );
}

public function test_run_with_errors_tested_up_to_latest_plus_one_version() {
$version = '6.0'; // Target plugin has "6.1" is readme.

set_transient( 'wp_plugin_check_latest_wp_version', $version );

$readme_check = new Plugin_Readme_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
$check_result = new Check_Result( $check_context );

$readme_check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );

delete_transient( 'wp_plugin_check_latest_wp_version' );
}

public function test_run_with_errors_tested_up_to_latest_stable_version() {
$version = '6.1'; // Target plugin has "6.1" is readme.

set_transient( 'wp_plugin_check_latest_wp_version', $version );

$readme_check = new Plugin_Readme_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
$check_result = new Check_Result( $check_context );

$readme_check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );

delete_transient( 'wp_plugin_check_latest_wp_version' );
}
}