Make WordPress Core

Changeset 57822


Ignore:
Timestamp:
03/12/2024 06:52:20 PM (7 months ago)
Author:
dmsnell
Message:

Interactivity API: Ensure proper directive processing on special elements.

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 https://github.com/WordPress/wordpress-develop/pull/6247
Discussed in https://core.trac.wordpress.org/ticket/60746

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

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php

    r57821 r57822  
    1111 * @group interactivity-api
    1212 */
    13 class Tests_Interactivity_API_Functions extends WP_UnitTestCase {
     13class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCase {
    1414    /**
    1515     * Set up.
     
    391391        $this->assertEquals( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) );
    392392    }
     393
     394    /**
     395     * Tests that directives processing of tags that don't visit closer tag work.
     396     *
     397     * @ticket 60746
     398     *
     399     * @covers ::wp_interactivity_process_directives_of_interactive_blocks
     400     */
     401    public function test_process_directives_in_tags_that_dont_visit_closer_tag() {
     402        register_block_type(
     403            'test/custom-directive-block',
     404            array(
     405                'render_callback' => function () {
     406                    return '<iframe data-wp-interactive="nameSpace" ' . wp_interactivity_data_wp_context( array( 'text' => 'test' ) ) . ' data-wp-class--test="context.text" src="1"></iframe>';
     407                },
     408                'supports'        => array(
     409                    'interactivity' => true,
     410                ),
     411            )
     412        );
     413        $post_content      = '<!-- wp:test/custom-directive-block /-->';
     414        $processed_content = do_blocks( $post_content );
     415        $processor         = new WP_HTML_Tag_Processor( $processed_content );
     416        $processor->next_tag( array( 'class_name' => 'test' ) );
     417        unregister_block_type( 'test/custom-directive-block' );
     418        $this->assertEquals( '1', $processor->get_attribute( 'src' ) );
     419    }
    393420}
Note: See TracChangeset for help on using the changeset viewer.