class MultisiteValidatorTest
@covers \Drupal\package_manager\Validator\MultisiteValidator @group package_manager @internal
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait
- class \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase extends \Drupal\KernelTests\KernelTestBase uses \Drupal\Tests\package_manager\Traits\AssertPreconditionsTrait, \Drupal\Tests\package_manager\Traits\ComposerStagerTestTrait, \Drupal\Tests\package_manager\Traits\FixtureManipulatorTrait, \Drupal\Tests\package_manager\Traits\FixtureUtilityTrait, \Drupal\package_manager\StatusCheckTrait, \Drupal\Tests\package_manager\Traits\ValidationTestTrait
- class \Drupal\Tests\package_manager\Kernel\MultisiteValidatorTest extends \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase
- class \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase extends \Drupal\KernelTests\KernelTestBase uses \Drupal\Tests\package_manager\Traits\AssertPreconditionsTrait, \Drupal\Tests\package_manager\Traits\ComposerStagerTestTrait, \Drupal\Tests\package_manager\Traits\FixtureManipulatorTrait, \Drupal\Tests\package_manager\Traits\FixtureUtilityTrait, \Drupal\package_manager\StatusCheckTrait, \Drupal\Tests\package_manager\Traits\ValidationTestTrait
Expanded class hierarchy of MultisiteValidatorTest
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ MultisiteValidatorTest.php, line 17
Namespace
Drupal\Tests\package_manager\KernelView source
class MultisiteValidatorTest extends PackageManagerKernelTestBase {
/**
* Data provider for testMultisite().
*
* @return mixed[][]
* The test cases.
*/
public static function providerMultisite() : array {
return [
'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.'),
]),
],
],
'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,
[],
],
];
}
/**
* Tests that Package Manager flags an error if run 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(?string $sites_php, array $expected_results = []) : void {
if ($sites_php) {
$project_root = $this->container
->get(PathLocator::class)
->getProjectRoot();
file_put_contents($project_root . '/sites/sites.php', $sites_php);
}
$this->assertStatusCheckResults($expected_results);
$this->assertResults($expected_results, PreCreateEvent::class);
}
/**
* Tests that an error is flagged if run in a multisite during pre-apply.
*
* @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(?string $sites_php, array $expected_results = []) : void {
$this->addEventTestListener(function () use ($sites_php) : void {
if ($sites_php) {
$project_root = $this->container
->get(PathLocator::class)
->getProjectRoot();
file_put_contents($project_root . '/sites/sites.php', $sites_php);
}
});
$this->assertResults($expected_results, PreApplyEvent::class);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.