From cb16d8d8d7e263d856741092b80dd241de81aed7 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 17 Jan 2024 15:18:23 +1000 Subject: [PATCH 1/3] Add a apply_filters() unit test. --- tests/phpunit/tests/export/hooks.inc | 1 + tests/phpunit/tests/export/hooks.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tests/phpunit/tests/export/hooks.inc b/tests/phpunit/tests/export/hooks.inc index 3cc11f4..54cf8f8 100644 --- a/tests/phpunit/tests/export/hooks.inc +++ b/tests/phpunit/tests/export/hooks.inc @@ -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 ); diff --git a/tests/phpunit/tests/export/hooks.php b/tests/phpunit/tests/export/hooks.php index adf4ef8..84c6cff 100644 --- a/tests/phpunit/tests/export/hooks.php +++ b/tests/phpunit/tests/export/hooks.php @@ -35,5 +35,9 @@ public function test_hook_names_standardized() { $this->assertFileContainsHook( array( 'name' => 'hook_{$object->property}_pre', 'line' => 7 ) ); + + $this->assertFileContainsHook( + array( 'type' => 'apply_filters', 'name' => 'plain_filter', 'line' => 8 ) + ); } } From 76be0eec863270043b72ade9c07922c2a09b0dcb Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 17 Jan 2024 16:55:14 +1000 Subject: [PATCH 2/3] Add a way to test that the arguments are extracted. --- tests/phpunit/includes/export-testcase.php | 8 +++++++- tests/phpunit/tests/export/hooks.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/export-testcase.php b/tests/phpunit/includes/export-testcase.php index 235e956..d74bf9f 100644 --- a/tests/phpunit/includes/export-testcase.php +++ b/tests/phpunit/includes/export-testcase.php @@ -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; diff --git a/tests/phpunit/tests/export/hooks.php b/tests/phpunit/tests/export/hooks.php index 84c6cff..4f289ac 100644 --- a/tests/phpunit/tests/export/hooks.php +++ b/tests/phpunit/tests/export/hooks.php @@ -37,7 +37,13 @@ public function test_hook_names_standardized() { ); $this->assertFileContainsHook( - array( 'type' => 'apply_filters', 'name' => 'plain_filter', 'line' => 8 ) + array( + 'type' => 'filter', + 'name' => 'plain_filter', + 'line' => 8, + 'arguments.0.name' => '$variable', + 'arguments.1.name' => '$filter_context' + ) ); } } From 2c4a40a097dddefe446215b74f0ef7f8735cb557 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 17 Jan 2024 17:32:08 +1000 Subject: [PATCH 3/3] Add test groups --- tests/phpunit/tests/export/docblocks.php | 3 +++ tests/phpunit/tests/export/hooks.php | 3 +++ tests/phpunit/tests/export/namespace.php | 3 +++ tests/phpunit/tests/export/uses/constructor.php | 3 +++ tests/phpunit/tests/export/uses/methods.php | 3 +++ tests/phpunit/tests/export/uses/nested.php | 3 +++ 6 files changed, 18 insertions(+) diff --git a/tests/phpunit/tests/export/docblocks.php b/tests/phpunit/tests/export/docblocks.php index 0d49b15..2c42b1c 100644 --- a/tests/phpunit/tests/export/docblocks.php +++ b/tests/phpunit/tests/export/docblocks.php @@ -8,6 +8,9 @@ /** * Test that docblocks are exported correctly. + * + * @group export + * @group export-docblocks */ class Export_Docblocks extends Export_UnitTestCase { diff --git a/tests/phpunit/tests/export/hooks.php b/tests/phpunit/tests/export/hooks.php index 4f289ac..09dd082 100644 --- a/tests/phpunit/tests/export/hooks.php +++ b/tests/phpunit/tests/export/hooks.php @@ -8,6 +8,9 @@ /** * Test that hooks are exported correctly. + * + * @group export + * @group export-hooks */ class Export_Hooks extends Export_UnitTestCase { diff --git a/tests/phpunit/tests/export/namespace.php b/tests/phpunit/tests/export/namespace.php index dc7834f..989b44f 100644 --- a/tests/phpunit/tests/export/namespace.php +++ b/tests/phpunit/tests/export/namespace.php @@ -8,6 +8,9 @@ /** * Test that hooks are exported correctly. + * + * @group export + * @group export-namespace */ class Export_Namespace extends Export_UnitTestCase { diff --git a/tests/phpunit/tests/export/uses/constructor.php b/tests/phpunit/tests/export/uses/constructor.php index 202eb7d..3d0ebf4 100644 --- a/tests/phpunit/tests/export/uses/constructor.php +++ b/tests/phpunit/tests/export/uses/constructor.php @@ -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 { diff --git a/tests/phpunit/tests/export/uses/methods.php b/tests/phpunit/tests/export/uses/methods.php index 2def239..31aabb9 100644 --- a/tests/phpunit/tests/export/uses/methods.php +++ b/tests/phpunit/tests/export/uses/methods.php @@ -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 { diff --git a/tests/phpunit/tests/export/uses/nested.php b/tests/phpunit/tests/export/uses/nested.php index 4caaef6..536d321 100644 --- a/tests/phpunit/tests/export/uses/nested.php +++ b/tests/phpunit/tests/export/uses/nested.php @@ -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 {