DomainAliasListHostnameTest.php in Domain Access 8
File
domain_alias/tests/src/Functional/DomainAliasListHostnameTest.php
View source
<?php
namespace Drupal\Tests\domain_alias\Functional;
class DomainAliasListHostnameTest extends DomainAliasTestBase {
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
->loadMultiple();
$base = $this->baseHostname;
$hostnames = [
$base,
'one.' . $base,
'two.' . $base,
];
$patterns = [
'*.' . $base,
'four.' . $base,
'five.' . $base,
];
$i = 0;
foreach ($domains as $domain) {
$this
->assert($domain
->getHostname() == $hostnames[$i], 'Hostnames set correctly');
$this
->assert($domain
->getCanonical() == $hostnames[$i], 'Canonical domains set correctly');
$values = [
'domain_id' => $domain
->id(),
'pattern' => array_shift($patterns),
'redirect' => 0,
'environment' => 'local',
];
$this
->createDomainAlias($values);
$i++;
}
$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.' . $base, 'Proper pattern match loaded.');
$admin = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
'administer node fields',
'administer node display',
'administer domains',
]);
$this
->drupalLogin($admin);
$this
->drupalGet($domain
->getScheme() . 'five.' . $base . '/admin/config/domain');
$this
->assertSession()
->statusCodeEquals(200);
$this
->pressButton('edit-submit');
$i = 0;
$domains = $domain_storage
->loadMultiple();
foreach ($domains as $domain) {
$this
->assert($domain
->getHostname() == $hostnames[$i], 'Hostnames set correctly');
$this
->assert($domain
->getCanonical() == $hostnames[$i], 'Canonical domains set correctly');
$i++;
}
}
}