You are here

public function HierarchicalTermFormatterTest::testFormatter in Hierarchical Term Formatter 8

Tests Hierarchical Term Formatter core functionality.

@dataProvider dataProvider

File

tests/src/Functional/HierarchicalTermFormatterTest.php, line 109

Class

HierarchicalTermFormatterTest
Verifies Hierarchical Term Formatter.

Namespace

Drupal\Tests\hierarchical_term_formatter\Functional

Code

public function testFormatter($term_label, $expected) {

  // Create the node.
  $node = $this->container
    ->get('entity_type.manager')
    ->getStorage('node')
    ->create([
    'title' => $this
      ->randomMachineName(),
    'type' => 'number_story',
    'field_number' => $this->createdTerms[$term_label],
  ]);
  $node
    ->save();
  $nid = $node
    ->id();
  $this
    ->drupalLogin($this->user);

  // Perform the actual test.
  foreach ($expected as $display_mode => $expected_value) {
    if ($display_mode == 'linked') {

      // We need to build the concatenated link string.
      // We do this here because we need the Service container.
      $expected_value = $this
        ->generateLinkString($expected_value['items'], $expected_value['separator']);
    }
    $this
      ->drupalGet("node/{$nid}/preview/{$display_mode}");
    $this
      ->assertRaw(">{$expected_value}<");
  }
  $this
    ->drupalLogout();
}