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
Extending createNodes/assertViewingNode for files #323
Comments
The simplest way to do this without any custom code is to use this step from
This is however not great from a BDD standpoint. It would be preferable to be able to provide a table of field values, as you suggest. Here is an example how we solved this in a project. Note that we are following strict BDD principles, so we are not using the default steps. We are using our own project's Domain Specific Language, which does not use Drupalisms such as "content type" and "node". We also never use machine names since these are not known by the end user. So we use for example In our user scenario we would have a step such as the following. This creates a "collection" (our DSL term for a group from the Organic Groups module), which includes two file fields:
Here is the step definition:
ref. givenCollection(). Most of this code is dealing with translating human readable values back to machine readable ones that we can use for creating the entity. Ref. collectionFieldAliases() which provides human readable field names, and convertValueAliases() which provides human readable values (e.g. for checkboxes and radio buttons). Then finally it passes to
Ref. createCollection(). This calls
Ref. createFile(). Note that you also need to keep track of the files you create so you can clean them up after the test scenario ends:
|
This works using #300 :
It doesn't need an actual file at the URI; it works because file fields are entity reference fields to file entities. It's not ideal from a BDD perspective because declaring the file entities first is exposing an implementation detail. I wonder if we could make the driver autocreate the targets of entity references that did not already exist. |
jhedstrom/DrupalDriver#123 handles files in @given content. |
Hello,
I'm searching how to best extend the createNodes/assertViewingNode for file upload fields. Probably expandEntityFields.
I would like functionality like:
Given contenttype node:
| title | Test Node |
| file_field | logo.jpg |
So that behat/drupalextension inserts a new file from files_path into drupal(8) and attaches it to the node.
Even thinking about writing extra context for paragraphs(d7)/components(d8) too.
And ideas how to do this best?
Trogie
The text was updated successfully, but these errors were encountered: