Skip to content
Snippets Groups Projects
Commit 79b7c59a authored by Yash Rode's avatar Yash Rode Committed by Adam G-H
Browse files

Issue #3267646 by yash.rode, Wim Leers, kunal.sachdev, phenaproxima: Refine...

Issue #3267646 by yash.rode, Wim Leers, kunal.sachdev, phenaproxima: Refine multisite detection: many aliases for a single site is fine!
parent 059443b7
No related branches found
No related tags found
5 merge requests!989Issue #3356804 by phenaproxima: Flag a warning during status check if the...,!700Issue #3267646: Refine multisite detection: many sites served by a single DB can be supported, only >1 DB cannot,!685Issue #3338667: [PP-1] Add build test to test cweaganscomposer-patches end-to-end,!548Issue #3310729: Incorrect documentation link in UI in case of Process error,!106Issue #3247479: Allow LockFileValidator results to carry multiple messages, and improve their text
......@@ -49,15 +49,23 @@ final class MultisiteValidator implements EventSubscriberInterface {
*
* @return bool
* TRUE if the current site is part of a multisite, otherwise FALSE.
*
* @todo Make this smarter in https://www.drupal.org/node/3267646.
*/
protected function isMultisite(): bool {
$web_root = $this->pathLocator->getWebRoot();
if ($web_root) {
$web_root .= '/';
}
return file_exists($this->pathLocator->getProjectRoot() . '/' . $web_root . 'sites/sites.php');
$sites_php_path = $this->pathLocator->getProjectRoot() . '/' . $web_root . 'sites/sites.php';
if (!file_exists($sites_php_path)) {
return FALSE;
}
// @see \Drupal\Core\DrupalKernel::findSitePath()
$sites = [];
include $sites_php_path;
// @see example.sites.php
return count(array_unique($sites)) > 1;
}
/**
......
......@@ -23,16 +23,40 @@ class MultisiteValidatorTest extends PackageManagerKernelTestBase {
*/
public function providerMultisite(): array {
return [
'multisite' => [
TRUE,
'sites.php present and listing multiple sites' => [
<<<'PHP'
<?php
// Site 1: the main site.
$sites['example.com'] = 'default';
// Site 2: the shop.
$sites['shop.example.com'] = 'shop';
PHP,
[
ValidationResult::createError([
t('Drupal multisite is not supported by Package Manager.'),
]),
],
],
'not multisite' => [
FALSE,
'sites.php present and listing single site' => [
<<<'PHP'
<?php
// Site 1: the main site.
$sites['example.com'] = 'default';
PHP,
[],
],
'sites.php present and listing multiple aliases for a single site' => [
<<<'PHP'
<?php
// Site 1: the main site.
$sites['example.com'] = 'example';
// Alias for site 1!
$sites['example.dev'] = 'example';
PHP,
[],
],
'sites.php absent' => [
NULL,
[],
],
];
......@@ -41,21 +65,18 @@ class MultisiteValidatorTest extends PackageManagerKernelTestBase {
/**
* Tests that Package Manager flags an error if run in a multisite.
*
* @param bool $is_multisite
* Whether the validator will be in a multisite.
* @param string|null $sites_php
* The sites.php contents to write, if any. If NULL, no sites.php will be
* created.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
*
* @dataProvider providerMultisite
*/
public function testMultisite(bool $is_multisite, array $expected_results = []): void {
// If we should simulate a multisite, ensure there is a sites.php in the
// test project.
// @see \Drupal\package_manager\Validator\MultisiteValidator::isMultisite()
if ($is_multisite) {
$project_root = $this->container->get('package_manager.path_locator')
->getProjectRoot();
touch($project_root . '/sites/sites.php');
public function testMultisite(?string $sites_php, array $expected_results = []): void {
if ($sites_php) {
$project_root = $this->container->get('package_manager.path_locator')->getProjectRoot();
file_put_contents($project_root . '/sites/sites.php', $sites_php);
}
$this->assertStatusCheckResults($expected_results);
$this->assertResults($expected_results, PreCreateEvent::class);
......@@ -64,22 +85,19 @@ class MultisiteValidatorTest extends PackageManagerKernelTestBase {
/**
* Tests that an error is flagged if run in a multisite during pre-apply.
*
* @param bool $is_multisite
* Whether the validator will be in a multisite.
* @param string|null $sites_php
* The sites.php contents to write, if any. If NULL, no sites.php will be
* created.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
*
* @dataProvider providerMultisite
*/
public function testMultisiteDuringPreApply(bool $is_multisite, array $expected_results = []): void {
$this->addEventTestListener(function () use ($is_multisite): void {
// If we should simulate a multisite, ensure there is a sites.php in the
// test project.
// @see \Drupal\package_manager\Validator\MultisiteValidator::isMultisite()
if ($is_multisite) {
$project_root = $this->container->get('package_manager.path_locator')
->getProjectRoot();
touch($project_root . '/sites/sites.php');
public function testMultisiteDuringPreApply(?string $sites_php, array $expected_results = []): void {
$this->addEventTestListener(function () use ($sites_php): void {
if ($sites_php) {
$project_root = $this->container->get('package_manager.path_locator')->getProjectRoot();
file_put_contents($project_root . '/sites/sites.php', $sites_php);
}
});
$this->assertResults($expected_results, PreApplyEvent::class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment