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 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
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.
22 changes: 20 additions & 2 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,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 @@ -491,8 +509,8 @@ public function test_run_with_errors_tested_up_to_latest_plus_two_version() {
$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'] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this test was affected by the PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap. I think that is because of the array of elements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$filtered_items = array_values( wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'nonexistent_tested_upto_header' ) ) ); If we use array_values() here we could make test more robust and it will whatever position this exists in the $errors array.

$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
Loading