public function ReverseEntityReferencesTest::testAddFieldValues in Search API 8
Tests that field value extraction works correctly.
@covers ::addFieldValues
File
- tests/
src/ Kernel/ Processor/ ReverseEntityReferencesTest.php, line 140
Class
- ReverseEntityReferencesTest
- Tests the "Reverse entity references" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function testAddFieldValues() {
$nids_by_user = [];
foreach ($this->nodeUids as $i => $uid) {
$nids_by_user[$uid][] = $this->nodes[$i]
->id();
}
$fields_helper = \Drupal::getContainer()
->get('search_api.fields_helper');
foreach ([
0,
1,
2,
3,
] as $uid) {
$item = $fields_helper
->createItem($this->index, "entity:user/{$uid}:en");
// This will automatically trigger field extraction.
$nids = $item
->getField('nid')
->getValues();
sort($nids);
$nids_by_user += [
$uid => [],
];
$this
->assertEquals($nids_by_user[$uid], $nids, "Unexpected field values extracted for user #{$uid}.");
}
}