-
-
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
"When I attach the file" and Drupal temporary files #355
Comments
Sorry, I overlooked the obvious: this is a UI step not an API step, so we don't have a definitive reference to the file entity associated with the uploaded step, so we can't clean it up. It's an instance of the more general problem of cleaning up changes to entities made by steps using the UI. I can't see a good global solution. But we might be able to help people create their own solutions if the driver had an entityDelete function that could take a very flexible condition argument. With this developers could then create their own hook functions to delete entities meeting the conditions. In the case of files, there could be an @cleanCreatedFiles hook that deleted any file entity created after the start time of the scenario. |
OK, I'm slow today. This is already handled for nodes and comments by Drupal itself using hook_ENTITY_TYPE_predelete to delete content created by a user. So when a user created by something like "Given I am logged in as" is cleaned up, their nodes and comments created through the UI is cleaned up. The file module doesn't use hook_user_predelete to clean up file entities when a user is deleted, hence my steps fail. Perhaps what we need is for the Drupal extension to have user delete/predelete hooks as well as the existing user create hooks. Then we could specify additional clean up for Behat created users, including files they 'own'. |
Only if it is configured to do so, you can also configure Drupal to unpublish the content when deleting the user, or to mark it as being owned by the anonymous user. In these cases the content will remain after the test and needs to be cleaned up manually. The rule in general is that anything created through the UI should be cleaned up manually at the end of the test.
Yes something like In project code this is really easy to do. In D8 I use an
Then in the subcontexts of my modules I provide a human readable step, but this can also be using the generic step definition from above. Here is the one for nodes:
|
The following steps work the first occasion they are run, but not on subsequent occasions:
The step
When I visit "_flysystem/dropboxwebarchive/discussions/test/testfile.txt"
fails on the subsequent occasions because the file from the first occasion is still present as a Drupal temporary file, and therefore the filename of the file from the second occasion is changed to "testfile_0.txt" to avoid overwriting.What is needed is to keep track of uploaded files and to clean them up after scenarios.
I suggest we add:
The file cleanup could use the entityDelete function from the entityContext, so we should postpone this on #300, which is in turn postponed on on #337 (Robust entity handling).
In fact, #337 will probably include making a generic entity cleanup mechanism, rather than endlessly proliferating near-duplicate entity-type-specific mechanisms.
The text was updated successfully, but these errors were encountered: