Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

File upload fails to upload file #389

Open
sboden opened this issue Aug 10, 2023 · 5 comments
Open

File upload fails to upload file #389

sboden opened this issue Aug 10, 2023 · 5 comments

Comments

@sboden
Copy link

sboden commented Aug 10, 2023

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.

@stof
Copy link
Member

stof commented Aug 10, 2023

Which Mink driver are you using ?

The behavior of triggering a page refresh on file upload is something I never saw and that I never heard of until now. Could it be something triggered by some JS code on the page ?

@sboden
Copy link
Author

sboden commented Aug 10, 2023

Goutte I assume. From the behat config file:

    Drupal\MinkExtension:
      goutte: ~
      base_url: "https://mysite.ddev.site"
      files_path: '%paths.base%/features/resources'

I don't know whether it's a real refresh, the effect was that when I uploaded a file with the step in the original message, it would throw away all values in the form previously entered with other behat steps. Hence the workaround. But since the last ddev upgrade even the workaround fails. A colleague has the same with my database dump, the same git version, and a little older ddev version.

The behats worked right before the ddev upgrade, it stopped working right after. Same codebase, same database state. The only thing I can think of now is that the ddev update comes with a new apache version.

@stof
Copy link
Member

stof commented Oct 12, 2023

The package you use seems to be a different extension. This package is not defining Drupal\MinkExtension

@sboden
Copy link
Author

sboden commented Oct 16, 2023

It's this one... The function I use is on line 207 of https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Context/MinkContext.php.

What it looks like is that when using this function in Drupal 10, the whole form is cleared somehow. I was running a set of behat tests that were green on Drupal 9, I only did the Drupal 10 upgrade, and afterwards the behats using this function fail since the file to be attached is not really attached.

@sboden
Copy link
Author

sboden commented Feb 3, 2024

Anyone already found a solution for the upload failing? It did work on Drupal 9, it started failing on Drupal 10.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants