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

Change error type for License check error codes #772

Merged
merged 2 commits into from
Nov 6, 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
4 changes: 2 additions & 2 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@

// Test for a valid SPDX license identifier.
if ( ! $this->is_license_valid_identifier( $license ) ) {
$this->add_result_warning_for_file(
$this->add_result_error_for_file(

Check warning on line 329 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#L329

Added line #L329 was not covered by tests
$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',
Expand Down Expand Up @@ -371,7 +371,7 @@

// Check different license types.
if ( ! empty( $plugin_license ) && ! empty( $license ) && $license !== $plugin_license ) {
$this->add_result_warning_for_file(
$this->add_result_error_for_file(

Check warning on line 374 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#L374

Added line #L374 was not covered by tests
$result,
__( '<strong>Your plugin has a different license declared in the readme file and plugin header.</strong><br>Please update your readme with a valid GPL license identifier.', 'plugin-check' ),
'license_mismatch',
Expand Down
22 changes: 11 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 @@ -148,18 +148,18 @@ public function test_run_with_errors_license() {

$readme_check->run( $check_result );

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

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

// 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' ) ) );
// Check for invalid license.
$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_license' ) ) );

// Check for not same license warning.
$this->assertCount( 1, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'license_mismatch' ) ) );
// Check for not same license.
$this->assertCount( 1, wp_list_filter( $errors['readme.txt'][0][0], array( 'code' => 'license_mismatch' ) ) );
}

public function test_run_with_errors_no_license() {
Expand Down Expand Up @@ -244,12 +244,12 @@ public function test_run_md_with_errors() {
$this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'trunk_stable_tag' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'outdated_tested_upto_header' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'default_readme_text' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'invalid_license' ) ) );
$this->assertCount( 1, wp_list_filter( $errors['readme.md'][0][0], array( 'code' => 'license_mismatch' ) ) );

$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' => 'license_mismatch' ) ) );
$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