You are here

public function ViewsIntegrationTest::testViewsIntegrationIncludingGrandChildren 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::testViewsIntegrationIncludingGrandChildren()

Tests views integration.

File

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

Class

ViewsIntegrationTest
Defines a class for testing views integration.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testViewsIntegrationIncludingGrandChildren() {
  $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,
    ],
    [
      'name' => 'Child 1',
      'id' => 2,
    ],
    [
      'name' => 'Child 5',
      'id' => 9,
    ],
    [
      'name' => 'Child 4',
      'id' => 8,
    ],
    [
      'name' => 'Child 3',
      'id' => 7,
    ],
    [
      'name' => 'Child 2',
      'id' => 6,
    ],
    [
      'name' => 'Child 1',
      'id' => 5,
    ],
  ];
  $executable = Views::getView('entity_hierarchy_test_children_view');
  $executable
    ->preview('block_2', [
    $this
      ->getArgumentFromEntity($this->parent),
  ]);
  $this
    ->assertCount(8, $executable->result);
  $this
    ->assertIdenticalResultset($executable, $expected, [
    'name' => 'name',
    'id' => 'id',
  ]);
}