Entities
DrevOps\BehatSteps\Steps\Drupal\EntityTrait - Source, Example, Helpers
Create entities of a type that has no dedicated trait, and reference them.
- Create entities of any type from a table of field values.
- Fill in an entity reference autocomplete field with an entity's label.
- Replace
[id:...]tokens in step arguments and table cells with the ID of an entity looked up by its label.
Covers types such ascommerce_productorgroup, where a dedicated trait would add vocabulary without adding behavior. Entities created here are removed after the scenario along with every other entity the scenario created.
Possible token formats:[id:ENTITY_TYPE:LABEL][id:ENTITY_TYPE.BUNDLE:LABEL]with:
ENTITY_TYPE: the entity type ID, such asnode,userortaxonomy_term.BUNDLE: the bundle to restrict the lookup to, such asarticle.LABEL: the label to match exactly, such as a title or a user name. It may hold balanced brackets, as in[TEST] Page, but no other token.
Examples:/print/pdf/user/[id:user:jane]converted to/print/pdf/user/12[id:taxonomy_term.topics:Jazz]converted to7When several entities share the label, the newest is used. A token whose entity does not exist fails the step.
Skip cleanup for 1 type with tag:@behat-steps-entity-cleanup-skip:commerce_product.
Skip token processing with tag:@behat-steps-skip:EntityTrait.
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
entity.enabled | boolean | TRUE | @behat-steps-skip:EntityTrait | If TRUE, replaces [id:...] tokens in step arguments and table cells with the ID of the newest entity with the token's label, though not in multiline text. If FALSE, tokens stay as written. |
Steps
@Given the following :entity_type entities exist:
Create entities of a type from a table of field values
Given the following "commerce_product" entities exist:
| title | type | status |
| TNT | product | 1 |
| Anvil | product | 1 |
@When I fill in the entity reference field :field with the :entity_type entity with the label :label
Fill in an entity reference autocomplete field with an entity's label
When I fill in the entity reference field "Authored by" with the "user" entity with the label "jane"
@When I fill in the entity reference field :field with the :bundle :entity_type entity with the label :label
Fill in an entity reference autocomplete field with a bundle entity
When I fill in the entity reference field "Program" with the "program" "node" entity with the label "Morning show"
When I fill in the entity reference field "Tags" with the "tags" "taxonomy_term" entity with the label "Jazz"