File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
tests/phpunit/tests/dependencies Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,28 @@ public function tear_down() {
6969 parent ::tear_down ();
7070 }
7171
72+ private function assertEqualHTMLScriptTagById ( string $ expected , string $ html , ?string $ message ) {
73+ $ find_id_tag_processor = new WP_HTML_Tag_Processor ( $ expected );
74+ $ find_id_tag_processor ->next_token ();
75+ $ id = $ find_id_tag_processor ->get_attribute ( 'id ' );
76+ assert ( is_string ( $ id ) );
77+
78+ $ processor = ( new class ('' , WP_HTML_Processor::CONSTRUCTOR_UNLOCK_CODE ) extends WP_HTML_Processor {
79+ public function get_script_html () {
80+ assert ( 'SCRIPT ' === $ this ->get_tag () );
81+ $ this ->set_bookmark ( 'here ' );
82+ $ span = $ this ->bookmarks ['_here ' ];
83+ return substr ( $ this ->html , $ span ->start , $ span ->length );
84+ }
85+ } )::create_fragment ( $ html );
86+
87+ while ( $ processor ->next_tag ( 'SCRIPT ' ) && $ processor ->get_attribute ( 'id ' ) !== $ id ) {
88+ // Loop until we find the right script tag.
89+ }
90+ $ this ->assertSame ( 'SCRIPT ' , $ processor ->get_tag (), "Matching tag `script# {$ id }` could not be found. " );
91+ $ this ->assertEqualHTML ( $ expected , $ processor ->get_script_html (), '<body> ' , $ message );
92+ }
93+
7294 /**
7395 * Test versioning
7496 *
You can’t perform that action at this time.
0 commit comments