Make WordPress Core

Changeset 61482


Ignore:
Timestamp:
01/14/2026 03:00:41 PM (5 weeks ago)
Author:
jonsurrell
Message:

Scripts: Add script tag attribute handling tests.

Add tests that verify the behavior of wp_get_inline_script_tag() and wp_get_script_tag() attribute handling.

Developed in https://github.com/WordPress/wordpress-develop/pull/10728.

Props jonsurrell, dmsnell.
See #64500.

Location:
trunk/tests/phpunit/tests/dependencies
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/wpInlineScriptTag.php

    r61415 r61482  
    9595        );
    9696    }
     97
     98    /**
     99     * Test the behavior of generated script tag attributes passed different values and types of values.
     100     *
     101     * @ticket 64500
     102     */
     103    public function test_script_tag_attribute_value_types() {
     104        $expected = <<<'HTML'
     105<script
     106    true
     107    null
     108    empty-string=""
     109    0-string="0"
     110    1-string="1"
     111    0-numeric="0"
     112    1-numeric="1"
     113>
     114"script data";
     115</script>
     116
     117HTML;
     118
     119        $this->assertEqualHTML(
     120            $expected,
     121            wp_get_inline_script_tag(
     122                '"script data";',
     123                array(
     124                    'true'         => true,
     125                    'false'        => false,
     126                    'null'         => null,
     127                    'empty-string' => '',
     128                    '0-string'     => '0',
     129                    '1-string'     => '1',
     130                    '0-numeric'    => 0,
     131                    '1-numeric'    => 1,
     132                )
     133            ),
     134        );
     135    }
     136
     137    /**
     138     * Test the behavior of generated script tag repeated attributes.
     139     *
     140     * HTML will ignore case-insensitive repeated attributes. Ensure that the handling of input
     141     * attributes aligns with expectations.
     142     *
     143     * @ticket 64500
     144     */
     145    public function test_script_tag_repeat_attributes() {
     146        $expected = <<<'HTML'
     147<script test="test-a">
     148"script data";
     149</script>
     150
     151HTML;
     152
     153        $this->assertEqualHTML(
     154            $expected,
     155            wp_get_inline_script_tag(
     156                '"script data";',
     157                array(
     158                    'test' => 'test-a',
     159                    'tesT' => 'tesT-b',
     160                    'teST' => 'teST-c',
     161                    'tEST' => 'tEST-d',
     162                    'TEST' => 'TEST-e',
     163                )
     164            ),
     165        );
     166    }
    97167}
  • trunk/tests/phpunit/tests/dependencies/wpScriptTag.php

    r61395 r61482  
    9999        );
    100100    }
     101
     102    /**
     103     * Test the behavior of generated script tag attributes passed different values and types of values.
     104     *
     105     * @ticket 64500
     106     */
     107    public function test_script_tag_attribute_value_types() {
     108        $expected = <<<'HTML'
     109<script
     110    true
     111    null
     112    empty-string=""
     113    0-string="0"
     114    1-string="1"
     115    0-numeric="0"
     116    1-numeric="1"
     117></script>
     118
     119HTML;
     120
     121        $this->assertEqualHTML(
     122            $expected,
     123            wp_get_script_tag(
     124                array(
     125                    'true'         => true,
     126                    'false'        => false,
     127                    'null'         => null,
     128                    'empty-string' => '',
     129                    '0-string'     => '0',
     130                    '1-string'     => '1',
     131                    '0-numeric'    => 0,
     132                    '1-numeric'    => 1,
     133                )
     134            ),
     135        );
     136    }
     137
     138    /**
     139     * Test the behavior of generated script tag repeated attributes.
     140     *
     141     * HTML will ignore case-insensitive repeated attributes. Ensure that the handling of input
     142     * attributes aligns with expectations.
     143     *
     144     * @ticket 64500
     145     */
     146    public function test_script_tag_repeat_attributes() {
     147        $expected = <<<'HTML'
     148<script test="test-a"></script>
     149
     150HTML;
     151
     152        $this->assertEqualHTML(
     153            $expected,
     154            wp_get_script_tag(
     155                array(
     156                    'test' => 'test-a',
     157                    'tesT' => 'tesT-b',
     158                    'teST' => 'teST-c',
     159                    'tEST' => 'tEST-d',
     160                    'TEST' => 'TEST-e',
     161                )
     162            ),
     163        );
     164    }
    101165}
Note: See TracChangeset for help on using the changeset viewer.