File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,9 +125,29 @@ public function test_resource_hints_use_wordpress_filter_contract(): void {
125125
126126 $ preconnect_hints = es_optimizer_add_preconnect_resource_hints ( array (), 'preconnect ' );
127127 $ dns_prefetch_urls = es_optimizer_add_dns_prefetch_resource_hints ( array (), 'dns-prefetch ' );
128+ $ cdn_hint = $ this ->findResourceHintByHref ( $ preconnect_hints , 'https://cdn.example.com ' );
128129
129130 $ this ->assertContains ( array ( 'href ' => 'https://fonts.gstatic.com ' , 'crossorigin ' => 'anonymous ' ), $ preconnect_hints );
130131 $ this ->assertContains ( array ( 'href ' => 'https://cdn.example.com ' ), $ preconnect_hints );
132+ $ this ->assertIsArray ( $ cdn_hint );
133+ $ this ->assertArrayNotHasKey ( 'crossorigin ' , $ cdn_hint );
131134 $ this ->assertContains ( 'https://static.example.com ' , $ dns_prefetch_urls );
132135 }
136+
137+ /**
138+ * Find a resource hint by href.
139+ *
140+ * @param array<int, array<string, mixed>|string> $hints Resource hints.
141+ * @param string $href Hint href to locate.
142+ * @return array<string, mixed>|null Matching hint, if present.
143+ */
144+ private function findResourceHintByHref ( array $ hints , string $ href ): ?array {
145+ foreach ( $ hints as $ hint ) {
146+ if ( is_array ( $ hint ) && $ href === ( $ hint ['href ' ] ?? null ) ) {
147+ return $ hint ;
148+ }
149+ }
150+
151+ return null ;
152+ }
133153}
You can’t perform that action at this time.
0 commit comments