You are here

public function ViewsIntegrationTest::testViewsIntegrationSiblings in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ViewsIntegrationTest.php \Drupal\Tests\entity_hierarchy\Kernel\ViewsIntegrationTest::testViewsIntegrationSiblings()

Tests views sibling integration.

File

tests/src/Kernel/ViewsIntegrationTest.php, line 189

Class

ViewsIntegrationTest
Defines a class for testing views integration.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testViewsIntegrationSiblings() {
  $children = $this
    ->createChildEntities($this->parent
    ->id(), 3);
  $child = reset($children);
  $this
    ->createChildEntities($child
    ->id(), 5);

  // Tree is as follows
  // 1     : Parent
  // - 4   : Child 3
  // - 3   : Child 2
  // - 2   : Child 1
  // - - 9 : Child 5
  // - - 8 : Child 4
  // - - 7 : Child 3
  // - - 6 : Child 2
  // - - 5 : Child 1
  // Test showing single hierarchy.
  $expected = [
    [
      'name' => 'Child 3',
      'id' => 4,
    ],
    [
      'name' => 'Child 2',
      'id' => 3,
    ],
  ];
  $executable = Views::getView('entity_hierarchy_test_children_view');
  $executable
    ->preview('block_4', [
    $this
      ->getArgumentFromEntity($child),
  ]);
  $this
    ->assertCount(2, $executable->result);
  $this
    ->assertIdenticalResultset($executable, $expected, [
    'name' => 'name',
    'id' => 'id',
  ]);
}