Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENEUROPA-1325: Media entity browser handling for files #9

Merged
merged 6 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions tests/Behat/AvPortalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,6 @@ public function assertAvPortalVideoIframe(string $title): void {
$this->assertSession()->elementAttributeContains('css', 'iframe', 'src', $ref);
}

/**
* Step that deletes an AV Portal media entity.
*
* @param string $title
* The media title.
*
* @Then I remove the AV Portal media :title
*/
public function removeAvPortalMedia(string $title): void {
$media = \Drupal::entityTypeManager()->getStorage('media')->loadByProperties(['name' => $title]);
if (!$media) {
throw new \Exception(sprintf('The media named "%s" does not exist', $title));
}

$media = reset($media);
$media->delete();
}

/**
* Enables the test module scanning.
*
Expand Down
40 changes: 32 additions & 8 deletions tests/Behat/DrupalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
use Drupal\DrupalExtension\Context\RawDrupalContext;

/**
* Class DrupalContext.
* The main Drupal context.
*/
class DrupalContext extends RawDrupalContext {

/**
* Click on drupal fiedlset form element.
* Clicks on a fieldset form element.
*
* @Given I click fieldset :field of entity browser widget
* @param string $field
* The name of the fieldset.
*
* @Given I click the fieldset :field
*/
public function iClickFieldset(string $field): void {
public function assertClickFieldset(string $field): void {
$this->getSession()->getPage()->find('named', ['link_or_button', $field])->click();
}

/**
* Switching to the iframe.
* Switches to the iframe of the Demo entity browser.
*
* @Then I should see entity browser modal window
*/
Expand All @@ -30,15 +33,36 @@ public function iSwitchToIframe(): void {
}

/**
* Select required media from galary.
* Selects required media entity from entity browser.
*
* @param string $name
* The name of the media.
*
* @When I select the :media_name media entity in the entity browser modal window
*/
public function iSelectMediaInEntityBrowser(string $media_name): void {
public function iSelectMediaInEntityBrowser(string $name): void {
$xpath = "//div[@class and contains(concat(' ', normalize-space(@class), ' '), ' views-row ')]";
$xpath .= "[.//div[@class and contains(concat(' ', normalize-space(@class), ' '), ' views-field-name ')][contains(string(.), '$media_name')]]";
$xpath .= "[.//div[@class and contains(concat(' ', normalize-space(@class), ' '), ' views-field-name ')][contains(string(.), '$name')]]";
$xpath .= "//input[@type='checkbox']";
$this->getSession()->getPage()->find('xpath', $xpath)->check();
}

/**
* Step that deletes a media entity.
*
* @param string $title
* The media title.
*
* @Then I remove the media :title
*/
public function removeMediaEntity(string $title): void {
$media = \Drupal::entityTypeManager()->getStorage('media')->loadByProperties(['name' => $title]);
if (!$media) {
throw new \Exception(sprintf('The media named "%s" does not exist', $title));
}

$media = reset($media);
$media->delete();
}

}
2 changes: 1 addition & 1 deletion tests/features/av_portal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Feature: AV Portal.
And I press "Save"
Then I should see the AV Portal video "Midday press briefing from 25/10/2018"
# Cleanup of the media entity.
Then I remove the AV Portal media "Midday press briefing from 25/10/2018"
And I remove the media "Midday press briefing from 25/10/2018"
14 changes: 8 additions & 6 deletions tests/features/media-file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@
Feature: Media document bundle.
In order to be able to showcase the media and entity browser features for managing files
As a site editor
I want to see the entity browser widget for adding and reusing document media entities.
I want to be able to work with File based Media entities

@javascript
Scenario: The node adding form should contain entity browser widget with possibility to add new and reuse existing files.
Scenario: The entity browser should allow the selection and creation of new File Media entities
Given I am logged in as a user with the "create oe_media_demo content,create document media,access media_entity_browser entity browser pages" permissions

When I visit "node/add/oe_media_demo"
And I fill in "Title" with "Media demo"
And I click fieldset "Media browser field" of entity browser widget
And I click the fieldset "Media browser field"
And I press the "Select entities" button
Then I should see entity browser modal window
When I click "Add File"
And I fill in "Name" with "Media document"
And I attach the file "sample.pdf" to "File"
And I press the "Save entity" button
And I press the "Save" button
Then I should see "sample.pdf"
Then I should see the link "sample.pdf"

When I visit "node/add/oe_media_demo"
And I fill in "Title" with "Media demo"
And I click fieldset "Media browser field" of entity browser widget
And I click the fieldset "Media browser field"
And I press the "Select entities" button
Then I should see entity browser modal window
When I click "View"
And I select the "Media document" 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 "sample.pdf"
Then I should see the link "sample.pdf"
# Cleanup of the media entity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup should be done with @afterScenario.
It's not a blocker but please create a follow-up ticket if you don't take this change it here.

And I remove the media "Media document"