Problem/Motivation

Follow-up to #2232861: Create BrowserTestBase for web-testing on top of Mink

BrowserTestBase::prepareRequestForGenerator says the following:

  protected function prepareRequestForGenerator($clean_urls = TRUE, $override_server_vars = array()) {
    $request = Request::createFromGlobals();
    $server = $request->server->all();
    if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
      // We need this for when the test is executed by run-tests.sh.
      // @todo Remove this once run-tests.sh has been converted to use a Request
      //   object.
      $cwd = getcwd();
      $server['SCRIPT_FILENAME'] = $cwd . '/' . basename($server['SCRIPT_NAME']);
      $base_path = rtrim($server['REQUEST_URI'], '/');
    }
    else {
      $base_path = $request->getBasePath();
    }

run-tests.sh currently uses Request and has its own special kernel anyway, so it's time to do this.

Proposed resolution

Work on the @todo.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mile23 created an issue. See original summary.

Mile23’s picture

Status: Active » Needs review
Issue tags: +mink
FileSize
1.79 KB

Somewhat naive first stab.

run-tests.sh has been massaged quite a bit and has much better isolation now, but I'm not sure what's up with the mink implementations. I believe we don't have any tests implementing BrowserTestBase in core, so someone from Mink-land should give a shout.

larowlan’s picture

BrowserTestBaseTest is in core

Mile23’s picture

Right. :-) But that's a test of BrowserTestBase, not anything else.

dawehner’s picture

Status: Needs review » Needs work

When we update this piece of code we should do it in parallel to \Drupal\simpletest\WebTestBase::prepareRequestForGenerator which still has the same code. When we update WebTestBase as well, we will be able to catch way more potential problems.

I believe we don't have any tests implementing BrowserTestBase in core, so someone from Mink-land should give a shout.

Never believe, try to prove your points :) The only one in core is \Drupal\Tests\simpletest\Functional\BrowserTestBaseTest at this moment in time.

Mile23’s picture

Status: Needs work » Needs review
FileSize
12.18 KB

Never believe, try to prove your points :)

Just my way of acknowledging that I don't know much about the status of mink testing in core.

OK, so in the name of DRY I hereby add a new trait called RebuildContainerTrait.

This trait modifies the prepareRequestForGenerator() method as in the patch in #2 so you can look at a diff there. It also puts rebuildContainer() into the trait, since it's the same in BrowserTestBase and WebTestBase.

The trait is used by BrowserTestBase and WebTestbase.

The methods in this trait should be marked as deprecated, since they are really only used as workarounds. rebuildContainer() exists because we haven't finished #2021959: Refactor module handling responsibilities out of DrupalKernel and prepareRequestForGenerator() is full of side-effects which should be refactored elsewhere (and only allows GET requests). But that might be out of scope here, so the patch doesn't reflect this.

Also, there are other traits such as AssertContentTrait which use \Drupal to access the container, presumably because the trait would be using a property it didn't declare. These should be fixed so they use $this->container, along with another trait which declares $container. RebuildContainerTrait just uses the properties without converting to \Drupal, because that's the wrong way to go. Adding a trait for $container is non-trivial and might be out of scope here, though.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

#2796105: Move similar methods in BrowserTestBase / WebTestBase to a trait; untangle installDrupal() gives us Drupal\Core\Test\FunctionalTestSetupTrait, so there's that part sorted.

We still have the @todo.

I found testing locally that just removing the code that adjusts the server globals for run-tests.sh works. Experimentally trying that with the testbot.

Mile23’s picture

Version: 8.4.x-dev » 8.3.x-dev

Even though it's a task, this really should be 8.3.x since it reduces the complexity of the testing system.

Mile23’s picture

Issue tags: +@todo clean-up

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Issue tags: -

#9 looks good, kicked off a test run against 10.1.x

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Took a look but appears #9 has some CI errors for 10.1.x that will need to be addressed

ankithashetty’s picture

Status: Needs work » Needs review
FileSize
1.98 KB
0 bytes

just rerolled the patch in #9, thanks!

ankithashetty’s picture

Uploading the right diff file.

mondrake’s picture

Component: simpletest.module » phpunit
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @ankithashetty

murilohp’s picture

+++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
@@ -251,32 +251,22 @@ protected function resetAll() {
+

Just a nitpick here, do we need this empty line here?

  • catch committed 8ef98588 on 10.1.x
    Issue #2698563 by Mile23, ankithashetty: @todo: BrowserTestBase::...
catch’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

I think the extra line is OK, if we don't like it, can remove next time this file is touched.

Committed/pushed to 10.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Mile23’s picture