Skip to content

Commit f8cfdf9

Browse files
committed
Clean up and fix tests
1 parent 3b5ef4e commit f8cfdf9

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class Tests_HtmlApi_WpHtmlTagProcessorScriptTag extends WP_UnitTestCase {
2323
public function test_is_javascript_script_tag( string $html, bool $expected_result ) {
2424
$processor = new WP_HTML_Tag_Processor( $html );
2525
$processor->next_tag();
26-
27-
$this->assertSame( 'SCRIPT', $processor->get_tag(), 'Should be positioned on a SCRIPT tag' );
2826
$this->assertSame(
2927
$expected_result,
3028
$processor->is_javascript_script_tag(),
@@ -37,7 +35,7 @@ public function test_is_javascript_script_tag( string $html, bool $expected_resu
3735
*
3836
* @return array[]
3937
*/
40-
public static function data_is_javascript_script_tag() {
38+
public static function data_is_javascript_script_tag(): array {
4139
return array(
4240
// Script tags without type or language attributes - should be JavaScript.
4341
'Script tag without attributes' => array( '<script></script>', true ),
@@ -57,7 +55,7 @@ public static function data_is_javascript_script_tag() {
5755
// Script tags with falsy but non-empty language attribute.
5856
'Script tag with language="0"' => array( '<script language="0"></script>', false ),
5957

60-
// Script tags with JavaScript MIME types - should be JavaScript.
58+
// Script tags with JavaScript MIME essence - should be JavaScript.
6159
'Script tag with application/ecmascript' => array( '<script type="application/ecmascript"></script>', true ),
6260
'Script tag with application/javascript' => array( '<script type="application/javascript"></script>', true ),
6361
'Script tag with application/x-ecmascript' => array( '<script type="application/x-ecmascript"></script>', true ),
@@ -75,7 +73,7 @@ public static function data_is_javascript_script_tag() {
7573
'Script tag with text/x-ecmascript' => array( '<script type="text/x-ecmascript"></script>', true ),
7674
'Script tag with text/x-javascript' => array( '<script type="text/x-javascript"></script>', true ),
7775

78-
// Case-insensitive matching for JavaScript MIME types.
76+
// Case-insensitive matching for JavaScript MIME essence.
7977
'Script tag with UPPERCASE type' => array( '<script type="TEXT/JAVASCRIPT"></script>', true ),
8078
'Script tag with MixedCase type' => array( '<script type="Text/JavaScript"></script>', true ),
8179
'Script tag with APPLICATION/JAVASCRIPT' => array( '<script type="APPLICATION/JAVASCRIPT"></script>', true ),
@@ -137,9 +135,8 @@ public function test_is_javascript_script_tag_returns_false_before_finding_tags(
137135
* @covers WP_HTML_Tag_Processor::is_javascript_script_tag
138136
*/
139137
public function test_is_javascript_script_tag_returns_false_for_non_html_namespace() {
140-
$processor = new WP_HTML_Tag_Processor( '<svg><script type="text/javascript"></script></svg>' );
141-
$processor->next_tag( 'SCRIPT' );
142-
138+
$processor = new WP_HTML_Tag_Processor( '<script></script>' );
139+
$processor->change_parsing_namespace( 'svg' );
143140
$this->assertFalse(
144141
$processor->is_javascript_script_tag(),
145142
'Should return false for script tags in non-HTML namespace'
@@ -159,8 +156,6 @@ public function test_is_javascript_script_tag_returns_false_for_non_html_namespa
159156
public function test_is_json_script_tag( string $html, bool $expected_result ) {
160157
$processor = new WP_HTML_Tag_Processor( $html );
161158
$processor->next_tag();
162-
163-
$this->assertSame( 'SCRIPT', $processor->get_tag(), 'Should be positioned on a SCRIPT tag' );
164159
$this->assertSame(
165160
$expected_result,
166161
$processor->is_json_script_tag(),
@@ -173,7 +168,7 @@ public function test_is_json_script_tag( string $html, bool $expected_result ) {
173168
*
174169
* @return array[]
175170
*/
176-
public static function data_is_json_script_tag() {
171+
public static function data_is_json_script_tag(): array {
177172
return array(
178173
// JSON MIME types - should be JSON.
179174
'Script tag with application/json type' => array( '<script type="application/json"></script>', true ),
@@ -227,7 +222,6 @@ public static function data_is_json_script_tag() {
227222
public function test_is_json_script_tag_returns_false_before_finding_tags() {
228223
$processor = new WP_HTML_Tag_Processor( 'Just some text' );
229224
$processor->next_token();
230-
231225
$this->assertFalse(
232226
$processor->is_json_script_tag(),
233227
'Should return false when not stopped on script tag'
@@ -240,9 +234,9 @@ public function test_is_json_script_tag_returns_false_before_finding_tags() {
240234
* @covers WP_HTML_Tag_Processor::is_json_script_tag
241235
*/
242236
public function test_is_json_script_tag_returns_false_for_non_html_namespace() {
243-
$processor = new WP_HTML_Tag_Processor( '<svg><script type="application/json"></script></svg>' );
244-
$processor->next_tag( 'SCRIPT' );
245-
237+
$processor = new WP_HTML_Tag_Processor( '<script></script>' );
238+
$processor->change_parsing_namespace( 'svg' );
239+
$processor->next_tag();
246240
$this->assertFalse(
247241
$processor->is_json_script_tag(),
248242
'Should return false for script tags in non-HTML namespace'

0 commit comments

Comments
 (0)