Skip to content

Commit a134e82

Browse files
committed
Make is_{javascript,json}_script_tag methods private
1 parent c7d1827 commit a134e82

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,7 +3952,7 @@ static function ( $tag_match ) {
39523952
*
39533953
* @return bool True if the script tag will be evaluated as JavaScript.
39543954
*/
3955-
public function is_javascript_script_tag(): bool {
3955+
private function is_javascript_script_tag(): bool {
39563956
if ( 'SCRIPT' !== $this->get_tag() || $this->get_namespace() !== 'html' ) {
39573957
return false;
39583958
}
@@ -4063,7 +4063,7 @@ public function is_javascript_script_tag(): bool {
40634063
*
40644064
* @return bool True if the script tag should be treated as JSON.
40654065
*/
4066-
public function is_json_script_tag(): bool {
4066+
private function is_json_script_tag(): bool {
40674067
if ( 'SCRIPT' !== $this->get_tag() || $this->get_namespace() !== 'html' ) {
40684068
return false;
40694069
}

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ 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+
$result = ( function () {
28+
return $this->is_javascript_script_tag();
29+
} )->call( $processor );
2630
$this->assertSame(
2731
$expected_result,
28-
$processor->is_javascript_script_tag(),
32+
$result,
2933
'Failed to correctly identify JavaScript script tag'
3034
);
3135
}
@@ -122,9 +126,11 @@ public static function data_is_javascript_script_tag(): array {
122126
public function test_is_javascript_script_tag_returns_false_before_finding_tags() {
123127
$processor = new WP_HTML_Tag_Processor( 'Just some text' );
124128
$processor->next_token();
125-
129+
$result = ( function () {
130+
return $this->is_javascript_script_tag();
131+
} )->call( $processor );
126132
$this->assertFalse(
127-
$processor->is_javascript_script_tag(),
133+
$result,
128134
'Should return false when not stopped on script tag'
129135
);
130136
}
@@ -139,8 +145,11 @@ public function test_is_javascript_script_tag_returns_false_for_non_html_namespa
139145
$processor->change_parsing_namespace( 'svg' );
140146
$processor->next_tag();
141147
$this->assertSame( 'SCRIPT', $processor->get_tag() );
148+
$result = ( function () {
149+
return $this->is_javascript_script_tag();
150+
} )->call( $processor );
142151
$this->assertFalse(
143-
$processor->is_javascript_script_tag(),
152+
$result,
144153
'Should return false for script tags in non-HTML namespace'
145154
);
146155
}
@@ -158,9 +167,12 @@ public function test_is_javascript_script_tag_returns_false_for_non_html_namespa
158167
public function test_is_json_script_tag( string $html, bool $expected_result ) {
159168
$processor = new WP_HTML_Tag_Processor( $html );
160169
$processor->next_tag();
170+
$result = ( function () {
171+
return $this->is_json_script_tag();
172+
} )->call( $processor );
161173
$this->assertSame(
162174
$expected_result,
163-
$processor->is_json_script_tag(),
175+
$result,
164176
'Failed to correctly identify JSON script tag'
165177
);
166178
}
@@ -224,8 +236,11 @@ public static function data_is_json_script_tag(): array {
224236
public function test_is_json_script_tag_returns_false_before_finding_tags() {
225237
$processor = new WP_HTML_Tag_Processor( 'Just some text' );
226238
$processor->next_token();
239+
$result = ( function () {
240+
return $this->is_json_script_tag();
241+
} )->call( $processor );
227242
$this->assertFalse(
228-
$processor->is_json_script_tag(),
243+
$result,
229244
'Should return false when not stopped on script tag'
230245
);
231246
}
@@ -240,8 +255,11 @@ public function test_is_json_script_tag_returns_false_for_non_html_namespace() {
240255
$processor->change_parsing_namespace( 'svg' );
241256
$processor->next_tag();
242257
$this->assertSame( 'SCRIPT', $processor->get_tag() );
258+
$result = ( function () {
259+
return $this->is_json_script_tag();
260+
} )->call( $processor );
243261
$this->assertFalse(
244-
$processor->is_json_script_tag(),
262+
$result,
245263
'Should return false for script tags in non-HTML namespace'
246264
);
247265
}

0 commit comments

Comments
 (0)