Skip to content

Commit 75be00e

Browse files
authored
Merge pull request #613 from WordPress/609-future-tested-up-to
2 parents 25c033e + 82f7279 commit 75be00e

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ private function check_headers( Check_Result $result, string $readme_file, Parse
193193
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
194194
7
195195
);
196+
} elseif ( version_compare( $parser->{$field_key}, number_format( (float) $latest_wordpress_version + 0.1, 1 ), '>' ) ) {
197+
$this->add_result_error_for_file(
198+
$result,
199+
sprintf(
200+
/* translators: 1: currently used version, 2: 'Tested up to' */
201+
__( '<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' ),
202+
$parser->{$field_key},
203+
'Tested up to'
204+
),
205+
'nonexistent_tested_upto_header',
206+
$readme_file,
207+
0,
208+
0,
209+
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
210+
7
211+
);
196212
}
197213
} else {
198214
if ( empty( $parser->{$field_key} ) ) {

tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,64 @@ public function test_run_with_errors_upgrade_notice() {
433433
$this->assertArrayHasKey( 'code', $warnings['readme.txt'][0][0][1] );
434434
$this->assertEquals( 'upgrade_notice_limit', $warnings['readme.txt'][0][0][1]['code'] );
435435
}
436+
437+
public function test_run_with_errors_tested_up_to_latest_plus_two_version() {
438+
$version = '5.9'; // Target plugin has "6.1" is readme.
439+
440+
set_transient( 'wp_plugin_check_latest_wp_version', $version );
441+
442+
$readme_check = new Plugin_Readme_Check();
443+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
444+
$check_result = new Check_Result( $check_context );
445+
446+
$readme_check->run( $check_result );
447+
448+
$errors = $check_result->get_errors();
449+
450+
$this->assertNotEmpty( $errors );
451+
452+
$filtered_items = wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) );
453+
454+
$this->assertCount( 1, $filtered_items );
455+
$this->assertStringContainsString( 'Tested up to: 6.1', $filtered_items[0]['message'] );
456+
$this->assertStringContainsString( 'This version of WordPress does not exist (yet).', $filtered_items[0]['message'] );
457+
458+
delete_transient( 'wp_plugin_check_latest_wp_version' );
459+
}
460+
461+
public function test_run_with_errors_tested_up_to_latest_plus_one_version() {
462+
$version = '6.0'; // Target plugin has "6.1" is readme.
463+
464+
set_transient( 'wp_plugin_check_latest_wp_version', $version );
465+
466+
$readme_check = new Plugin_Readme_Check();
467+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
468+
$check_result = new Check_Result( $check_context );
469+
470+
$readme_check->run( $check_result );
471+
472+
$errors = $check_result->get_errors();
473+
474+
$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );
475+
476+
delete_transient( 'wp_plugin_check_latest_wp_version' );
477+
}
478+
479+
public function test_run_with_errors_tested_up_to_latest_stable_version() {
480+
$version = '6.1'; // Target plugin has "6.1" is readme.
481+
482+
set_transient( 'wp_plugin_check_latest_wp_version', $version );
483+
484+
$readme_check = new Plugin_Readme_Check();
485+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-md-with-errors/load.php' );
486+
$check_result = new Check_Result( $check_context );
487+
488+
$readme_check->run( $check_result );
489+
490+
$errors = $check_result->get_errors();
491+
492+
$this->assertCount( 0, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) );
493+
494+
delete_transient( 'wp_plugin_check_latest_wp_version' );
495+
}
436496
}

0 commit comments

Comments
 (0)