public function MediaLibraryContext::createItems in Lightning Media 8.3
Same name and namespace in other branches
- 8.2 tests/contexts/MediaLibraryContext.behat.inc \Acquia\LightningExtension\Context\MediaLibraryContext::createItems()
Creates media items for the scenario.
@Given I have items in the media library
File
- tests/
contexts/ MediaLibraryContext.behat.inc, line 42
Class
- MediaLibraryContext
- Contains step definitions to interact with the administrative media library.
Namespace
Acquia\LightningExtension\ContextCode
public function createItems() {
$storage = \Drupal::entityTypeManager()
->getStorage('media');
/** @var \Drupal\media\MediaInterface $media */
$media = $storage
->create([
'bundle' => 'tweet',
]);
$media
->setName("I'm a tweet")
->set('embed_code', 'https://twitter.com/50NerdsofGrey/status/757319527151636480')
->set('field_media_in_library', TRUE)
->setPublished();
$storage
->save($media);
$id = $media
->id();
$this->media[$id] = $media
->label();
$media = $storage
->create([
'bundle' => 'instagram',
]);
$media
->setName("I'm an instagram")
->set('embed_code', 'https://www.instagram.com/p/BaecNGYAYyP/')
->set('field_media_in_library', TRUE)
->setPublished();
$storage
->save($media);
$id = $media
->id();
$this->media[$id] = $media
->label();
}