You are here

public function SelectionTest::testAnchorTagStripping in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::testAnchorTagStripping()

Tests the anchor tag stripping.

Unstripped results based on the data above will result in output like so: ...<a href="/node/1" hreflang="en">Test first node</a>... ...<a href="/node/2" hreflang="en">Test second node</a>... ...<a href="/node/3" hreflang="en">Test third node</a>... If we expect our output to not have the <a> tags, and this matches what's produced by the tag-stripping method, we'll know that it's working.

File

core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php, line 132

Class

SelectionTest
Tests entity reference selection handler.

Namespace

Drupal\Tests\field\Kernel\EntityReference\Views

Code

public function testAnchorTagStripping() {
  $filtered_rendered_results_formatted = [];
  foreach ($this->selectionHandler
    ->getReferenceableEntities() as $subresults) {
    $filtered_rendered_results_formatted += $subresults;
  }

  // Note the missing <a> tags.
  $expected = [
    1 => '<span class="views-field views-field-title"><span class="field-content">' . Html::escape($this->nodes[1]
      ->label()) . '</span></span>',
    2 => '<span class="views-field views-field-title"><span class="field-content">' . Html::escape($this->nodes[2]
      ->label()) . '</span></span>',
    3 => '<span class="views-field views-field-title"><span class="field-content">' . Html::escape($this->nodes[3]
      ->label()) . '</span></span>',
  ];
  $this
    ->assertEquals($expected, $filtered_rendered_results_formatted, 'Anchor tag stripping has failed.');
}