Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check minor version tested up #886

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -214,18 +216,37 @@ 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 = $matches[0];
$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 */
__( '<strong>Tested up to: %1$s</strong><br>The version number should only include major versions %2$s.', 'plugin-check' ),
$tested_upto,
$tested_upto_major
),
'invalid_tested_upto_minor',
$readme_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
7
);
}

$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' */
__( '<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' ),
$tested_upto,
$tested_upto_major,
$latest_wordpress_version,
'Tested up to'
),
Expand All @@ -236,13 +257,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' */
__( '<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' ),
$tested_upto,
$tested_upto_major,
'Tested up to'
),
'nonexistent_tested_upto_header',
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.
20 changes: 19 additions & 1 deletion 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,24 @@ 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();

$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,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 = array_values( 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'] );
Expand Down
Loading