public function RenderedItemTest::testSearchExcerptField in Search API 8
Tests that the "Search excerpt" field in entity displays works correctly.
File
- tests/
src/ Kernel/ Processor/ RenderedItemTest.php, line 366
Class
- RenderedItemTest
- Tests the "Rendered item" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function testSearchExcerptField() {
\Drupal::getContainer()
->get('module_installer')
->install([
'search_api_test_excerpt_field',
]);
$this
->installEntitySchema('entity_view_mode');
$view_mode = EntityViewDisplay::load('node.article.teaser');
$view_mode
->set('content', [
'search_api_excerpt' => [
'weight' => 0,
'region' => 'content',
],
]);
$view_mode
->save();
$item = $this
->generateItem([
'datasource' => 'entity:node',
'item' => $this->nodes[3]
->getTypedData(),
'item_id' => 3,
]);
$test_value = 'This is the test excerpt value';
$item
->setExcerpt($test_value);
$this->processor
->addFieldValues($item);
$rendered_item = $item
->getField('rendered_item');
$values = $rendered_item
->getValues();
$this
->assertCount(1, $values);
$this
->assertInstanceOf(TextValueInterface::class, $values[0]);
$this
->assertStringContainsString($test_value, (string) $values[0]);
}