You are here

public function DomainViewsAccessTest::testInactiveDomain in Domain Access 8

Test inactive domain.

File

domain/tests/src/Functional/DomainViewsAccessTest.php, line 22

Class

DomainViewsAccessTest
Tests the domain access plugin for Views.

Namespace

Drupal\Tests\domain\Functional

Code

public function testInactiveDomain() {

  // Create five new domains programmatically.
  $this
    ->domainCreateTestDomains(5);
  $domains = \Drupal::entityTypeManager()
    ->getStorage('domain')
    ->loadMultiple();

  // Enable the views.
  $this
    ->enableViewsTestModule();

  // Create a user. To test the area output was more difficult, so we just
  // configured two views. The page shows the first, admin, user, and the
  // block will show this new user name.
  $this->user = $this
    ->drupalCreateUser([
    'administer domains',
    'create domains',
  ]);

  // Place the view block.
  $this
    ->drupalPlaceBlock('views_block:domain_views_access-block_1');

  // The block and page should be visible on example_com and one_example_com.
  $allowed = [
    'example_com',
    'one_example_com',
  ];
  foreach ($domains as $domain) {
    $path = $domain
      ->getPath() . 'domain-views-access';
    $this
      ->DrupalGet($path);
    if (in_array($domain
      ->id(), $allowed)) {
      $this
        ->assertResponse('200', 'Access allowed');
      $this
        ->assertRaw('admin');
      $this
        ->assertRaw($this->user
        ->getAccountName());
    }
    else {
      $this
        ->assertResponse('403', 'Access denied');
      $this
        ->assertNoRaw('admin');
      $this
        ->assertNoRaw($this->user
        ->getAccountName());
    }

    // Test the block on another page.
    $this
      ->drupalGet($domain
      ->getPath());
    if (in_array($domain
      ->id(), $allowed)) {
      $this
        ->assertRaw($this->user
        ->getAccountName());
    }
    else {
      $this
        ->assertNoRaw($this->user
        ->getAccountName());
    }
  }
}