protected function RenderedItemTest::checkRenderedNode in Search API 8
Verifies that a certain node has been rendered correctly.
Parameters
\Drupal\node\NodeInterface $node: The node.
string $field_value: The rendered field value.
1 call to RenderedItemTest::checkRenderedNode()
- RenderedItemTest::testAddFieldValues in tests/
src/ Kernel/ Processor/ RenderedItemTest.php - Tests whether the rendered_item field is correctly filled by the processor.
File
- tests/
src/ Kernel/ Processor/ RenderedItemTest.php, line 277
Class
- RenderedItemTest
- Tests the "Rendered item" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
protected function checkRenderedNode(NodeInterface $node, $field_value) {
// These tests rely on the template not changing. However, if we'd only
// check whether the field values themselves are included, there could
// easier be false positives. For example, the title text was present even
// when the processor was broken, because the schema metadata was also
// adding it to the output.
$nid = $node
->id();
$full_view = $node
->bundle() === 'page';
$view_mode = $full_view ? 'full' : 'teaser';
$this
->assertStringContainsString("view-mode-{$view_mode}", $field_value, 'Node item ' . $nid . " rendered in view-mode \"{$view_mode}\".");
$this
->assertStringContainsString('field--name-title', $field_value, 'Node item ' . $nid . ' has a rendered title field.');
$this
->assertStringContainsString('>' . $node
->label() . '<', $field_value, 'Node item ' . $nid . ' has a rendered title inside HTML-Tags.');
$this
->assertStringContainsString('>Member for<', $field_value, 'Node item ' . $nid . ' has rendered member information HTML-Tags.');
if ($full_view) {
$body_value = $node
->get('body')
->getValue()[0]['value'] . '<';
}
else {
$body_value = $node
->get('body')
->getValue()[0]['summary'] . '<';
}
$this
->assertStringContainsString('>' . $body_value, $field_value, 'Node item ' . $nid . ' has rendered content inside HTML-Tags.');
}