You are here

public function HierarchyNestedSetIntegrationTest::testNestedSetResaveParent in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/HierarchyNestedSetIntegrationTest.php \Drupal\Tests\entity_hierarchy\Kernel\HierarchyNestedSetIntegrationTest::testNestedSetResaveParent()

Test saving the parent after adding children.

File

tests/src/Kernel/HierarchyNestedSetIntegrationTest.php, line 259

Class

HierarchyNestedSetIntegrationTest
Tests integration with entity_hierarchy.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testNestedSetResaveParent() {

  // Test for weight ordering of inserts.
  $entities = $this
    ->createChildEntities($this->parent
    ->id());
  $root_node = $this->treeStorage
    ->getNode($this->parentStub);
  $this
    ->assertChildOrder($root_node, $entities, [
    'Child 5',
    'Child 4',
    'Child 3',
    'Child 2',
    'Child 1',
  ]);

  // Now insert one in the middle.
  $name = 'Child 6';
  $entities[$name] = $this
    ->createTestEntity($this->parent
    ->id(), $name, -2);
  $this
    ->assertChildOrder($root_node, $entities, [
    'Child 5',
    'Child 4',
    'Child 3',
    'Child 2',
    'Child 6',
    'Child 1',
  ]);
  $this
    ->resaveParent();
  $this
    ->assertChildOrder($this->treeStorage
    ->getNode($this->parentStub), $entities, [
    'Child 5',
    'Child 4',
    'Child 3',
    'Child 2',
    'Child 6',
    'Child 1',
  ]);
}