You are here

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

Tests the relationship to the parent node.

File

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

Class

ViewsIntegrationTest
Defines a class for testing views integration.

Namespace

Drupal\Tests\entity_hierarchy\Kernel

Code

public function testRelationshipParent() {
  $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('parent');
  $output = \Drupal::service('renderer')
    ->renderRoot($output);
  $this
    ->assertStringContainsString('Child First1 is parent of Child Second2', $output);
  $this
    ->assertStringContainsString('Child Second1 is parent of Child Third1', $output);
  $this
    ->assertStringContainsString('Child Third1 is parent of Child Fourth1', $output);
  $this
    ->assertStringNotContainsString('Child Fourth1 is parent of', $output);
  $this
    ->assertEquals(5, substr_count($output, ' is parent of Child'));
}