View source
<?php
namespace Drupal\Tests\domain_config\Functional;
use Drupal\user\RoleInterface;
class DomainConfigHomepageTest extends DomainConfigTestBase {
public static $modules = [
'node',
'views',
];
public function testDomainConfigHomepage() {
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access content',
]);
$site_config = $this
->config('system.site');
$site_config
->set('page.front', '/node')
->save();
$this
->domainTableIsEmpty();
$this
->domainCreateTestDomains(5);
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
$node1 = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Node 1',
'promoted' => TRUE,
]);
$node2 = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Node 2',
'promoted' => TRUE,
]);
$node3 = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Node 3',
'promoted' => TRUE,
]);
$homepages = $this
->getHomepages();
foreach ($domains as $domain) {
foreach ([
'en',
'es',
] as $langcode) {
$prefix = '';
if ($langcode == 'es') {
$prefix = 'es/';
}
$home = $this
->drupalGet($domain
->getPath() . $prefix);
$expected = $domain
->getPath() . $prefix . $homepages[$domain
->id()][$langcode];
$expected_home = $this
->drupalGet($expected);
$this
->assertEqual($home, $expected_home, 'Proper home page loaded (' . $domain
->id() . ').');
}
}
$admin_user = $this
->drupalCreateUser([
'bypass node access',
'access administration pages',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet($domain
->getPath() . 'node/' . $node3
->id() . '/delete');
$this
->getSession()
->getPage()
->pressButton('Delete');
$this
->drupalLogout();
foreach ($domains as $domain) {
foreach ([
'en',
'es',
] as $langcode) {
$prefix = '';
if ($langcode == 'es') {
$prefix = 'es/';
}
$this
->drupalGet($domain
->getPath() . $prefix);
$home = $this
->drupalGet($domain
->getPath() . $prefix);
$expected = $domain
->getPath() . $prefix . $homepages[$domain
->id()][$langcode];
$expected_home = $this
->drupalGet($expected);
$this
->assertEqual($home, $expected_home, 'Proper home page loaded (' . $domain
->id() . ').');
}
}
}
private function getHomepages() {
$homepages = [
'example_com' => [
'en' => 'node',
'es' => 'node',
],
'one_example_com' => [
'en' => 'node/1',
'es' => 'node',
],
'two_example_com' => [
'en' => 'node',
'es' => 'node',
],
'three_example_com' => [
'en' => 'node',
'es' => 'node',
],
'four_example_com' => [
'en' => 'node/2',
'es' => 'node/2',
],
];
return $homepages;
}
}