Skip to content

Commit

Permalink
EWPP-2023: Add a Behat step to create av portal videos programmatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
yenyasinn committed Mar 22, 2022
1 parent 15f9bde commit ce4fbbf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/features/av-portal-video.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Feature: AV Portal video.
@javascript @av_portal @cleanup:media
Scenario: The node adding form should contain an entity browser widget with the possibility to add new and reuse existing AV Portal video.
Given I am logged in as a user with the "create oe_media_demo content,create av_portal_video media,access media_entity_browser entity browser pages" permission
And the following AV Portal video:
| url |
| https://audiovisual.ec.europa.eu/en/video/I-163162 |
When I visit "the demo content creation page"
And I fill in "Title" with "Media demo"
And I click the fieldset "Media browser field"
Expand All @@ -36,10 +39,10 @@ Feature: AV Portal video.
When I press the "Select entities" button
Then I should see entity browser modal window
When I click "View"
And I select the "Midday press briefing from 25/10/2018" media entity in the entity browser modal window
And I select the "Economic and Financial Affairs Council - Arrivals" media entity in the entity browser modal window
And I press the "Select entities" button
And I press the "Save" button
Then I should see the AV Portal video "Midday press briefing from 25/10/2018"
Then I should see the AV Portal video " Economic and Financial Affairs Council - Arrivals"

When I visit "the demo content creation page"
And I fill in "Title" with "Media demo"
Expand Down
34 changes: 34 additions & 0 deletions tests/src/Behat/MediaContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,40 @@ public function createMediaImages(TableNode $table): void {
}
}

/**
* Creates media AVPortal video with the specified URLs.
*
* Usage example:
*
* Given the following AV Portal videos:
* | url |
* | url 1 |
* | ... |
*
* @Given the following AV Portal video(s):
*/
public function createMediaAvPortalVideo(TableNode $table): void {
/** @var \Drupal\media_avportal\Plugin\media\Source\MediaAvPortalSourceInterface $media_source */
$media_source = \Drupal::entityTypeManager()
->getStorage('media_type')
->load('av_portal_video')
->getSource();

// Retrieve the url table from the test scenario.
foreach ($table->getColumnsHash() as $hash) {
$media = \Drupal::entityTypeManager()
->getStorage('media')->create([
'bundle' => 'av_portal_video',
'oe_media_avportal_video' => $media_source->transformUrlToReference($hash['url']),
'status' => 1,
]);
$media->save();

// Store for cleanup.
$this->media[] = $media;
}
}

/**
* Creates media AVPortal photos with the specified URLs.
*
Expand Down

0 comments on commit ce4fbbf

Please sign in to comment.