DomainAliasWildcardTest.php in Domain Access 8
File
domain_alias/tests/src/Functional/DomainAliasWildcardTest.php
View source
<?php
namespace Drupal\Tests\domain_alias\Functional;
use Drupal\user\RoleInterface;
class DomainAliasWildcardTest extends DomainAliasTestBase {
public static $modules = [
'domain',
'domain_alias',
'user',
];
protected function setUp() {
parent::setUp();
$this
->domainCreateTestDomains(3);
}
public function testDomainAliasWildcards() {
$domain_storage = \Drupal::entityTypeManager()
->getStorage('domain');
$alias_loader = \Drupal::entityTypeManager()
->getStorage('domain_alias');
$domains = $domain_storage
->loadMultipleSorted(NULL, TRUE);
$patterns = [
'example.*',
'four.example.*',
'five.example.*',
];
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.example.*', 'Proper pattern match 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.example.*', '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() . str_replace('*', $this->baseTLD, $alias
->getPattern());
$this
->drupalGet($url);
foreach ($matches as $match) {
$this
->assertSession()
->assertEscaped(str_replace('*', $this->baseTLD, $match
->getPattern()));
}
}
}