Skip to main content

Media

DrevOps\BehatSteps\Steps\Drupal\MediaTrait - Source, Example, Helpers

Manage Drupal media entities with type-specific field handling.

  • Create structured media items with proper file reference handling.
  • Assert media type and media item existence.
  • Visit media view, edit, delete and revision pages.
  • Support for multiple media types with field value expansion handling.
  • Created entities are automatically removed at the end of the scenario.

Prerequisites​

PrerequisiteCapability
A backend in the scenario's list provides "ContentCapabilityInterface"ContentCapabilityInterface
The core "media" module is enabledModuleCapabilityInterface

Steps​

@Given the media type :media_type does not exist

Remove media type

Given the media type "video" does not exist
@Given the following :media_type media exist:

Create media of a given type

Given the following "video" media exist:
| name | field1 | field2 | field3 |
| My media | file.jpg | value | value |
| ... | ... | ... | ... |
@Given the following :media_type media with fields exist:

Create media entities with vertical field format

Given the following image media with fields exist:
| name | [TEST] Image 1 | [TEST] Image 2 |
| field_media_image | image1.jpg | image2.jpg |
@Given the following :media_type media do not exist:

Remove media defined by provided properties

Given the following "image" media do not exist:
| name |
| Media item |
| Another media item |
@When I visit the :media_type media page with the name :name

Visit the page of the media with the specified type and name

When I visit the "image" media page with the name "Test media image"
@When I visit the :media_type media edit page with the name :name

Visit the edit page of the media with the specified type and name

When I visit the "document" media edit page with the name "Test document"
@When I visit the :media_type media delete page with the name :name

Visit the delete page of the media with the specified type and name

When I visit the "image" media delete page with the name "Test media image"
@When I visit the :media_type media revisions page with the name :name

Visit the revisions page of the media with the specified type and name

When I visit the "image" media revisions page with the name "Test media image"
@Then the media type :media_type should exist

Assert that a media type exists

Then the media type "image" should exist
@Then the media type :media_type should not exist

Assert that a media type does not exist

Then the media type "test_type" should not exist
@Then the :media_type media with the name :name should exist

Assert that a media entity with a specific type and name exists

Then the "image" media with the name "Test media image" should exist
@Then the :media_type media with the name :name should not exist

Assert that a media entity with a specific type and name does not exist

Then the "image" media with the name "Test media image" should not exist