Skip to content

Commit 6cbc69e

Browse files
authored
Merge pull request #928 from WordPress/917-tested-upto
Show tested up to minor check only when it is current major version
2 parents 1168667 + 4e58151 commit 6cbc69e

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ private function check_headers( Check_Result $result, string $readme_file, Parse
216216
if ( ! empty( $parser->{$field_key} ) && 'tested' === $field_key ) {
217217
list( $tested_upto, ) = explode( '-', $parser->{$field_key} );
218218

219+
$latest_wordpress_version = $this->get_wordpress_stable_version();
220+
219221
$tested_upto_major = $tested_upto;
220222
if ( preg_match( '#^\d.\d#', $tested_upto, $matches ) ) {
221223
$tested_upto_major = $matches[0];
222224
}
223225

224-
if ( preg_match( '/^\d+\.\d+\.\d+/', $tested_upto ) ) {
226+
if ( $tested_upto_major === $latest_wordpress_version && preg_match( '/^\d+\.\d+\.\d+/', $tested_upto ) ) {
225227
$this->add_result_error_for_file(
226228
$result,
227229
sprintf(
@@ -239,7 +241,6 @@ private function check_headers( Check_Result $result, string $readme_file, Parse
239241
);
240242
}
241243

242-
$latest_wordpress_version = $this->get_wordpress_stable_version();
243244
if ( version_compare( $tested_upto_major, $latest_wordpress_version, '<' ) ) {
244245
$this->add_result_error_for_file(
245246
$result,

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ public function test_run_with_errors_tested_upto() {
220220
$this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'outdated_tested_upto_header' ) ) );
221221
}
222222

223-
public function test_run_with_errors_tested_upto_minor() {
223+
public function test_run_with_errors_tested_upto_minor_same_major_version() {
224+
// Target plugin has "6.1.1" is readme.
225+
// Current version is set to 6.1.2.
226+
set_transient( 'wp_plugin_check_latest_version_info', array( 'current' => '6.1.2' ) );
227+
224228
$readme_check = new Plugin_Readme_Check();
225229
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-tested-upto-minor/load.php' );
226230
$check_result = new Check_Result( $check_context );
@@ -229,15 +233,44 @@ public function test_run_with_errors_tested_upto_minor() {
229233

230234
$errors = $check_result->get_errors();
231235

236+
delete_transient( 'wp_plugin_check_latest_version_info' );
237+
232238
$this->assertNotEmpty( $errors );
233239
$this->assertArrayHasKey( 'readme.txt', $errors );
234240

235-
// Check for tested upto.
241+
// Check for tested upto minor error.
236242
$this->assertArrayHasKey( 0, $errors['readme.txt'] );
237243
$this->assertArrayHasKey( 0, $errors['readme.txt'][0] );
238244
$this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'invalid_tested_upto_minor' ) ) );
239245
}
240246

247+
public function test_run_with_errors_tested_upto_minor_different_major_version() {
248+
// Target plugin has "6.1.1" is readme.
249+
// Current version is set to 6.2.1.
250+
set_transient( 'wp_plugin_check_latest_version_info', array( 'current' => '6.2.1' ) );
251+
252+
$readme_check = new Plugin_Readme_Check();
253+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-tested-upto-minor/load.php' );
254+
$check_result = new Check_Result( $check_context );
255+
256+
$readme_check->run( $check_result );
257+
258+
$errors = $check_result->get_errors();
259+
260+
delete_transient( 'wp_plugin_check_latest_version_info' );
261+
262+
$this->assertNotEmpty( $errors );
263+
$this->assertArrayHasKey( 'readme.txt', $errors );
264+
265+
// Check for tested upto minor error.
266+
$this->assertArrayHasKey( 0, $errors['readme.txt'] );
267+
$this->assertArrayHasKey( 0, $errors['readme.txt'][0] );
268+
$this->assertCount( 0, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'invalid_tested_upto_minor' ) ) );
269+
270+
// There must be outdated_tested_upto_header error.
271+
$this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'outdated_tested_upto_header' ) ) );
272+
}
273+
241274
public function test_run_with_errors_missing_readme_headers() {
242275
$readme_check = new Plugin_Readme_Check();
243276
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-upgrade-notice/load.php' );

0 commit comments

Comments
 (0)