Skip to content

Commit

Permalink
Interactivity API: Ensure proper directive processing on special elem…
Browse files Browse the repository at this point in the history
…ents.

Adds a test to ensure proper processing of directives on special HTML elements,
or HTML which contains special elements. These special elements are defined by
the HTML API and are the HTML elements which cannot contain other tags, such as
the IFRAME, SCRIPT, TEXTAREA, TITLE, elements, etc...

The server diretive processor performs a custom tracking of HTML structure and
this test ensures it isn't mislead by the handling of those special elements.

Developed in #6247
Discussed in https://core.trac.wordpress.org/ticket/60746

Props santosguillamot, cbravobernal, mukesh27, westonruter, swissspidy, dmsnell.
Follow-up to [57348].
Fixes #60746.



git-svn-id: https://develop.svn.wordpress.org/trunk@57822 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
dmsnell committed Mar 12, 2024
1 parent 234ec16 commit b1b97f9
Showing 1 changed file with 28 additions and 1 deletion.
Expand Up @@ -10,7 +10,7 @@
*
* @group interactivity-api
*/
class Tests_Interactivity_API_Functions extends WP_UnitTestCase {
class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCase {
/**
* Set up.
*/
Expand Down Expand Up @@ -390,4 +390,31 @@ public function test_wp_interactivity_data_wp_context_with_json_flags() {
$this->assertEquals( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', wp_interactivity_data_wp_context( array( 'quot' => '"baz"' ) ) );
$this->assertEquals( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) );
}

/**
* Tests that directives processing of tags that don't visit closer tag work.
*
* @ticket 60746
*
* @covers ::wp_interactivity_process_directives_of_interactive_blocks
*/
public function test_process_directives_in_tags_that_dont_visit_closer_tag() {
register_block_type(
'test/custom-directive-block',
array(
'render_callback' => function () {
return '<iframe data-wp-interactive="nameSpace" ' . wp_interactivity_data_wp_context( array( 'text' => 'test' ) ) . ' data-wp-class--test="context.text" src="1"></iframe>';
},
'supports' => array(
'interactivity' => true,
),
)
);
$post_content = '<!-- wp:test/custom-directive-block /-->';
$processed_content = do_blocks( $post_content );
$processor = new WP_HTML_Tag_Processor( $processed_content );
$processor->next_tag( array( 'class_name' => 'test' ) );
unregister_block_type( 'test/custom-directive-block' );
$this->assertEquals( '1', $processor->get_attribute( 'src' ) );
}
}

0 comments on commit b1b97f9

Please sign in to comment.