public function RenderedItemTest::testHideRenderedItem in Search API 8
Tests that hiding a rendered item works.
File
- tests/
src/ Kernel/ Processor/ RenderedItemTest.php, line 326
Class
- RenderedItemTest
- Tests the "Rendered item" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function testHideRenderedItem() {
// Change the processor configuration to make sure that that the rendered
// item content will be empty.
$field = $this->index
->getField('rendered_item');
$config = $field
->getConfiguration();
$config['view_mode'] = [
'entity:node' => [
'page' => '',
'article' => '',
],
];
$field
->setConfiguration($config);
// Create items that we can index.
$items = [];
foreach ($this->nodes as $node) {
$items[] = [
'datasource' => 'entity:node',
'item' => $node
->getTypedData(),
'item_id' => $node
->id(),
'text' => 'text for ' . $node
->id(),
];
}
$items = $this
->generateItems($items);
// Add the processor's field values to the items.
foreach ($items as $item) {
$this->processor
->addFieldValues($item);
}
// Verify that no field values were added.
foreach ($items as $key => $item) {
$rendered_item = $item
->getField('rendered_item');
$this
->assertEmpty($rendered_item
->getValues(), 'No rendered_item field value added when disabled for content type.');
}
}