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

Unit Test: Ensure that apply_filters is extracted, and that the parameters to it are as well. #239

Merged
merged 3 commits into from
Jan 18, 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
8 changes: 7 additions & 1 deletion tests/phpunit/includes/export-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ protected function assertEntityContains( $entity, $type, $expected ) {
foreach ( $entity[ $type ] as $exported ) {
if ( $exported['line'] == $expected['line'] ) {
foreach ( $expected as $key => $expected_value ) {
$this->assertEquals( $expected_value, $exported[ $key ] );
if ( isset( $exported[ $key ] ) ) {
$exported_value = $exported[ $key ];
} else {
$exported_value = _wp_array_get( $exported, explode( '.', $key ), null );
}

$this->assertEquals( $expected_value, $exported_value );
}

return;
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/export/docblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* Test that docblocks are exported correctly.
*
* @group export
* @group export-docblocks
*/
class Export_Docblocks extends Export_UnitTestCase {

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/tests/export/hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ do_action( "action_with_double_quotes" );
do_action( $variable . '-action' );
do_action( "another-{$variable}-action" );
do_action( 'hook_' . $object->property . '_pre' );
apply_filters( 'plain_filter', $variable, $filter_context );
13 changes: 13 additions & 0 deletions tests/phpunit/tests/export/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* Test that hooks are exported correctly.
*
* @group export
* @group export-hooks
*/
class Export_Hooks extends Export_UnitTestCase {

Expand Down Expand Up @@ -35,5 +38,15 @@ public function test_hook_names_standardized() {
$this->assertFileContainsHook(
array( 'name' => 'hook_{$object->property}_pre', 'line' => 7 )
);

$this->assertFileContainsHook(
array(
'type' => 'filter',
'name' => 'plain_filter',
'line' => 8,
'arguments.0.name' => '$variable',
'arguments.1.name' => '$filter_context'
)
);
}
}
3 changes: 3 additions & 0 deletions tests/phpunit/tests/export/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* Test that hooks are exported correctly.
*
* @group export
* @group export-namespace
*/
class Export_Namespace extends Export_UnitTestCase {

Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/export/uses/constructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* Test that use of the __construct() method is exported for new Class() statements.
*
* @group export-uses
* @group export-uses-constructor
*/
class Export_Constructor_Use extends Export_UnitTestCase {

Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/export/uses/methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* Test that method use is exported correctly.
*
* @group export-uses
* @group export-uses-methods
*/
class Export_Method_Use extends Export_UnitTestCase {

Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/export/uses/nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* Test that function use is exported correctly when function declarations are nested.
*
* @group export-uses
* @group export-uses-nested
*/
class Export_Nested_Function_Use extends Export_UnitTestCase {

Expand Down