You are here

public function DomainConditionTest::testConditions in Domain Access 8

Test the domain condition.

File

domain/tests/src/Functional/Condition/DomainConditionTest.php, line 63

Class

DomainConditionTest
Tests the domain condition.

Namespace

Drupal\Tests\domain\Functional\Condition

Code

public function testConditions() {

  // Grab the domain condition and configure it to check against one domain.
  $configuration = [
    'domains' => [
      $this->testDomain
        ->id() => $this->testDomain
        ->id(),
    ],
    'context' => [
      'domain' => $this->notDomain,
    ],
  ];
  $condition = $this->manager
    ->createInstance('domain', $configuration);
  $this
    ->assertFalse($condition
    ->execute(), 'Domain request condition fails on wrong domain.');

  // Grab the domain condition and configure it to check against itself.
  $configuration = [
    'domains' => [
      $this->testDomain
        ->id() => $this->testDomain
        ->id(),
    ],
    'context' => [
      'domain' => $this->testDomain,
    ],
  ];
  $condition = $this->manager
    ->createInstance('domain', $configuration);
  $this
    ->assertTrue($condition
    ->execute(), 'Domain request condition succeeds on matching domain.');

  // Check for the proper summary.
  // Summaries require an extra space due to negate handling in summary().
  $this
    ->assertEqual($condition
    ->summary(), 'Active domain is ' . $this->testDomain
    ->label());

  // Check the negated summary.
  $condition
    ->setConfig('negate', TRUE);
  $this
    ->assertEqual($condition
    ->summary(), 'Active domain is not ' . $this->testDomain
    ->label());

  // Check the negated condition.
  $this
    ->assertFalse($condition
    ->execute(), 'Domain request condition fails when condition negated.');
}