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

Update error message for plugin_header_invalid_requires_wp code #827

Merged
merged 3 commits into from
Dec 12, 2024
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\Stable_Check;
use WordPress\Plugin_Check\Traits\Version_Utils;

/**
* Check for plugin header fields.
Expand All @@ -25,6 +26,7 @@
use Amend_Check_Result;
use License_Utils;
use Stable_Check;
use Version_Utils;

/**
* Gets the categories for the check.
Expand Down Expand Up @@ -245,14 +247,17 @@

if ( ! empty( $plugin_header['RequiresWP'] ) ) {
if ( ! preg_match( '!^\d+\.\d(\.\d+)?$!', $plugin_header['RequiresWP'] ) ) {
$latest_wp_version = $this->get_wordpress_stable_version();
$previous_wp_version = $this->get_wordpress_relative_major_version( $latest_wp_version, -1 );

Check warning on line 251 in includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php#L250-L251

Added lines #L250 - L251 were not covered by tests

$this->add_result_error_for_file(
$result,
sprintf(
/* translators: 1: plugin header field; 2: Example version 6.5.1. 3: Example version 6.6. */
/* translators: 1: plugin header field, 2: Example version 6.7, 3: Example version 6.6 */
__( 'The "%1$s" header in the plugin file should only contain a WordPress version such as "%2$s" or "%3$s".', 'plugin-check' ),
esc_html( $labels['RequiresWP'] ),
'6.5.1',
'6.6'
esc_html( $latest_wp_version ),
esc_html( $previous_wp_version )

Check warning on line 260 in includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php#L259-L260

Added lines #L259 - L260 were not covered by tests
),
'plugin_header_invalid_requires_wp',
$plugin_main_file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ public function test_run_with_errors() {
}
}

public function test_run_with_invalid_requires_wp_header() {
set_transient( 'wp_plugin_check_latest_version_info', array( 'current' => '6.5.1' ) );

$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-header-fields-with-errors/load.php' );
$check_result = new Check_Result( $check_context );

$check->run( $check_result );

$errors = $check_result->get_errors();

$this->assertNotEmpty( $errors );

$error_items = wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_wp' ) );

$this->assertCount( 1, $error_items );
$this->assertStringContainsString( 'such as "6.5" or "6.4"', reset( $error_items )['message'] );

delete_transient( 'wp_plugin_check_latest_version_info' );
}

public function test_run_with_valid_requires_plugins_header() {
/*
* Test plugin has following valid header.
Expand Down
Loading