From ccacd9f1cd633993895d8f37307848339741e8f2 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 16 Feb 2023 11:54:01 +0100 Subject: [PATCH 1/4] Add test for directives with colon --- phpunit/directives/wp-process-directives.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/phpunit/directives/wp-process-directives.php b/phpunit/directives/wp-process-directives.php index 30766560..2962dcb7 100644 --- a/phpunit/directives/wp-process-directives.php +++ b/phpunit/directives/wp-process-directives.php @@ -47,4 +47,18 @@ function( $p ) { $tags = new WP_HTML_Tag_Processor( $markup ); wp_process_directives( $tags, 'foo-', array(), $attribute_directives ); } + + public function test_directives_with_type_and_name_are_processed_correctly() { + $test_helper = $this->createMock( Helper_Class::class ); + $test_helper->expects( $this->atLeastOnce() ) + ->method( 'process_foo_test' ); + + $attribute_directives = array( + 'foo-test' => array( $test_helper, 'process_foo_test' ), + ); + + $markup = '
'; + $tags = new WP_HTML_Tag_Processor( $markup ); + wp_process_directives( $tags, 'foo-', array(), $attribute_directives ); + } } From 1c9a07a9c9622dc49abfede069ba55d36bf8285a Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 16 Feb 2023 12:08:10 +0100 Subject: [PATCH 2/4] Get directive type before looking for processor --- src/directives/wp-process-directives.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/directives/wp-process-directives.php b/src/directives/wp-process-directives.php index 2d20404a..901861ed 100644 --- a/src/directives/wp-process-directives.php +++ b/src/directives/wp-process-directives.php @@ -30,7 +30,12 @@ function wp_process_directives( $tags, $prefix, $tag_directives, $attribute_dire } } } else { + $get_directive_type = function ( $attr ) { + return strtok( $attr, ':' ); + }; + $attributes = $tags->get_attribute_names_with_prefix( $prefix ); + $attributes = array_map( $get_directive_type, $attributes ); $attributes = array_intersect( $attributes, array_keys( $attribute_directives ) ); // If this is an open tag, and if it either has attribute directives, From dc34b60447003ac3a594a63f451a298f016262fd Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 16 Feb 2023 12:09:35 +0100 Subject: [PATCH 3/4] Add a comment --- src/directives/wp-process-directives.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/directives/wp-process-directives.php b/src/directives/wp-process-directives.php index 901861ed..fe03ebfb 100644 --- a/src/directives/wp-process-directives.php +++ b/src/directives/wp-process-directives.php @@ -30,6 +30,8 @@ function wp_process_directives( $tags, $prefix, $tag_directives, $attribute_dire } } } else { + // Helper that removes the part after the colon before looking + // for the directive processor inside `$attribute_directives`. $get_directive_type = function ( $attr ) { return strtok( $attr, ':' ); }; From 40e6a19af5dc83d22902ac71848690dcdd3f8da5 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Thu, 16 Feb 2023 18:37:03 +0100 Subject: [PATCH 4/4] Change name for directives with colon test Co-authored-by: Bernie Reiter --- phpunit/directives/wp-process-directives.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/directives/wp-process-directives.php b/phpunit/directives/wp-process-directives.php index 2962dcb7..27050f2a 100644 --- a/phpunit/directives/wp-process-directives.php +++ b/phpunit/directives/wp-process-directives.php @@ -48,7 +48,7 @@ function( $p ) { wp_process_directives( $tags, 'foo-', array(), $attribute_directives ); } - public function test_directives_with_type_and_name_are_processed_correctly() { + public function test_directives_with_colon_processed_correctly() { $test_helper = $this->createMock( Helper_Class::class ); $test_helper->expects( $this->atLeastOnce() ) ->method( 'process_foo_test' );