DomainConfigOverriderTest.php in Domain Access 8
File
domain_config/tests/src/Functional/DomainConfigOverriderTest.php
View source
<?php
namespace Drupal\Tests\domain_config\Functional;
use Drupal\domain\DomainInterface;
class DomainConfigOverriderTest extends DomainConfigTestBase {
public function testDomainConfigOverrider() {
$this
->domainTableIsEmpty();
$this
->domainCreateTestDomains(5);
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
foreach ($domains as $domain) {
foreach ($this->langcodes as $langcode => $language) {
$path = $domain
->getPath() . $langcode . '/user/login';
$this
->drupalGet($path);
if ($domain
->isDefault()) {
$this
->assertRaw('<title>Log in | Drupal</title>', 'Loaded the proper site name.');
}
else {
$this
->assertRaw('<title>Log in | ' . $this
->expectedName($domain, $langcode) . '</title>', 'Loaded the proper site name.' . '<title>Log in | ' . $this
->expectedName($domain, $langcode) . '</title>');
}
}
}
}
public function testDomainConfigOverriderFromSettings() {
$settings = [];
$settings['config']['domain.config.one_example_com.en.system.site']['name'] = (object) [
'value' => 'First',
'required' => TRUE,
];
$settings['config']['domain.config.four_example_com.system.site']['name'] = (object) [
'value' => 'Four overridden in settings',
'required' => TRUE,
];
$this
->writeSettings($settings);
$this
->domainCreateTestDomains(5);
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple([
'one_example_com',
'four_example_com',
]);
$domain_one = $domains['one_example_com'];
$this
->drupalGet($domain_one
->getPath() . 'user/login');
$this
->assertRaw('<title>Log in | First</title>', 'Found overridden slogan for one.example.com.');
$domain_four = $domains['four_example_com'];
$this
->drupalGet($domain_four
->getPath() . 'user/login');
$this
->assertRaw('<title>Log in | Four overridden in settings</title>', 'Found overridden slogan for four.example.com.');
}
private function expectedName(DomainInterface $domain, $langcode = NULL) {
$name = '';
switch ($domain
->id()) {
case 'one_example_com':
$name = $langcode == 'es' ? 'Drupal' : 'One';
break;
case 'two_example_com':
$name = $langcode == 'es' ? 'Dos' : 'Two';
break;
case 'three_example_com':
$name = 'Drupal';
break;
case 'four_example_com':
$name = 'Four';
break;
}
return $name;
}
}