DomainInactiveTest.php in Domain Access 8
File
domain/tests/src/Functional/DomainInactiveTest.php
View source
<?php
namespace Drupal\Tests\domain\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\RoleInterface;
class DomainInactiveTest extends DomainTestBase {
public static $modules = [
'domain',
'node',
'views',
];
public function testInactiveDomain() {
$site_config = $this
->config('system.site');
$site_config
->set('page.front', '/node')
->save();
$this
->domainCreateTestDomains(4);
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
$domain = $domains['two_example_com'];
$this
->drupalGet($domain
->getPath());
$this
->assertTrue($domain
->status(), 'Tested domain is set to active.');
$this
->assertTrue($domain
->getPath() == $this
->getUrl(), 'Loaded the active domain.');
$domain
->disable();
$default = \Drupal::entityTypeManager()
->getStorage('domain')
->loadDefaultDomain();
$this
->drupalGet($domain
->getPath());
$this
->assertFalse($domain
->status(), 'Tested domain is set to inactive.');
$this
->assertTrue($default
->getPath() == $this
->getUrl(), 'Redirected an inactive domain to the default domain.');
$url = $domain
->getPath() . 'user/login';
$this
->drupalGet($url);
$this
->assertResponse(200, 'Request to login on inactive domain allowed.');
$url = $domain
->getPath() . 'user/password';
$this
->drupalGet($url);
$this
->assertResponse(200, 'Request to reset password on inactive domain allowed.');
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
'access inactive domains',
]);
drupal_flush_all_caches();
$this
->assertFalse($domain
->status(), 'Tested domain is set to inactive.');
$this
->drupalGet($domain
->getPath());
$domain2 = $domains['one_example_com'];
$domain3 = $domains['three_example_com'];
$settings['settings']['trusted_host_patterns'] = (object) [
'value' => [
'^' . $this
->prepareTrustedHostname($domain
->getHostname()) . '$',
'^' . $this
->prepareTrustedHostname($domain2
->getHostname()) . '$',
],
'required' => TRUE,
];
$this
->writeSettings($settings);
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, [
'access inactive domains',
]);
$domain2
->saveDefault();
$this
->drupalGet($domain
->getPath());
$this
->assertTrue($domain2
->getPath() == $this
->getUrl(), 'Redirected from the inactive domain.');
$this
->assertResponse(200, 'Request to trusted host allowed.');
drupal_flush_all_caches();
$domain3
->saveDefault();
$this
->drupalGet($domain
->getPath());
$this
->assertRaw('The provided host name is not a valid redirect.');
}
}