Skip to content

Commit 0107eca

Browse files
davidperezgarernilambardavidperezgarfrantorres
authored
Merge pull request #1288 from WordPress/1286-checks-updates
Adjust checks for update mode Co-authored-by: ernilambar <nilambar@git.wordpress.org> Co-authored-by: davidperezgar <davidperez@git.wordpress.org> Co-authored-by: frantorres <frantorres@git.wordpress.org>
2 parents 523f062 + 390919c commit 0107eca

4 files changed

Lines changed: 87 additions & 19 deletions

File tree

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public function run( Check_Result $result ) {
515515

516516
$target_path = wp_normalize_path( $result->plugin()->path() . $domain_path );
517517

518-
if ( ! is_dir( $target_path ) ) {
518+
if ( ! is_dir( $target_path ) && $this->is_new_mode( $result ) ) {
519519
$this->add_result_warning_for_file(
520520
$result,
521521
sprintf(

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
1515
use WordPress\Plugin_Check\Traits\Language_Utils;
1616
use WordPress\Plugin_Check\Traits\License_Utils;
17+
use WordPress\Plugin_Check\Traits\Mode_Aware;
1718
use WordPress\Plugin_Check\Traits\Readme_Utils;
1819
use WordPress\Plugin_Check\Traits\Stable_Check;
1920
use WordPress\Plugin_Check\Traits\URL_Utils;
@@ -31,6 +32,7 @@
3132
class Plugin_Readme_Check extends Abstract_File_Check {
3233

3334
use Amend_Check_Result;
35+
use Mode_Aware;
3436
use Readme_Utils;
3537
use Stable_Check;
3638
use License_Utils;
@@ -256,22 +258,38 @@ private function check_headers( Check_Result $result, string $readme_file, $pars
256258
}
257259

258260
if ( version_compare( $tested_upto_major, $latest_wordpress_version, '<' ) ) {
259-
$this->add_result_error_for_file(
260-
$result,
261-
sprintf(
262-
/* translators: 1: currently used version, 2: latest stable WordPress version, 3: 'Tested up to' */
263-
__( '<strong>Tested up to: %1$s &lt; %2$s.</strong><br>The "%3$s" value in your plugin is not set to the current version of WordPress. This means your plugin will not show up in searches, as we require plugins to be compatible and documented as tested up to the most recent version of WordPress.', 'plugin-check' ),
264-
$tested_upto_major,
265-
$latest_wordpress_version,
266-
'Tested up to'
267-
),
268-
'outdated_tested_upto_header',
269-
$readme_file,
270-
0,
271-
0,
272-
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
273-
7
261+
$outdated_tested_message = sprintf(
262+
/* translators: 1: currently used version, 2: latest stable WordPress version, 3: 'Tested up to' */
263+
__( '<strong>Tested up to: %1$s &lt; %2$s.</strong><br>The "%3$s" value in your plugin is not set to the current version of WordPress. This means your plugin will not show up in searches, as we require plugins to be compatible and documented as tested up to the most recent version of WordPress.', 'plugin-check' ),
264+
$tested_upto_major,
265+
$latest_wordpress_version,
266+
'Tested up to'
274267
);
268+
$outdated_tested_docs = 'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information';
269+
270+
if ( $this->is_update_mode( $result ) ) {
271+
$this->add_result_warning_for_file(
272+
$result,
273+
$outdated_tested_message,
274+
'outdated_tested_upto_header',
275+
$readme_file,
276+
0,
277+
0,
278+
$outdated_tested_docs,
279+
5
280+
);
281+
} else {
282+
$this->add_result_error_for_file(
283+
$result,
284+
$outdated_tested_message,
285+
'outdated_tested_upto_header',
286+
$readme_file,
287+
0,
288+
0,
289+
$outdated_tested_docs,
290+
7
291+
);
292+
}
275293
} elseif ( version_compare( $tested_upto_major, number_format( (float) $latest_wordpress_version + 0.1, 1 ), '>' ) ) {
276294
$this->add_result_error_for_file(
277295
$result,

tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ public function test_run_with_errors() {
4141
}
4242
}
4343

44+
public function test_plugin_header_nonexistent_domain_path_skipped_in_update_mode() {
45+
$check = new Plugin_Header_Fields_Check();
46+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-header-fields-with-errors/load.php', '', 'update' );
47+
$check_result = new Check_Result( $check_context );
48+
49+
$check->run( $check_result );
50+
51+
$warnings = $check_result->get_warnings();
52+
53+
$this->assertArrayHasKey( 'load.php', $warnings, 'Fixture should still emit warnings for the main plugin file in update mode.' );
54+
$this->assertCount(
55+
1,
56+
wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'textdomain_mismatch' ) ),
57+
'Unrelated warnings must still run so we know the check executed (same fixture as test_run_with_errors).'
58+
);
59+
$this->assertCount(
60+
0,
61+
wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_nonexistent_domain_path' ) )
62+
);
63+
}
64+
4465
public function test_run_with_invalid_requires_wp_header() {
4566
set_transient( 'wp_plugin_check_latest_version_info', array( 'current' => '6.5.1' ) );
4667

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,50 @@ public function test_run_with_errors_no_license() {
203203
}
204204

205205
public function test_run_with_errors_tested_upto() {
206+
set_transient( 'wp_plugin_check_latest_version_info', array( 'current' => '6.5.0' ) );
207+
206208
$readme_check = new Plugin_Readme_Check();
207209
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-tested-upto/load.php' );
208210
$check_result = new Check_Result( $check_context );
209211

210212
$readme_check->run( $check_result );
211213

212-
$errors = $check_result->get_errors();
214+
delete_transient( 'wp_plugin_check_latest_version_info' );
215+
216+
$errors = $check_result->get_errors();
217+
$warnings = $check_result->get_warnings();
213218

214219
$this->assertNotEmpty( $errors );
215220
$this->assertArrayHasKey( 'readme.txt', $errors );
216221

217-
// Check for tested upto.
222+
// Check for tested upto (default mode is new).
218223
$this->assertArrayHasKey( 0, $errors['readme.txt'] );
219224
$this->assertArrayHasKey( 0, $errors['readme.txt'][0] );
220-
$this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'outdated_tested_upto_header' ) ) );
225+
$error_items = wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'outdated_tested_upto_header' ) );
226+
$this->assertCount( 1, $error_items );
227+
$this->assertSame( 7, reset( $error_items )['severity'] );
228+
$this->assertCount( 0, wp_list_filter( $warnings['readme.txt'][0][0] ?? array(), array( 'code' => 'outdated_tested_upto_header' ) ) );
229+
}
230+
231+
public function test_outdated_tested_upto_header_reported_as_warning_in_update_mode() {
232+
set_transient( 'wp_plugin_check_latest_version_info', array( 'current' => '6.5.0' ) );
233+
234+
$readme_check = new Plugin_Readme_Check();
235+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-tested-upto/load.php', '', 'update' );
236+
$check_result = new Check_Result( $check_context );
237+
238+
$readme_check->run( $check_result );
239+
240+
delete_transient( 'wp_plugin_check_latest_version_info' );
241+
242+
$errors = $check_result->get_errors();
243+
$warnings = $check_result->get_warnings();
244+
245+
$this->assertCount( 0, wp_list_filter( $errors['readme.txt'][0][0] ?? array(), array( 'code' => 'outdated_tested_upto_header' ) ) );
246+
247+
$warning_items = wp_list_filter( $warnings['readme.txt'][0][0] ?? array(), array( 'code' => 'outdated_tested_upto_header' ) );
248+
$this->assertCount( 1, $warning_items );
249+
$this->assertSame( 5, reset( $warning_items )['severity'] );
221250
}
222251

223252
public function test_run_with_errors_tested_upto_minor_same_major_version() {

0 commit comments

Comments
 (0)