function SelectionTest::testAnchorTagStripping

Same name and namespace in other branches
  1. 10 core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::testAnchorTagStripping()
  2. 9 core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::testAnchorTagStripping()
  3. 8.9.x 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 148

Class

SelectionTest
Tests entity reference selection handler.

Namespace

Drupal\Tests\field\Kernel\EntityReference\Views

Code

public function testAnchorTagStripping() : void {
  $filtered_rendered_results_formatted = [];
  foreach ($this->selectionHandler
    ->getReferenceableEntities() as $subresults) {
    $filtered_rendered_results_formatted += array_map(fn(MarkupInterface $markup): string => (string) $markup, $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->assertSame($expected, $filtered_rendered_results_formatted, 'Anchor tag stripping has failed.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.