Do not manually construct the site path during Drupal8+ setup
Overview
I am working on writing tests that allow testing the Drupal CiviCRM integration. However, the installation is broken due to an assumption of the site directory path.
// Compute settingsPath.
$siteDir = \Civi\Setup\DrupalUtil::getDrupalSiteDir($cmsPath);
$model->settingsPath = implode(DIRECTORY_SEPARATOR, [$cmsPath, 'sites', $siteDir, 'civicrm.settings.php']);
In a PHPUnit test the path is actually sites/simpletest/$siteDir/
. This is causing CiviCRM to write files to sites/$siteDir
and prevent a test run.
In the \Civi\Setup\DrupalUtil::getDrupalSiteDir
the basename is fetched, when really the entire path should be returned and trusted:
elseif (class_exists('Drupal')) {
- return basename(\Drupal::service('site.path'));
+ return \Drupal::service('site.path');
}
Then the computed path is just
// Compute settingsPath.
$siteDir = \Civi\Setup\DrupalUtil::getDrupalSiteDir($cmsPath);
$model->settingsPath = implode(DIRECTORY_SEPARATOR, [$cmsPath, $siteDir, 'civicrm.settings.php']);
Reproduction steps
- Attempt to write a Functional test
Current behaviour
1) Drupal\Tests\drupal_civicrm\Functional\InstallTest::testInstall
include_once(sites/simpletest/34927510/civicrm.settings.php): failed to open stream: No such file or directory
Expected behaviour
No error, beyond any other testing errors.