comparison core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
89 $assert_session->selectExists('field_map[width]')->setValue('field_string_width'); 89 $assert_session->selectExists('field_map[width]')->setValue('field_string_width');
90 $assert_session->selectExists('field_map[height]')->setValue('field_string_height'); 90 $assert_session->selectExists('field_map[height]')->setValue('field_string_height');
91 $assert_session->selectExists('field_map[author_name]')->setValue('field_string_author_name'); 91 $assert_session->selectExists('field_map[author_name]')->setValue('field_string_author_name');
92 $assert_session->buttonExists('Save')->press(); 92 $assert_session->buttonExists('Save')->press();
93 93
94 // Configure the iframe to be narrower than the actual video, so we can
95 // verify that the video scales correctly.
96 $display = entity_get_display('media', $media_type_id, 'default');
97 $this->assertFalse($display->isNew());
98 $component = $display->getComponent('field_media_oembed_video');
99 $this->assertInternalType('array', $component);
100 $component['settings']['max_width'] = 240;
101 $display->setComponent('field_media_oembed_video', $component);
102 $this->assertSame(SAVED_UPDATED, $display->save());
103
94 $this->hijackProviderEndpoints(); 104 $this->hijackProviderEndpoints();
95 $video_url = 'https://vimeo.com/7073899'; 105 $video_url = 'https://vimeo.com/7073899';
96 ResourceController::setResourceUrl($video_url, $this->getFixturesDirectory() . '/video_vimeo.json'); 106 ResourceController::setResourceUrl($video_url, $this->getFixturesDirectory() . '/video_vimeo.json');
97 107
98 // Create a media item. 108 // Create a media item.
110 120
111 // The thumbnail should have been downloaded. 121 // The thumbnail should have been downloaded.
112 $thumbnail = $media->getSource()->getMetadata($media, 'thumbnail_uri'); 122 $thumbnail = $media->getSource()->getMetadata($media, 'thumbnail_uri');
113 $this->assertFileExists($thumbnail); 123 $this->assertFileExists($thumbnail);
114 124
115 // Ensure the iframe exists and that its src attribute contains a coherent 125 // Ensure the iframe exists and has the expected CSS class, and that its src
116 // URL with the query parameters we expect. 126 // attribute contains a coherent URL with the query parameters we expect.
117 $iframe_url = $assert_session->elementExists('css', 'iframe')->getAttribute('src'); 127 $iframe = $assert_session->elementExists('css', 'iframe.media-oembed-content');
118 $iframe_url = parse_url($iframe_url); 128 $iframe_url = parse_url($iframe->getAttribute('src'));
119 $this->assertStringEndsWith('/media/oembed', $iframe_url['path']); 129 $this->assertStringEndsWith('/media/oembed', $iframe_url['path']);
120 $this->assertNotEmpty($iframe_url['query']); 130 $this->assertNotEmpty($iframe_url['query']);
121 $query = []; 131 $query = [];
122 parse_str($iframe_url['query'], $query); 132 parse_str($iframe_url['query'], $query);
123 $this->assertSame($video_url, $query['url']); 133 $this->assertSame($video_url, $query['url']);
124 $this->assertNotEmpty($query['hash']); 134 $this->assertNotEmpty($query['hash']);
135 // Ensure that the outer iframe's width respects the formatter settings.
136 $this->assertSame('240', $iframe->getAttribute('width'));
137 // Check the inner iframe to make sure that CSS has been applied to scale it
138 // correctly, regardless of whatever its width attribute may be (the fixture
139 // hard-codes it to 480).
140 $inner_frame = 'frames[0].document.querySelector("iframe")';
141 $this->assertSame('480', $session->evaluateScript("$inner_frame.getAttribute('width')"));
142 $this->assertLessThanOrEqual(240, $session->evaluateScript("$inner_frame.clientWidth"));
125 143
126 // Make sure the thumbnail is displayed from uploaded image. 144 // Make sure the thumbnail is displayed from uploaded image.
127 $assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'src', '/oembed_thumbnails/' . basename($thumbnail)); 145 $assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'src', '/oembed_thumbnails/' . basename($thumbnail));
128 146
129 // Load the media and check that all fields are properly populated. 147 // Load the media and check that all fields are properly populated.