public function MediaSourceAudioStreamTest::testFileExtensionConstraint in Media entity audio 8.3
Tests the file extension constraint.
File
- tests/
src/ Kernel/ MediaSourceAudioStreamTest.php, line 51
Class
- MediaSourceAudioStreamTest
- Tests the audio stream media source.
Namespace
Drupal\Tests\media_entity_audio\KernelCode
public function testFileExtensionConstraint() {
$media_type = $this
->createMediaType('audio_stream');
// Add the source field to the form display for the media type.
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
$view_display = \Drupal::service('entity_display.repository')
->getViewDisplay('media', $media_type
->id(), 'default');
$media_type
->getSource()
->prepareViewDisplay($media_type, $view_display);
$view_display
->removeComponent('thumbnail');
$view_display
->save();
$metadata_attributes = $media_type
->getSource()
->getMetadataAttributes();
$this
->assertEquals('Name', (string) $metadata_attributes['default_name']);
$media = Media::create([
'field_media_audio_stream' => 'http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p',
'bundle' => $media_type
->id(),
]);
$media
->save();
$this
->assertEquals('bbcmedia_radio1_mf_p', $media
->label());
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder('media');
$build = $view_builder
->view($media);
$html = \Drupal::service('renderer')
->renderPlain($build);
$this
->assertContains('<audio controls="controls"><source src="http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p"></audio>', (string) $html);
}