You are here

public function RequestDomainTest::testRequestDomainNegate in Context 8.4

Tests the negated request domain condition against a path/route.

File

tests/src/Kernel/RequestDomainTest.php, line 83

Class

RequestDomainTest
Tests the request domain condition plugin.

Namespace

Drupal\Tests\context\Kernel

Code

public function testRequestDomainNegate() {
  $request = Request::create('/');
  $this->requestStack
    ->push($request);
  $domain = $request
    ->getHost();

  /** @var \Drupal\context\Plugin\Condition\RequestDomain $condition */
  $condition = $this->pluginManager
    ->createInstance('request_domain');
  $condition
    ->setConfig('negate', 1);
  $condition
    ->setConfig('domains', $domain);
  $this
    ->assertFalse($condition
    ->execute(), 'Domains do not match');
  $this
    ->assertEquals($condition
    ->summary(), 'Do not return true on the following domains: ' . $domain, 'Domains match.');
  $condition
    ->setConfig('domains', 'example.com');
  $this
    ->assertTrue($condition
    ->execute(), 'Domains match');
}