ChildOfMicrositeConditionTest.php in Entity Reference Hierarchy 8.2
File
modules/entity_hierarchy_microsite/tests/src/Kernel/ChildOfMicrositeConditionTest.php
View source
<?php
namespace Drupal\Tests\entity_hierarchy_microsite\Kernel;
use Drupal\entity_hierarchy_microsite\Entity\Microsite;
class ChildOfMicrositeConditionTest extends EntityHierarchyMicrositeKernelTestBase {
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();
$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);
$this
->assertFalse($condition
->evaluate());
}
}