6
6
* @since 0.7
7
7
*/
8
8
9
+ use AmpProject \AmpWP \Tests \Helpers \MarkupComparison ;
9
10
use AmpProject \AmpWP \Tests \Helpers \PrivateAccess ;
10
11
use AmpProject \AmpWP \Tests \Helpers \WithoutBlockPreRendering ;
11
12
use AmpProject \AmpWP \Tests \TestCase ;
17
18
*/
18
19
class Test_AMP_YouTube_Embed_Handler extends TestCase {
19
20
21
+ use MarkupComparison;
20
22
use PrivateAccess;
21
23
use WithoutBlockPreRendering {
22
24
setUp as public prevent_block_pre_render;
@@ -114,7 +116,7 @@ public function test_register_and_unregister_embed() {
114
116
$ embed = new AMP_YouTube_Embed_Handler ();
115
117
$ embed ->register_embed ();
116
118
$ this ->assertEquals ( 10 , has_filter ( 'embed_oembed_html ' , [ $ embed , 'filter_embed_oembed_html ' ] ) );
117
- $ this ->assertEquals ( 10 , has_filter ( 'wp_video_shortcode_override ' , [ $ embed , 'video_override ' ] ) );
119
+ $ this ->assertEquals ( PHP_INT_MAX , has_filter ( 'wp_video_shortcode_override ' , [ $ embed , 'video_override ' ] ) );
118
120
$ embed ->unregister_embed ();
119
121
$ this ->assertFalse ( has_filter ( 'embed_oembed_html ' , [ $ embed , 'filter_embed_oembed_html ' ] ) );
120
122
$ this ->assertFalse ( has_filter ( 'wp_video_shortcode_override ' , [ $ embed , 'video_override ' ] ) );
@@ -156,6 +158,10 @@ public function sanitize_raw_embeds_data_provider() {
156
158
'source ' => '<iframe src="https://www.youtube.com/feed/library" title="YouTube Library" width="560" height="315"></iframe> ' ,
157
159
'expected ' => '<iframe src="https://www.youtube.com/feed/library" title="YouTube Library" width="560" height="315"></iframe> ' ,
158
160
],
161
+ 'youtube-fixed-height ' => [
162
+ 'source ' => '<iframe width="100%" height="315" src="https://www.youtube.com/embed/s52JNMT59s8"></iframe> ' ,
163
+ 'expected ' => '<amp-youtube layout="fixed-height" width="auto" height="315" data-videoid="s52JNMT59s8"><a placeholder="" href="https://www.youtube.com/watch?v=s52JNMT59s8"><img src="https://i.ytimg.com/vi/s52JNMT59s8/hqdefault.jpg" layout="fill" object-fit="cover"></a></amp-youtube> ' ,
164
+ ],
159
165
];
160
166
}
161
167
@@ -166,6 +172,7 @@ public function sanitize_raw_embeds_data_provider() {
166
172
* @covers ::get_amp_component()
167
173
* @covers ::get_placeholder_element()
168
174
* @covers ::prepare_attributes()
175
+ * @covers ::amend_fixed_height_layout()
169
176
*/
170
177
public function test_sanitize_raw_embeds ( $ source , $ expected ) {
171
178
@@ -180,7 +187,7 @@ public function test_sanitize_raw_embeds( $source, $expected ) {
180
187
181
188
$ content = AMP_DOM_Utils::get_content_from_dom ( $ dom );
182
189
183
- $ this ->assertEquals ( $ expected , trim ( $ content ) );
190
+ $ this ->assertEqualMarkup ( $ expected , $ content );
184
191
}
185
192
186
193
/**
@@ -190,6 +197,7 @@ public function test_sanitize_raw_embeds( $source, $expected ) {
190
197
* @covers ::video_override()
191
198
* @covers ::render()
192
199
* @covers ::get_placeholder_markup()
200
+ * @covers ::amend_fixed_height_layout()
193
201
*/
194
202
public function test_video_override () {
195
203
remove_all_filters ( 'wp_video_shortcode_override ' );
@@ -201,8 +209,33 @@ public function test_video_override() {
201
209
];
202
210
203
211
$ youtube_shortcode = $ this ->handler ->video_override ( '' , $ attr_youtube );
204
- $ this ->assertStringContainsString ( '<amp-youtube ' , $ youtube_shortcode );
205
- $ this ->assertStringContainsString ( $ youtube_id , $ youtube_shortcode );
212
+ $ this ->assertEqualMarkup (
213
+ '<amp-youtube layout="responsive" width="600" height="338" data-videoid="XOY3ZUO6P0k"><a placeholder href="https://youtu.be/XOY3ZUO6P0k"><img src="https://i.ytimg.com/vi/XOY3ZUO6P0k/hqdefault.jpg" layout="fill" object-fit="cover"></a></amp-youtube> ' ,
214
+ $ youtube_shortcode
215
+ );
216
+
217
+ // Test when wp_video_shortcode_override filter has already overridden the markup.
218
+ $ youtube_shortcode = $ this ->handler ->video_override ( "<iframe width= \"200 \" height= \"100 \" src= \"$ youtube_src \"></iframe> " , $ attr_youtube );
219
+ $ this ->assertEqualMarkup (
220
+ '<amp-youtube layout="responsive" width="200" height="100" data-videoid="XOY3ZUO6P0k"><a placeholder href="https://youtu.be/XOY3ZUO6P0k"><img src="https://i.ytimg.com/vi/XOY3ZUO6P0k/hqdefault.jpg" layout="fill" object-fit="cover"></a></amp-youtube> ' ,
221
+ $ youtube_shortcode
222
+ );
223
+
224
+ // Test 100% width in video shortcode.
225
+ $ youtube_shortcode = $ this ->handler ->video_override (
226
+ '' ,
227
+ array_merge (
228
+ $ attr_youtube ,
229
+ [
230
+ 'width ' => '100% ' ,
231
+ 'height ' => '315 ' ,
232
+ ]
233
+ )
234
+ );
235
+ $ this ->assertEqualMarkup (
236
+ '<amp-youtube layout="fixed-height" width="auto" height="315" data-videoid="XOY3ZUO6P0k"><a placeholder href="https://youtu.be/XOY3ZUO6P0k"><img src="https://i.ytimg.com/vi/XOY3ZUO6P0k/hqdefault.jpg" layout="fill" object-fit="cover"></a></amp-youtube> ' ,
237
+ $ youtube_shortcode
238
+ );
206
239
207
240
$ vimeo_id = '64086087 ' ;
208
241
$ vimeo_src = 'https://vimeo.com/ ' . $ vimeo_id ;
@@ -313,9 +346,9 @@ public function test__conversion( $source, $expected, $fallback_for_expected = n
313
346
version_compare ( strtok ( get_bloginfo ( 'version ' ), '- ' ), '5.1 ' , '< ' )
314
347
&& null !== $ fallback_for_expected
315
348
) {
316
- $ this ->assertEquals ( $ fallback_for_expected , $ filtered_content );
349
+ $ this ->assertEqualMarkup ( $ fallback_for_expected , $ filtered_content );
317
350
} else {
318
- $ this ->assertEquals ( $ expected , $ filtered_content );
351
+ $ this ->assertEqualMarkup ( $ expected , $ filtered_content );
319
352
}
320
353
}
321
354
0 commit comments