Skip to content

Commit 7c16ca6

Browse files
committed
Fixes
1 parent dcbc7ff commit 7c16ca6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/unit/DomainValidationTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)