Skip to content

Commit

Permalink
Merge branch 'trunk' into add-experimental-admin-option
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar authored Feb 19, 2025
2 parents 5861b96 + 2613611 commit c2de86d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 19 deletions.
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"npm": ">=10.2.3"
},
"devDependencies": {
"@wordpress/env": "^10.17.0",
"@wordpress/scripts": "^30.11.0",
"@wordpress/env": "^10.18.0",
"@wordpress/scripts": "^30.10.0",
"gherkin-lint": "^4.2.4",
"patch-package": "^8.0.0"
},
Expand Down
22 changes: 21 additions & 1 deletion tests/behat/features/plugin-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,12 @@ Feature: Test that the WP-CLI command works.
*/
$text = 'I am bad'; // This should trigger the error.
$string = 'This is experimental string.';
"""
And I run the WP-CLI command `plugin activate foo-sample`

# The two checks from pcp-addon should be available.
# The two stable checks from pcp-addon should be available.
When I run the WP-CLI command `plugin list-checks --fields=slug,category,stability --format=csv`
Then STDOUT should contain:
"""
Expand All @@ -503,6 +505,17 @@ Feature: Test that the WP-CLI command works.
"""
example_runtime,new_category,stable
"""
And STDOUT should not contain:
"""
example_experimental,new_category,experimental
"""

# Experimental checks from pcp-addon should be available.
When I run the WP-CLI command `plugin list-checks --fields=slug,category,stability --format=csv --include-experimental`
Then STDOUT should contain:
"""
example_experimental,new_category,experimental
"""

# The new check category should therefore also be available.
When I run the WP-CLI command `plugin list-check-categories --fields=slug,name --format=csv`
Expand All @@ -525,6 +538,13 @@ Feature: Test that the WP-CLI command works.
prohibited_text_detected,ERROR
"""

# Running experimental checks, including the one from pcp-addon
When I run the WP-CLI command `plugin check foo-sample --fields=code,type --format=csv --include-experimental`
Then STDOUT should contain:
"""
experimental_text_detected,ERROR
"""

# Running only the check from pcp-addon
When I run the WP-CLI command `plugin check foo-sample --checks=example_static --fields=code,type --format=csv`
Then STDOUT should contain:
Expand Down
41 changes: 41 additions & 0 deletions tests/behat/testdata/pcp-addon/Example_Experimental_Check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use WordPress\Plugin_Check\Checker\Check_Result;
use WordPress\Plugin_Check\Checker\Checks\Abstract_File_Check;
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\Experimental_Check;

class Example_Experimental_Check extends Abstract_File_Check {

use Amend_Check_Result;
use Experimental_Check;

public function get_categories() {
return array( 'new_category' );
}

protected function check_files( Check_Result $result, array $files ) {
$php_files = self::filter_files_by_extension( $files, 'php' );
$file = self::file_preg_match( '#experimental#', $php_files );
if ( $file ) {
$this->add_result_error_for_file(
$result,
__( 'Experimental text found.', 'pcp-addon' ),
'experimental_text_detected',
$file,
0,
0,
'',
7
);
}
}

public function get_description(): string {
return '';
}

public function get_documentation_url(): string {
return '';
}
}
6 changes: 4 additions & 2 deletions tests/behat/testdata/pcp-addon/pcp-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ function ( array $categories ) {
function ( array $checks ) {
require_once plugin_dir_path( __FILE__ ) . 'Example_Static_Check.php';
require_once plugin_dir_path( __FILE__ ) . 'Example_Runtime_Check.php';
require_once plugin_dir_path( __FILE__ ) . 'Example_Experimental_Check.php';

return array_merge(
$checks,
array(
'example_static' => new Example_Static_Check(),
'example_runtime' => new Example_Runtime_Check(),
'example_static' => new Example_Static_Check(),
'example_runtime' => new Example_Runtime_Check(),
'example_experimental' => new Example_Experimental_Check(),
)
);
}
Expand Down

0 comments on commit c2de86d

Please sign in to comment.