From 1585ca2e5aef3f3fe1550651006d0c4583f0b6dc Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Wed, 5 Mar 2025 23:20:42 +0100 Subject: [PATCH 1/5] Check minor version tested up --- .../Plugin_Repo/Plugin_Readme_Check.php | 17 ++++++++++++ .../load.php | 16 +++++++++++ .../readme.txt | 12 +++++++++ .../Checks/Plugin_Readme_Check_Tests.php | 27 ++++++++++++++++--- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-errors-tested-upto-minor/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-plugin-readme-errors-tested-upto-minor/readme.txt diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index 9e4ecb287..c4f4d47a7 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -214,6 +214,23 @@ private function check_headers( Check_Result $result, string $readme_file, Parse if ( ! empty( $parser->{$field_key} ) && 'tested' === $field_key ) { list( $tested_upto, ) = explode( '-', $parser->{$field_key} ); + if ( preg_match( '/^\d+\.\d+\.\d+/', $tested_upto ) ) { + $this->add_result_error_for_file( + $result, + sprintf( + /* translators: %s: currently used version */ + __( 'Tested up to: %s
The version number should only include major versions (e.g. 6.7), not minor versions (e.g. 6.7.1).', 'plugin-check' ), + $tested_upto + ), + 'invalid_tested_upto_minor', + $readme_file, + 0, + 0, + 'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information', + 7 + ); + } + if ( preg_match( '#^\d.\d#', $tested_upto, $matches ) ) { $tested_upto = $matches[0]; } diff --git a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-errors-tested-upto-minor/load.php b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-errors-tested-upto-minor/load.php new file mode 100644 index 000000000..e0e144fac --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-errors-tested-upto-minor/load.php @@ -0,0 +1,16 @@ +assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'outdated_tested_upto_header' ) ) ); } + public function test_run_with_errors_tested_upto_minor() { + $readme_check = new Plugin_Readme_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-tested-upto-minor/load.php' ); + $check_result = new Check_Result( $check_context ); + + $readme_check->run( $check_result ); + + $errors = $check_result->get_errors(); + + var_dump( $errors ); + ob_flush(); + + $this->assertNotEmpty( $errors ); + $this->assertArrayHasKey( 'readme.txt', $errors ); + + // Check for tested upto. + $this->assertArrayHasKey( 0, $errors['readme.txt'] ); + $this->assertArrayHasKey( 0, $errors['readme.txt'][0] ); + $this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'invalid_tested_upto_minor' ) ) ); + } + public function test_run_with_errors_missing_readme_headers() { $readme_check = new Plugin_Readme_Check(); $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-errors-upgrade-notice/load.php' ); @@ -488,11 +509,11 @@ public function test_run_with_errors_tested_up_to_latest_plus_two_version() { $this->assertNotEmpty( $errors ); - $filtered_items = wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ); + $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'] ); + $this->assertStringContainsString( 'Tested up to: 6.1', $filtered_items[1]['message'] ); + $this->assertStringContainsString( 'This version of WordPress does not exist (yet).', $filtered_items[1]['message'] ); } public function test_run_without_errors_tested_up_to_latest_plus_one_version() { From 65f24e39cc460480c102aa48fce37f852e69df59 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Wed, 5 Mar 2025 23:23:27 +0100 Subject: [PATCH 2/5] remove debug code --- .../tests/Checker/Checks/Plugin_Readme_Check_Tests.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php index a6103ded1..38f962a06 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php @@ -241,9 +241,6 @@ public function test_run_with_errors_tested_upto_minor() { $errors = $check_result->get_errors(); - var_dump( $errors ); - ob_flush(); - $this->assertNotEmpty( $errors ); $this->assertArrayHasKey( 'readme.txt', $errors ); @@ -509,7 +506,7 @@ public function test_run_with_errors_tested_up_to_latest_plus_two_version() { $this->assertNotEmpty( $errors ); - $filtered_items = wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) );å + $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[1]['message'] ); From 45c3843cd748d7775b10e875bf2c82cc82678508 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 6 Mar 2025 18:47:45 +0100 Subject: [PATCH 3/5] dynamic example version --- .../Plugin_Repo/Plugin_Readme_Check.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index c4f4d47a7..adcd421bc 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -214,12 +214,18 @@ private function check_headers( Check_Result $result, string $readme_file, Parse if ( ! empty( $parser->{$field_key} ) && 'tested' === $field_key ) { list( $tested_upto, ) = explode( '-', $parser->{$field_key} ); + $tested_upto_major = $tested_upto; + if ( preg_match( '#^\d.\d#', $tested_upto, $matches ) ) { + $tested_upto_major = $matches[0]; + } + if ( preg_match( '/^\d+\.\d+\.\d+/', $tested_upto ) ) { $this->add_result_error_for_file( $result, sprintf( /* translators: %s: currently used version */ - __( 'Tested up to: %s
The version number should only include major versions (e.g. 6.7), not minor versions (e.g. 6.7.1).', 'plugin-check' ), + __( 'Tested up to:
The version number should only include major versions %1$s, not minor versions %2$s.', 'plugin-check' ), + $tested_upto_major, $tested_upto ), 'invalid_tested_upto_minor', @@ -231,18 +237,14 @@ private function check_headers( Check_Result $result, string $readme_file, Parse ); } - if ( preg_match( '#^\d.\d#', $tested_upto, $matches ) ) { - $tested_upto = $matches[0]; - } - $latest_wordpress_version = $this->get_wordpress_stable_version(); - if ( version_compare( $tested_upto, $latest_wordpress_version, '<' ) ) { + if ( version_compare( $tested_upto_major, $latest_wordpress_version, '<' ) ) { $this->add_result_error_for_file( $result, sprintf( /* translators: 1: currently used version, 2: latest stable WordPress version, 3: 'Tested up to' */ __( 'Tested up to: %1$s < %2$s.
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' ), - $tested_upto, + $tested_upto_major, $latest_wordpress_version, 'Tested up to' ), @@ -253,13 +255,13 @@ 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( $tested_upto, number_format( (float) $latest_wordpress_version + 0.1, 1 ), '>' ) ) { + } elseif ( version_compare( $tested_upto_major, 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' */ __( 'Tested up to: %1$s.
The "%2$s" value in your plugin is not valid. This version of WordPress does not exist (yet).', 'plugin-check' ), - $tested_upto, + $tested_upto_major, 'Tested up to' ), 'nonexistent_tested_upto_header', From a2dd556aecfe6bae0e5d258f618c0ab1db8b6946 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 6 Mar 2025 18:52:03 +0100 Subject: [PATCH 4/5] add more lines to avoid this error --- phpmd.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpmd.xml b/phpmd.xml index 3c4bb3789..9d6e21b61 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -26,6 +26,12 @@ + + + + + + From eff69a2c4ac3ec51d2a3a1942e5613c67a8ea7cf Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 6 Mar 2025 18:56:59 +0100 Subject: [PATCH 5/5] SuppressWarnings(PHPMD.ExcessiveMethodLength) --- includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php | 2 ++ phpmd.xml | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index adcd421bc..765afa2c9 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -191,6 +191,8 @@ private function check_name( Check_Result $result, string $readme_file, Parser $ * @param Check_Result $result The Check Result to amend. * @param string $readme_file Readme file. * @param Parser $parser The Parser object. + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ private function check_headers( Check_Result $result, string $readme_file, Parser $parser ) { $ignored_warnings = $this->get_ignored_warnings( $parser ); diff --git a/phpmd.xml b/phpmd.xml index 9d6e21b61..3c4bb3789 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -26,12 +26,6 @@ - - - - - -