Skip to content

Commit

Permalink
Check minor version tested up
Browse files Browse the repository at this point in the history
  • Loading branch information
davidperezgar committed Mar 5, 2025
1 parent bc72bd4 commit 1585ca2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
17 changes: 17 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
__( '<strong>Tested up to: %s</strong><br>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];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Test Plugin Readme Errors (tested upto)
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin for the Readme check.
* Requires at least: 6.0
* Requires PHP: 5.6
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-readme-errors-tested-upto
*
* @package test-plugin-readme-errors-tested-upto
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Test Plugin Readme Errors (tested upto) ===

Contributors: plugin-check
Requires at least: 6.0
Tested up to: 6.1.1
Requires PHP: 5.6
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: testing, security

Plugin description.
27 changes: 24 additions & 3 deletions tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ public function test_run_with_errors_tested_upto() {
$this->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' );
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1585ca2

Please sign in to comment.