You are here

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

Tests views sibling integration with show_self enabled.

File

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

Class

ViewsIntegrationTest
Defines a class for testing views integration.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testViewsIntegrationSiblingsShowSelf() {
  $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 siblings with the show_self option enabled.
  $expected = [
    [
      'name' => 'Child 3',
      'id' => 4,
    ],
    [
      'name' => 'Child 2',
      'id' => 3,
    ],
    [
      'name' => 'Child 1',
      'id' => 2,
    ],
  ];
  $executable = Views::getView('entity_hierarchy_test_children_view');
  $executable
    ->preview('block_5', [
    $this
      ->getArgumentFromEntity($child),
  ]);
  $this
    ->assertCount(3, $executable->result);
  $this
    ->assertIdenticalResultset($executable, $expected, [
    'name' => 'name',
    'id' => 'id',
  ]);
}