public function ChildOfMicrositeConditionTest::testCondition in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x modules/entity_hierarchy_microsite/tests/src/Kernel/ChildOfMicrositeConditionTest.php \Drupal\Tests\entity_hierarchy_microsite\Kernel\ChildOfMicrositeConditionTest::testCondition()
File
- modules/
entity_hierarchy_microsite/ tests/ src/ Kernel/ ChildOfMicrositeConditionTest.php, line 17
Class
- ChildOfMicrositeConditionTest
- Defines a class for testing the child of microsite condition plugin.
Namespace
Drupal\Tests\entity_hierarchy_microsite\KernelCode
public function testCondition() {
$children = $this
->createChildEntities($this->parent
->id(), 1);
$child = reset($children);
$grandchildren = $this
->createChildEntities($child
->id(), 2);
$microsite = Microsite::create([
'name' => $child
->label(),
'home' => $child,
]);
$microsite
->save();
$standalone = $this
->createChildEntities(NULL, 1);
$standalone = reset($standalone);
$microsite2 = Microsite::create([
'name' => $standalone
->label(),
'home' => $standalone,
]);
$microsite2
->save();
/** @var \Drupal\Core\Condition\ConditionInterface|\Drupal\Core\Plugin\ContextAwarePluginInterface $condition */
$condition = $this->container
->get('plugin.manager.condition')
->createInstance('entity_hierarchy_microsite_child');
$this
->assertTrue($condition
->evaluate());
$condition
->setConfiguration([
'field' => self::FIELD_NAME,
]);
$condition
->setContextValue('node', $this->parent);
$this
->assertFalse($condition
->evaluate());
$condition
->setContextValue('node', $child);
$this
->assertTrue($condition
->evaluate());
$condition
->setContextValue('node', reset($grandchildren));
$this
->assertTrue($condition
->evaluate());
$condition
->setContextValue('node', $standalone);
$this
->assertTrue($condition
->evaluate());
$condition
->setContextValue('node', NULL);
// There is no microsite if there is no active node.
$this
->assertFalse($condition
->evaluate());
}