FileFieldWidgetTest fails on local sites running in a subdirectory

Created on 18 November 2019, about 5 years ago
Updated 26 April 2023, over 1 year ago

Problem/Motivation

I have a local 8.8.x dev site.
It lives at http://localhost/drupal-8_8
When I try to run core/modules/file/tests/src/Functional/FileFieldWidgetTest.php locally, it fails with 5 of these:

1) Drupal\Tests\file\Functional\FileFieldWidgetTest::testSingleValuedWidget
Behat\Mink\Exception\ExpectationException: Current response status code is 404, but 200 expected.

When I use run-tests and inspect the HTML output, I see this:

GET request to: http://localhost/drupal-8_8/drupal-8_8/sites/simpletest/93134289/files/2019-11/text-0.txt

Notice the double "drupal-8_8" in there?

Digging a bit deeper, each of the calls that fails is something like this:

  $this->drupalGet($node_file->createFileUrl());

Looking at core/modules/file/src/Entity/File.php we find this:

  public function createFileUrl($relative = TRUE) {

So somehow, using relative file links in the test is confusing phpunit + run-tests.sh for me.

Proposed resolution

Invoke createFileUrl() with FALSE to always get absolute links, instead of relying on relative links.

Remaining tasks

  1. Review.
  2. RTBC.
  3. Commit.

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

-

🐛 Bug report
Status

Needs work

Version

9.5

Component
File system 

Last updated about 12 hours ago

Created by

🇺🇸United States dww

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇳India nikhil_110

    Re-roll patch #10 against Drupal 9.5.x
    Patch #10 is not applied for Drupal 9.5.x so Inter-diff file is not added.

    Checking patch core/modules/file/tests/src/Functional/FileFieldWidgetTest.php...
    Hunk #1 succeeded at 94 (offset 2 lines).
    Hunk #2 succeeded at 267 (offset 2 lines).
    Hunk #3 succeeded at 335 (offset 4 lines).
    Hunk #4 succeeded at 353 (offset 5 lines).
    error: while searching for:
        $this->assertEqual($attacker_user->id(), $node_file->getOwnerId(), 'New file belongs to the attacker.');
    
        // Ensure the file can be downloaded.
        $this->drupalGet($node_file->createFileUrl());
        $this->assertSession()->statusCodeEquals(200);
    
        // "Click" the remove button (emulating either a nojs or js submission).
    
    error: patch failed: core/modules/file/tests/src/Functional/FileFieldWidgetTest.php:564
    error: core/modules/file/tests/src/Functional/FileFieldWidgetTest.php: patch does not apply
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,322 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,343 pass
Production build 0.71.5 2024