Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\License_Utils;
use WordPress\Plugin_Check\Traits\Mode_Aware;
use WordPress\Plugin_Check\Traits\Readme_Utils;
use WordPress\Plugin_Check\Traits\Stable_Check;
use WordPress\Plugin_Check\Traits\URL_Utils;
use WordPress\Plugin_Check\Traits\Version_Utils;
Expand All @@ -22,15 +23,18 @@
* Check for plugin header fields.
*
* @since 1.2.0
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Plugin_Header_Fields_Check implements Static_Check {

use Amend_Check_Result;
use License_Utils;
use Mode_Aware;
use Readme_Utils;
use Stable_Check;
use URL_Utils;
use Version_Utils;
use Mode_Aware;

/**
* Gets the categories for the check.
Expand Down
67 changes: 65 additions & 2 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use WordPress\Plugin_Check\Checker\Checks\Abstract_File_Check;
use WordPress\Plugin_Check\Lib\Readme\Parser as PCPParser;
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\Find_Readme;
use WordPress\Plugin_Check\Traits\Language_Utils;
use WordPress\Plugin_Check\Traits\License_Utils;
use WordPress\Plugin_Check\Traits\Readme_Utils;
use WordPress\Plugin_Check\Traits\Stable_Check;
use WordPress\Plugin_Check\Traits\URL_Utils;
use WordPress\Plugin_Check\Traits\Version_Utils;
Expand All @@ -31,7 +31,7 @@
class Plugin_Readme_Check extends Abstract_File_Check {

use Amend_Check_Result;
use Find_Readme;
use Readme_Utils;
use Stable_Check;
use License_Utils;
use URL_Utils;
Expand Down Expand Up @@ -123,6 +123,9 @@ protected function check_files( Check_Result $result, array $files ) {

// Check the readme for language.
$this->check_language( $result, $readme_file, $parser );

// Check for mismatched "Tested up to" header between plugin header and readme.
$this->check_tested_up_to_mismatch( $result, $parser, $result->plugin()->main_file() );
}

/**
Expand Down Expand Up @@ -953,6 +956,66 @@ private function check_language( Check_Result $result, string $readme_file, $par
}
}


/**
* Checks for mismatched "Tested up to" header between plugin header and readme.
*
* @since 1.8.0
*
* @param Check_Result $result The Check Result to amend.
* @param DotorgParser|PCPParser $parser The Parser object.
* @param string $plugin_main_file The main plugin file path.
*/
private function check_tested_up_to_mismatch( Check_Result $result, $parser, string $plugin_main_file ) {

// Check if single file plugin, then bail early.
if ( $result->plugin()->is_single_file_plugin() ) {
return;
}

// Get the "Tested up to" value from the readme.
$readme_tested = isset( $parser->tested ) ? $parser->tested : '';

if ( empty( $readme_tested ) ) {
return;
}

// Get the "Tested up to" value from the plugin header.
$tested_header = get_file_data(
$plugin_main_file,
array( 'TestedWP' => 'Tested up to' ),
'plugin'
);

$plugin_tested = isset( $tested_header['TestedWP'] ) ? $tested_header['TestedWP'] : '';
if ( empty( $plugin_tested ) ) {
return;
}

// Normalize versions by removing any suffixes (like -RC1, -beta1).
$readme_tested_normalized = strtok( $readme_tested, '-' );
$plugin_tested_normalized = strtok( $plugin_tested, '-' );

// Compare the two values.
if ( $readme_tested_normalized !== $plugin_tested_normalized ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: 1: Tested up to value from readme, 2: Tested up to value from plugin header */
__( '<strong>Mismatched "Tested up to": %1$s != %2$s.</strong><br>The "Tested up to" value in the readme file must match the "Tested up to" value in the plugin header. If the plugin header has a "Tested up to" value, it will override the readme value, which can cause confusion.', 'plugin-check' ),
esc_html( $readme_tested_normalized ),
esc_html( $plugin_tested_normalized )
),
'mismatched_tested_up_to_header',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
7
);
}
}

/**
* Returns ignored warnings.
*
Expand Down
4 changes: 2 additions & 2 deletions includes/Checker/Checks/Plugin_Repo/Trademarks_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use WordPress\Plugin_Check\Checker\Checks\Abstract_File_Check;
use WordPress\Plugin_Check\Lib\Readme\Parser as PCPParser;
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\Find_Readme;
use WordPress\Plugin_Check\Traits\Readme_Utils;
use WordPress\Plugin_Check\Traits\Stable_Check;
use WordPressdotorg\Plugin_Directory\Readme\Parser as DotorgParser;

Expand All @@ -25,7 +25,7 @@
class Trademarks_Check extends Abstract_File_Check {

use Amend_Check_Result;
use Find_Readme;
use Readme_Utils;
use Stable_Check;

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/Plugin_Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Exception;
use WordPress\Plugin_Check\Lib\Readme\Parser as PCPParser;
use WordPress\Plugin_Check\Traits\Find_Readme;
use WordPress\Plugin_Check\Traits\Readme_Utils;
use WordPressdotorg\Plugin_Directory\Readme\Parser as DotorgParser;
use function WP_CLI\Utils\normalize_path;

Expand All @@ -20,7 +20,7 @@
*/
class Plugin_Context {

use Find_Readme;
use Readme_Utils;

/**
* Absolute path of the plugin main file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
/**
* Trait WordPress\Plugin_Check\Traits\Find_Readme
* Trait WordPress\Plugin_Check\Traits\Readme_Utils
*
* @package plugin-check
*/

namespace WordPress\Plugin_Check\Traits;

/**
* Trait for find readme.
* Trait for readme utilities.
*
* @since 1.0.0
*/
trait Find_Readme {
trait Readme_Utils {

/**
* Filter the given array of files for readme files (readme.txt or readme.md).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Plugin Name: Test Plugin Tested Up To Header Only
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin with "Tested up to" only in header.
* Requires at least: 6.0
* Requires PHP: 7.4
* Tested up to: 6.7
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: test-plugin-tested-up-to-header-only
*
* @package test-plugin-tested-up-to-header-only
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== Test Plugin Tested Up To Header Only ===

Contributors: plugin-check
Requires at least: 6.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: testing

Plugin with "Tested up to" only in plugin header - no "Tested up to" in readme.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Plugin Name: Test Plugin Tested Up To Match
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin with matching "Tested up to" headers.
* Requires at least: 6.0
* Requires PHP: 7.4
* Tested up to: 6.7
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: test-plugin-tested-up-to-match
*
* @package test-plugin-tested-up-to-match
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Test Plugin Tested Up To Match ===

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

Plugin with matching "Tested up to" headers - both readme and plugin header have 6.7.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Plugin Name: Test Plugin Tested Up To Mismatch
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin with mismatched "Tested up to" headers.
* Requires at least: 6.0
* Requires PHP: 7.4
* Tested up to: 6.5
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: test-plugin-tested-up-to-mismatch
*
* @package test-plugin-tested-up-to-mismatch
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Test Plugin Tested Up To Mismatch ===

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

Plugin with mismatched "Tested up to" headers - readme has 6.7, plugin header has 6.5.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Plugin Name: Test Plugin Tested Up To Readme Only
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Test plugin with "Tested up to" only in readme.
* Requires at least: 6.0
* Requires PHP: 7.4
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: test-plugin-tested-up-to-readme-only
*
* @package test-plugin-tested-up-to-readme-only
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== Test Plugin Tested Up To Readme Only ===

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

Plugin with "Tested up to" only in readme - no "Tested up to" in plugin header.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,41 @@ public function test_run_with_valid_requires_plugins_header() {

if ( is_wp_version_compatible( '6.5' ) ) {
$this->assertCount( 0, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) );
} else {
// For WordPress < 6.5, the check doesn't run.
$this->assertTrue( true );
}
}

public function test_run_with_mismatched_tested_up_to() {
$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-tested-up-to-mismatch/load.php' );
$check_result = new Check_Result( $check_context );

$check->run( $check_result );

$errors = $check_result->get_errors();

// The "Tested up to" mismatch check has been moved to Plugin_Readme_Check.
// This test now verifies that Plugin_Header_Fields_Check does NOT report this error.
$error_items = wp_list_filter( $errors['load.php'][0][0] ?? array(), array( 'code' => 'mismatched_tested_up_to_header' ) );
$this->assertCount( 0, $error_items );
}

public function test_run_with_matching_tested_up_to() {
$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-tested-up-to-match/load.php' );
$check_result = new Check_Result( $check_context );

$check->run( $check_result );

$errors = $check_result->get_errors();

// Should not have mismatched tested up to error.
$error_items = wp_list_filter( $errors['load.php'][0][0] ?? array(), array( 'code' => 'mismatched_tested_up_to_header' ) );
$this->assertCount( 0, $error_items );
}

public function test_run_with_invalid_mpl1_license() {
$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-plugin-readme-mpl1-license-with-errors/load.php' );
Expand Down
Loading
Loading