manager = $this->container->get('plugin.manager.condition'); // Create test domains. $this->domainCreateTestDomains(5); // Get two sample domains. $this->domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple(); $this->testDomain = array_shift($this->domains); $this->notDomain = array_shift($this->domains); } /** * Test the domain condition. */ public function testConditions() { // Grab the domain condition and configure it to check against one domain. $condition = $this->manager->createInstance('domain') ->setConfig('domains', [$this->testDomain->id() => $this->testDomain->id()]) ->setContextValue('entity:domain', $this->notDomain); $this->assertFalse($condition->execute(), 'Domain request condition fails on wrong domain.'); // Grab the domain condition and configure it to check against itself. $condition = $this->manager->createInstance('domain') ->setConfig('domains', [$this->testDomain->id() => $this->testDomain->id()]) ->setContextValue('entity:domain', $this->testDomain); $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.'); } }