Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions tests/phpunit/tests/dependencies/wpInlineScriptTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,74 @@ static function ( $attributes ) {
)
);
}

/**
* Test the behavior of generated script tag attributes passed different values and types of values.
*
* @ticket 64500
*/
public function test_script_tag_attribute_value_types() {
$expected = <<<'HTML'
<script
true
null
empty-string=""
0-string="0"
1-string="1"
0-numeric="0"
1-numeric="1"
>
"script data";
</script>

HTML;

$this->assertEqualHTML(
$expected,
wp_get_inline_script_tag(
'"script data";',
array(
'true' => true,
'false' => false,
'null' => null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have always wondered if we should treat null and false values equivalently in set_attribute(). This scenario almost makes it seem important to do so, because who is going to expect the string value "null" to appear when sending a null value?

'empty-string' => '',
'0-string' => '0',
'1-string' => '1',
'0-numeric' => 0,
'1-numeric' => 1,
)
),
);
}

/**
* Test the behavior of generated script tag repeated attributes.
*
* HTML will ignore case-insensitive repeated attributes. Ensure that the handling of input
* attributes aligns with expectations.
*
* @ticket 64500
*/
public function test_script_tag_repeat_attributes() {
$expected = <<<'HTML'
<script test="test-a">
"script data";
</script>

HTML;

$this->assertEqualHTML(
$expected,
wp_get_inline_script_tag(
'"script data";',
array(
'test' => 'test-a',
'tesT' => 'tesT-b',
'teST' => 'teST-c',
'tEST' => 'tEST-d',
'TEST' => 'TEST-e',
)
),
);
}
}
64 changes: 64 additions & 0 deletions tests/phpunit/tests/dependencies/wpScriptTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,68 @@ static function ( $attributes ) {
)
);
}

/**
* Test the behavior of generated script tag attributes passed different values and types of values.
*
* @ticket 64500
*/
public function test_script_tag_attribute_value_types() {
$expected = <<<'HTML'
<script
true
null
empty-string=""
0-string="0"
1-string="1"
0-numeric="0"
1-numeric="1"
></script>

HTML;

$this->assertEqualHTML(
$expected,
wp_get_script_tag(
array(
'true' => true,
'false' => false,
'null' => null,
'empty-string' => '',
'0-string' => '0',
'1-string' => '1',
'0-numeric' => 0,
'1-numeric' => 1,
)
),
);
}

/**
* Test the behavior of generated script tag repeated attributes.
*
* HTML will ignore case-insensitive repeated attributes. Ensure that the handling of input
* attributes aligns with expectations.
*
* @ticket 64500
*/
public function test_script_tag_repeat_attributes() {
$expected = <<<'HTML'
<script test="test-a"></script>

HTML;

$this->assertEqualHTML(
$expected,
wp_get_script_tag(
array(
'test' => 'test-a',
'tesT' => 'tesT-b',
'teST' => 'teST-c',
'tEST' => 'tEST-d',
'TEST' => 'TEST-e',
)
),
);
}
}
Loading