You are here

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

Tests the relationship to the root node..

File

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

Class

ViewsIntegrationTest
Defines a class for testing views integration.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testRelationshipRoot() {
  $children = $this
    ->createChildEntities($this->parent
    ->id(), 1, 'First');
  $child = reset($children);
  $children = $this
    ->createChildEntities($child
    ->id(), 2, 'Second');
  $child = reset($children);
  $children = $this
    ->createChildEntities($child
    ->id(), 1, 'Third');
  $child = reset($children);
  $children = $this
    ->createChildEntities($child
    ->id(), 1, 'Fourth');

  // Tree is as follows.
  // 1     : First 1
  // - 2   : Second 1
  // - 3   : Second 2
  // -- 4  : Third 1
  // --- 5 : Fourth 1.
  $executable = Views::getView('entity_hierarchy_test_relationships_view');
  $output = $executable
    ->preview('root');
  $output = trim(\Drupal::service('renderer')
    ->renderRoot($output));
  $this
    ->assertStringContainsString('Parent is root of Child First1', $output);
  $this
    ->assertStringContainsString('Parent is root of Child Third1', $output);
  $this
    ->assertStringContainsString('Parent is root of Child Fourth1', $output);
  $this
    ->assertStringNotContainsString('1 is root', $output);
  $this
    ->assertEquals(6, substr_count($output, ' is root of'));
}