-
Notifications
You must be signed in to change notification settings - Fork 273
File upload fails to upload file #389
Description
Uploading a file with 'When I attach the file "pdf-sample.pdf" to "edit-field-document-0-upload"' doesn't work anymore.
I'm using Drupal 9/10, I had behats which were all green (some of them were uploading files). The only thing I changed was upgrading our ddev development environment to the latest version, so I assume the apache version in use inside of ddev is now newer than before.
The code of the step being used in behat is this (from mink-extension, hence the issue here):
/**
* Attaches file to field with specified id|name|label|value
* Example: When I attach the file "bwayne_profile.png" to "profileImageUpload"
* Example: And I attach the file "bwayne_profile.png" to "profileImageUpload"
*
* @When /^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
*/
public function attachFileToField($field, $path)
{
$field = $this->fixStepArgument($field);
if ($this->getMinkParameter('files_path')) {
$fullPath = rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$path;
if (is_file($fullPath)) {
$path = $fullPath;
}
}
$this->getSession()->getPage()->attachFileToField($field, $path);
}
Before we had problems with this step which we worked around:
What we saw before is that when a file is uploaded a refresh of the page would be done, so anything filled in on a form before the upload of a file would disappear. The workaround in behat was then:
- Upload a file
- Press submit (which would fail, but keep the file in the form)
- Fill in the rest of the fields
- Press submit
Since the ddev upgrade, this workaround is also not working anymore. I (x)debugged the step, but I don't see anything strange happening that could explain the behavior.