@@ -1516,6 +1516,30 @@ public function test_highest_fetchpriority_with_dependents_uses_cached_result()
15161516 );
15171517 }
15181518
1519+ /**
1520+ * Tests expected priority is used when a dependent is registered but not enqueued.
1521+ *
1522+ * @ticket 64429
1523+ *
1524+ * @covers WP_Scripts::print_scripts
1525+ * @covers WP_Scripts::get_highest_fetchpriority_with_dependents
1526+ */
1527+ public function test_priority_of_dependency_for_non_enqueued_dependent () {
1528+ $ wp_scripts = wp_scripts ();
1529+ wp_default_scripts ( $ wp_scripts );
1530+
1531+ $ wp_scripts ->add ( 'not-enqueued ' , 'https://example.com/not-enqueued.js ' , array ( 'comment-reply ' ), null , array ( 'priority ' => 'high ' ) );
1532+ $ wp_scripts ->enqueue ( 'comment-reply ' );
1533+
1534+ $ actual = $ this ->normalize_markup_for_snapshot ( get_echo ( array ( $ wp_scripts , 'print_scripts ' ) ) );
1535+ $ this ->assertEqualHTML (
1536+ '<script type="text/javascript" src="/wp-includes/js/comment-reply.js" id="comment-reply-js" async="async" data-wp-strategy="async" fetchpriority="low"></script> ' ,
1537+ $ actual ,
1538+ '<body> ' ,
1539+ "Snapshot: \n$ actual "
1540+ );
1541+ }
1542+
15191543 /**
15201544 * Tests that printing a script without enqueueing has the same output as when it is enqueued.
15211545 *
@@ -4256,4 +4280,26 @@ public function data_varying_versions_handle_args() {
42564280 ),
42574281 );
42584282 }
4283+
4284+ /**
4285+ * Normalizes markup for snapshot.
4286+ *
4287+ * @param string $markup Markup.
4288+ * @return string Normalized markup.
4289+ */
4290+ private function normalize_markup_for_snapshot ( string $ markup ): string {
4291+ $ processor = new WP_HTML_Tag_Processor ( $ markup );
4292+ $ clean_url = static function ( string $ url ): string {
4293+ $ url = preg_replace ( '#^https?://[^/]+# ' , '' , $ url );
4294+ return remove_query_arg ( 'ver ' , $ url );
4295+ };
4296+ while ( $ processor ->next_tag () ) {
4297+ if ( 'LINK ' === $ processor ->get_tag () && is_string ( $ processor ->get_attribute ( 'href ' ) ) ) {
4298+ $ processor ->set_attribute ( 'href ' , $ clean_url ( $ processor ->get_attribute ( 'href ' ) ) );
4299+ } elseif ( 'SCRIPT ' === $ processor ->get_tag () && is_string ( $ processor ->get_attribute ( 'src ' ) ) ) {
4300+ $ processor ->set_attribute ( 'src ' , $ clean_url ( $ processor ->get_attribute ( 'src ' ) ) );
4301+ }
4302+ }
4303+ return $ processor ->get_updated_html ();
4304+ }
42594305}
0 commit comments