Skip to content

Commit fbce78f

Browse files
Copilotswissspidy
andcommitted
Add HTTP request mocking for audio.com URLs in tests
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent e6ed2eb commit fbce78f

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

‎features/add-oembed-provider.feature‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ Feature: Register and use custom oEmbed providers
128128

129129
@require-wp-4.0
130130
Scenario: Match an oEmbed provider
131+
# Mock the audio.com URL to return HTML with oEmbed discovery links
132+
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
133+
"""
134+
HTTP/1.1 200
135+
Content-Type: text/html
136+
137+
<!DOCTYPE html>
138+
<html>
139+
<head>
140+
<link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
141+
<link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
142+
</head>
143+
<body>
144+
<h1>Ambient Focus Collection</h1>
145+
</body>
146+
</html>
147+
"""
148+
131149
# Provider not requiring discovery
132150
When I run `wp embed provider match https://www.youtube.com/watch?v=dQw4w9WgXcQ`
133151
Then STDOUT should contain:
@@ -196,6 +214,24 @@ Feature: Register and use custom oEmbed providers
196214
# Depends on `oembed_remote_get_args` filter introduced in WP 4.0 https://core.trac.wordpress.org/ticket/23442
197215
@require-wp-4.0
198216
Scenario: Discover a provider with limited response size
217+
# Mock the audio.com URL to return HTML with oEmbed discovery links
218+
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
219+
"""
220+
HTTP/1.1 200
221+
Content-Type: text/html
222+
223+
<!DOCTYPE html>
224+
<html>
225+
<head>
226+
<link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
227+
<link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
228+
</head>
229+
<body>
230+
<h1>Ambient Focus Collection</h1>
231+
</body>
232+
</html>
233+
"""
234+
199235
When I run `wp embed provider match https://audio.com/audio-com/collections/ambient-focus`
200236
Then save STDOUT as {DEFAULT_STDOUT}
201237

@@ -243,6 +279,24 @@ Feature: Register and use custom oEmbed providers
243279

244280
@require-wp-4.0
245281
Scenario: Only match an oEmbed provider if discover
282+
# Mock the audio.com URL to return HTML with oEmbed discovery links
283+
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
284+
"""
285+
HTTP/1.1 200
286+
Content-Type: text/html
287+
288+
<!DOCTYPE html>
289+
<html>
290+
<head>
291+
<link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
292+
<link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
293+
</head>
294+
<body>
295+
<h1>Ambient Focus Collection</h1>
296+
</body>
297+
</html>
298+
"""
299+
246300
When I try `wp embed provider match https://audio.com/audio-com/collections/ambient-focus --no-discover`
247301
Then the return code should be 1
248302
And STDERR should be:

‎features/provider.feature‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ Feature: Manage oEmbed providers.
129129

130130
@require-wp-4.0
131131
Scenario: Match an oEmbed provider
132+
# Mock the audio.com URL to return HTML with oEmbed discovery links
133+
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
134+
"""
135+
HTTP/1.1 200
136+
Content-Type: text/html
137+
138+
<!DOCTYPE html>
139+
<html>
140+
<head>
141+
<link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
142+
<link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
143+
</head>
144+
<body>
145+
<h1>Ambient Focus Collection</h1>
146+
</body>
147+
</html>
148+
"""
149+
132150
# Provider not requiring discovery
133151
When I run `wp embed provider match https://www.youtube.com/watch?v=dQw4w9WgXcQ`
134152
Then STDOUT should contain:
@@ -197,6 +215,24 @@ Feature: Manage oEmbed providers.
197215
# Depends on `oembed_remote_get_args` filter introduced in WP 4.0 https://core.trac.wordpress.org/ticket/23442
198216
@require-wp-4.0
199217
Scenario: Discover a provider with limited response size
218+
# Mock the audio.com URL to return HTML with oEmbed discovery links
219+
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
220+
"""
221+
HTTP/1.1 200
222+
Content-Type: text/html
223+
224+
<!DOCTYPE html>
225+
<html>
226+
<head>
227+
<link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
228+
<link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
229+
</head>
230+
<body>
231+
<h1>Ambient Focus Collection</h1>
232+
</body>
233+
</html>
234+
"""
235+
200236
When I run `wp embed provider match https://audio.com/audio-com/collections/ambient-focus`
201237
Then save STDOUT as {DEFAULT_STDOUT}
202238

@@ -244,6 +280,24 @@ Feature: Manage oEmbed providers.
244280

245281
@require-wp-4.0
246282
Scenario: Only match an oEmbed provider if discover
283+
# Mock the audio.com URL to return HTML with oEmbed discovery links
284+
Given that HTTP requests to https://audio.com/audio-com/collections/ambient-focus will respond with:
285+
"""
286+
HTTP/1.1 200
287+
Content-Type: text/html
288+
289+
<!DOCTYPE html>
290+
<html>
291+
<head>
292+
<link rel="alternate" type="application/json+oembed" href="https://audio.com/oembed?format=json&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
293+
<link rel="alternate" type="text/xml+oembed" href="https://audio.com/oembed?format=xml&url=https%3A%2F%2Faudio.com%2Faudio-com%2Fcollections%2Fambient-focus" title="Ambient Focus Collection">
294+
</head>
295+
<body>
296+
<h1>Ambient Focus Collection</h1>
297+
</body>
298+
</html>
299+
"""
300+
247301
When I try `wp embed provider match https://audio.com/audio-com/collections/ambient-focus --no-discover`
248302
Then the return code should be 1
249303
And STDERR should be:

0 commit comments

Comments
 (0)