-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Given (a/an) :entity entity/entities/item/items #194
Comments
http://cgit.drupalcode.org/lightning/tree/tests/features/bootstrap/entity.behat.inc?h=8.x-1.x |
Basic subcontext I wrote up that does the basics. Took some inspiration from Lightning but only kept what I needed. This is for D7, understandable it needs to be abstracted for D8. I named the steps similar to how they are for content in Drupalextension.
|
Testing an entity type created from ECK:
|
Great. I was thinking to work on this for D8 in the coming week or 2 anyway, maybe you can help me with the D7 part? I'll build on your work, and as you say try to abstract it a bit. |
Absolutely, my guess it it would go in the Drupal7/Drupal8 implementations of AbstractCore. |
OK, I've got something that works for D8. Todo:
@djdevin It turned out that adding this to the Drupal extension itself is very different from a straight port of your/Lightning's code. But extending it to D7 is a fairly contained task: there's just an entityCreate and entityDelete stub in DrupalDriver that need filling in. Are you up for it? I know little about D8 but nothing at all about D7. Feel free to PR my repo and I'll quickly merge your PR, or make a follow-up PR here, whatever works for you. |
I've added a File field handler as well. Now we can have file entities as "given", in D8 field fields can be treated as just entity references to file entities. I haven't created tests for it, partly because it's nothing more than an empty wrapper and partly because creating the fixtures needed is hard for me.
|
Some issues with bundle names other than "type", I will have a fix shortly. |
Bundles fixed. I've had to adopt the ugly convention of passing around the entity_type and bundle as array/object keys "step_entity_type" and "step_bundle" in order to avoid collision with other fields. For example, comments have a required field called "entity_type" that references the entity type the comment is about. This is part of a more general issue already present for Nodes etc. : we're passing complex objects around to represent entities, back and forth between the driver and extension as well as within each, and these have no predefined structure or interface. The entity object we pass around is basically a collection of desired field names and values, and so it gets messy when we went to add non-field values like entity type and these sit amidst the fields with no defined way of distinguishing them, and potentially colliding with them. Ideally we could have some kind of interface that defines properties: entity_type, bundle, id, canonical url, edit url, and fields. So it's entity->fields that has the collection of desired fields. This should be a separate issue however as it requires refactoring beyond the scope of this issue and is not caused by the new EntityContext, it's already present. |
Sure, I think getting it done first in D8 would be best so I could just do a followup PR and write the D7 implementation.
Even outside of Behat I think it's safe to assume that there shouldn't be a field that is called entity_type. IIRC in Drupal 7 this was also possible, you could create a field that clashed with a property. I haven't looked at your PR yet but If you take a look at my steps though I put the entity type and bundle into the step itself, so that the defined id/bundle key would be used, and the table would only contain properties and fields. The test writer should not have to know what those keys are. |
Agreed, and I have implemented the same. (although I have also allowed bundle to be set by column as well). The challenge is in passing entity_type and bundle to the driver, hooks and cleanup without colliding with field names. |
Ridiculous :) Does the same apply for a field called "nid"? I thought all user fields had to be prefixed with |
Certainly fields I create through UI get "field_". Basefields created programmatically don't seem to need that. So yes, there could very well be one called "nid"! A developer making a custom entity that always had a parent node might think to use "nid" for a basefield. The joy of catering for Drupal's infinite use cases ... |
I opened jhedstrom/DrupalDriver#113 for the D7 driver functionality. Going to test against #300 in a bit. Seems like this issue isn't needed any more. Close? |
Here's some documentation in order to get this working:
|
Any update on this? It would be a major improvement. |
The key pieces are already in the Drupal Driver, so if somebody wants to pick up #300 and push it through that would be great. |
Following on from: https://www.drupal.org/node/2537618, planning for adding support beyond nodes to the more basic content entities.
JHedstrom commented there:
"In the Drupal Drivers, there would be new methods added. For the changes to the Drupal Extension, these could go into a dedicated EntityContext class so people could enable that as needed."
Questions:
Lastly, teardown is a significant challenge. AFAIK this project removes test data by removing all data created by the user created in the test process. However, basic entities do not necessarily record who created or owns them. My suggestion is that when working with basic entities we would have to record the full set of fields specified in the Given, and then delete entities that match those fields.
This could potentially delete too many entities in the case that the supplied fields overlapped with existing entities of the type, so we would need to document clearly the importance of giving novel values for the fields of the entities to be Given...
"Given a Pizza item with Flavor "test flavor gdfdfsh"
The text was updated successfully, but these errors were encountered: