You are here

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

Tests the depth field.

File

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

Class

ViewsIntegrationTest
Defines a class for testing views integration.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testDepthField() {
  $children = $this
    ->createChildEntities($this->parent
    ->id(), 1);
  $child = reset($children);
  $this
    ->createChildEntities($child
    ->id(), 1);

  // Tree is as follows
  // 1     : Parent
  // - 2   : Child 1
  // - - 3 : Child 1.
  $executable = Views::getView('entity_hierarchy_test_fields_view');
  $output = $executable
    ->preview('field_depth');
  $output = \Drupal::service('renderer')
    ->renderRoot($output);
  $this
    ->assertStringContainsString('Parent at depth 0', $output);
  $this
    ->assertStringContainsString('Child 1 at depth 2', $output);
}