Make WordPress Core


Ignore:
Timestamp:
10/21/2025 12:07:16 PM (4 months ago)
Author:
luisherranz
Message:

Interactivity API: Support unique IDs in server-side directives processing.

Server-side logic to support unique IDs in the Interactivity API directives to match what the client is doing (https://github.com/WordPress/gutenberg/pull/72161).

Props santosguillamot, darerodz, luisherranz.
Fixes #64106.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-text.php

    r58594 r61020  
    1313 * @group interactivity-api
    1414 */
    15 class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
     15class Tests_WP_Interactivity_API_WP_Text extends WP_UnitTestCase {
    1616    /**
    1717     * Instance of WP_Interactivity_API.
     
    132132     *
    133133     * @covers ::process_directives
    134      *
    135      * @expectedIncorrectUsage WP_Interactivity_API::_process_directives
    136134     */
    137135    public function test_wp_text_fails_with_unbalanced_and_same_tags_inside_content() {
     
    155153        $this->assertSame( '<div data-wp-text="myPlugin::state.text">&lt;span&gt;Updated&lt;/span&gt;</div>', $new_html );
    156154    }
     155
     156    /**
     157     * Tests it ignores suffixes and unique-ids.
     158     *
     159     * @ticket 64106
     160     *
     161     * @covers ::process_directives
     162     */
     163    public function test_wp_text_ignores_suffixes_and_unique_ids() {
     164        $html     = '<span data-wp-text--suffix="myPlugin::state.text">Text</span>';
     165        $new_html = $this->interactivity->process_directives( $html );
     166        $this->assertSame( $html, $new_html );
     167
     168        $html     = '<span data-wp-text---unique-id="myPlugin::state.text">Text</span>';
     169        $new_html = $this->interactivity->process_directives( $html );
     170        $this->assertSame( $html, $new_html );
     171    }
     172
     173    /**
     174     * Tests first `data-wp-text` works even when suffixes and unique-ids are included.
     175     *
     176     * @ticket 64106
     177     *
     178     * @covers ::process_directives
     179     */
     180    public function test_wp_text_works_even_when_suffixes_and_unique_ids_are_included() {
     181        $original = '<span data-wp-text--suffix="myPlugin::state.text" data-wp-text---unique-id="myPlugin::state.text" data-wp-text="myPlugin::state.text">Text</span>';
     182        $expected = '<span data-wp-text--suffix="myPlugin::state.text" data-wp-text---unique-id="myPlugin::state.text" data-wp-text="myPlugin::state.text">Updated</span>';
     183        $new_html = $this->interactivity->process_directives( $original );
     184        $this->assertSame( $expected, $new_html );
     185    }
    157186}
Note: See TracChangeset for help on using the changeset viewer.