Skip to content

Commit

Permalink
Update readme tests to make sure only readme file checks are tested
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Oct 30, 2024
1 parent 5a54a9f commit 5d28a05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
16 changes: 16 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ private function check_license( Check_Result $result, string $readme_file, Parse
$this->add_result_warning_for_file(
$result,
__( '<strong>Your plugin has an invalid license declared.</strong><br>Please update your readme with a valid SPDX license identifier.', 'plugin-check' ),
'invalid_license_identifier',

Check warning on line 330 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php#L330

Added line #L330 was not covered by tests
$readme_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#no-gpl-compatible-license-declared',
9
);

return;

Check warning on line 338 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php#L338

Added line #L338 was not covered by tests
}

// Test for a valid GPL compatible license.
if ( ! $this->is_gpl_compatible_license( $license ) ) {
$this->add_result_warning_for_file(
$result,
__( '<strong>Your plugin has an invalid license declared.</strong><br>Please update your readme with a valid GPL compatible license identifier.', 'plugin-check' ),
'invalid_license',

Check warning on line 346 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php#L345-L346

Added lines #L345 - L346 were not covered by tests
$readme_file,
0,
Expand Down
23 changes: 12 additions & 11 deletions tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function test_run_with_errors_license() {
// Check for invalid license warning.
$this->assertArrayHasKey( 0, $warnings['readme.txt'] );
$this->assertArrayHasKey( 0, $warnings['readme.txt'][0] );
$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license_identifier' ) ) );
}

public function test_run_with_errors_no_license() {
Expand Down Expand Up @@ -189,7 +189,7 @@ public function test_run_with_errors_invalid_license() {
$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'readme.txt', $warnings );

$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license_identifier' ) ) );
}

public function test_run_without_error_mpl2_license() {
Expand All @@ -199,9 +199,10 @@ public function test_run_without_error_mpl2_license() {

$readme_check->run( $check_result );

$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

$this->assertEmpty( $errors );
$this->assertNotEmpty( $warnings );
$this->assertCount( 0, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license' ) ) );
}

public function test_run_with_errors_mpl1_license() {
Expand All @@ -211,15 +212,15 @@ public function test_run_with_errors_mpl1_license() {

$readme_check->run( $check_result );

$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( 'load.php', $errors );
$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'readme.txt', $warnings );

// Check for invalid license.
$this->assertArrayHasKey( 0, $errors['load.php'] );
$this->assertArrayHasKey( 0, $errors['load.php'][0] );
$this->assertCount( 1, wp_list_filter( $errors['load.php'][0][0], array( 'code' => 'invalid_license' ) ) );
$this->assertArrayHasKey( 0, $warnings['readme.txt'] );
$this->assertArrayHasKey( 0, $warnings['readme.txt'][0] );
$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'invalid_license' ) ) );
}

public function test_run_with_errors_tested_upto() {
Expand Down Expand Up @@ -260,7 +261,7 @@ public function test_run_md_with_errors() {
$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'readme.md', $warnings );

$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'invalid_license' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'invalid_license_identifier' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'mismatched_plugin_name' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'readme_invalid_contributors' ) ) );
}
Expand Down

0 comments on commit 5d28a05

Please sign in to comment.