DomainBlockVisibilityTest.php in Domain Access 8
File
domain/tests/src/Functional/DomainBlockVisibilityTest.php
View source
<?php
namespace Drupal\Tests\domain\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\block\Functional\AssertBlockAppearsTrait;
use Drupal\Tests\block\Traits\BlockCreationTrait;
class DomainBlockVisibilityTest extends DomainTestBase {
use AssertBlockAppearsTrait;
use BlockCreationTrait;
public static $modules = [
'domain',
'block',
];
public function testDomainBlockVisibility() {
$this
->domainCreateTestDomains(4);
$domains = \Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple();
$block = $this
->placeBlock('domain_nav_block');
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
'use domain nav block',
]);
foreach ($domains as $domain) {
$url = $domain
->getPath();
$this
->drupalGet($url);
$this
->assertBlockAppears($block);
}
$allowed_domains = [
'example_com' => 'example_com',
'one_example_com' => 'one_example_com',
];
$settings = [
'visibility' => [
'domain' => [
'id' => 'domain',
'domains' => $allowed_domains,
'negate' => FALSE,
'context_mapping' => [
'domain' => '@domain.current_domain_context:domain',
],
],
],
];
$block2 = $this
->placeBlock('domain_nav_block', $settings);
foreach ($domains as $id => $domain) {
$url = $domain
->getPath();
$this
->drupalGet($url);
if (in_array($id, $allowed_domains, TRUE)) {
$this
->assertBlockAppears($block2);
}
else {
$this
->assertNoBlockAppears($block2);
}
}
$settings['visibility']['domain']['negate'] = TRUE;
$block3 = $this
->placeBlock('domain_nav_block', $settings);
foreach ($domains as $id => $domain) {
$url = $domain
->getPath();
$this
->drupalGet($url);
if (!in_array($id, $allowed_domains, TRUE)) {
$this
->assertBlockAppears($block3);
}
else {
$this
->assertNoBlockAppears($block3);
}
}
}
}