HierarchyNestedSetRevisionIntegrationTest.php in Entity Reference Hierarchy 3.x
File
tests/src/Kernel/HierarchyNestedSetRevisionIntegrationTest.php
View source
<?php
namespace Drupal\Tests\entity_hierarchy\Kernel;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity_test\Entity\EntityTestRev;
use PNX\NestedSet\Node;
class HierarchyNestedSetRevisionIntegrationTest extends HierarchyNestedSetIntegrationTest {
const ENTITY_TYPE = 'entity_test_rev';
protected function additionalSetup() {
$this
->installEntitySchema('entity_test');
parent::additionalSetup();
}
protected function doCreateTestEntity(array $values) {
$entity = EntityTestRev::create($values);
return $entity;
}
protected function createTestEntity($parentId, $label = 'Child 1', $weight = 0, $withRevision = TRUE) {
$entity = parent::createTestEntity($parentId, $label, $weight);
if ($withRevision) {
$entity
->setNewRevision(TRUE);
$entity
->save();
}
return $entity;
}
protected function doCreateChildTestEntity($parentId, $label, $weight) {
return $this
->createTestEntity($parentId, $label, $weight, FALSE);
}
protected function getChildren(Node $parent_node) {
$children = parent::getChildren($parent_node);
$entity_storage = $this->container
->get('entity_type.manager')
->getStorage(static::ENTITY_TYPE);
$entities = $entity_storage
->loadMultiple();
$revisions = array_map(function (EntityInterface $entity) {
return $entity
->getRevisionId();
}, $entities);
$children = array_values(array_filter($children, function (Node $node) use ($revisions) {
return in_array($node
->getRevisionId(), $revisions, TRUE);
}));
return $children;
}
protected function resaveParent() {
$this->parent
->setNewRevision(TRUE);
$this->parent
->save();
$this->parentStub = $this->nodeFactory
->fromEntity($this->parent);
}
}