Problem/Motivation
We have a Nighwatch command drupalInstall()
that performs the Drupal installation and configures the test environment to work with the test installation - here it is: https://git.drupalcode.org/project/drupal/-/blob/daf3cd72f76049d0f036b75...
The command sets the cookie with the Simpletest site id using the code
this.url(process.env.DRUPAL_TEST_BASE_URL).setCookie({
name: 'SIMPLETEST_USER_AGENT',
// Colons need to be URL encoded to be valid.
value: encodeURIComponent(installData.user_agent),
path: url.pathname,
});
It works for the browser actions well, but doesn't work for Drush and Drupal Console commands run from the Nightwatch tests. Because Drupal expects the Simpletest site id to be in the cookie, which is not available for the command line commands, or in the environment variable, that is not filled by the command too. Here is the Drupal code to detect the test environment:
$http_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? NULL;
$user_agent = $_COOKIE['SIMPLETEST_USER_AGENT'] ?? $http_user_agent;
if (isset($user_agent) && preg_match("/^simple(\w+\d+):(.+):(.+):(.+)$/", $user_agent, $matches)) {
Here
🐛
Drush in Nightwatch tests can't detect the Simpletest site path
Active
is a parent issue for Gitlab Templates to resolve it, with a workaround, but the right fix should be in Drupal Core, I believe.
Steps to reproduce
1. Execute a drush command from a Nightwatch test, for example drush cache:clear
2. See that it doesn't use the simpletest site path, and fails on the database connection in CI, and locally - clears the cache of the local Drupal setup instead of the test instance's database.
And here https://git.drupalcode.org/project/test_helpers/-/merge_requests/134 is a pipeline reproducing this issue.
Proposed resolution
A solution for this can be setting the HTTP_USER_AGENT
environment variable by the Simpletest user agent too.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet