DomainAliasEnvironmentTest.php in Domain Access 8
File
domain_alias/tests/src/Functional/DomainAliasEnvironmentTest.php
View source
<?php
namespace Drupal\Tests\domain_alias\Functional;
use Drupal\user\RoleInterface;
class DomainAliasEnvironmentTest extends DomainAliasTestBase {
public static $modules = [
'domain',
'domain_alias',
'user',
];
protected function setUp() {
parent::setUp();
$this
->domainCreateTestDomains(3);
}
public function testDomainAliasEnvironments() {
$domain_storage = \Drupal::entityTypeManager()
->getStorage('domain');
$alias_loader = \Drupal::entityTypeManager()
->getStorage('domain_alias');
$domains = $domain_storage
->loadMultipleSorted(NULL, TRUE);
$patterns = [
'*.' . $this->baseHostname,
'four.' . $this->baseHostname,
'five.' . $this->baseHostname,
];
foreach ($domains as $domain) {
$values = [
'domain_id' => $domain
->id(),
'pattern' => array_shift($patterns),
'redirect' => 0,
'environment' => 'local',
];
$this
->createDomainAlias($values);
}
$local = $alias_loader
->loadByEnvironment('local');
$this
->assert(count($local) == 3, 'Three aliases set to local');
$match = $alias_loader
->loadByEnvironmentMatch($domain, 'local');
$this
->assert(count($match) == 1, 'One environment match loaded');
$alias = current($match);
$this
->assert($alias
->getPattern() == 'five.' . $this->baseHostname, 'Proper pattern match loaded.');
$alias
->set('environment', 'testing')
->save();
$local = $alias_loader
->loadByEnvironment('local');
$this
->assert(count($local) == 2, 'Two aliases set to local');
$matches = $alias_loader
->loadByEnvironmentMatch($domain, 'local');
$this
->assert(count($matches) == 0, 'No environment matches loaded');
$domain = $domain_storage
->load('one_example_com');
$matches = $alias_loader
->loadByEnvironmentMatch($domain, 'local');
$this
->assert(count($matches) == 1, 'One environment match loaded');
$alias = current($matches);
$this
->assert($alias
->getPattern() == 'four.' . $this->baseHostname, 'Proper pattern match loaded.');
$this
->drupalPlaceBlock('domain_switcher_block');
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'administer domains',
]);
$this
->drupalGet($domain
->getPath());
foreach ($domains as $domain) {
$this
->assertSession()
->assertEscaped($domain
->getHostname());
$this
->assertSession()
->linkByHrefExists($domain
->getPath(), 0, 'Link found: ' . $domain
->getPath());
}
$url = $domain
->getScheme() . $alias
->getPattern();
$this
->drupalGet($url);
foreach ($matches as $match) {
$this
->assertSession()
->assertEscaped($match
->getPattern());
}
}
}