public function RoleAccessTest::testComputedFieldValues in Search API 8
Tests whether the correct field values are created for nodes.
File
- tests/
src/ Kernel/ Processor/ RoleAccessTest.php, line 131
Class
- RoleAccessTest
- Tests the "Role-based access" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function testComputedFieldValues() {
$allowed_foo = $this
->createTestNode('allow for foo role');
$allowed_bar = $this
->createTestNode('allow for bar role');
$allowed_anonymous = $this
->createTestNode('allow for anonymous role');
$allowed_authenticated = $this
->createTestNode('allow for authenticated role');
$allowed_all = $this
->createTestNode('allow for foo, bar, baz, anonymous, authenticated role');
$expected_roles = [
$allowed_foo => [
'foo',
],
$allowed_bar => [
'bar',
],
$allowed_anonymous => [
'anonymous',
],
$allowed_authenticated => [
'authenticated',
],
$allowed_all => [
'foo',
'bar',
'baz',
'anonymous',
'authenticated',
],
];
$fields_helper = \Drupal::getContainer()
->get('search_api.fields_helper');
$datasource = $this->index
->getDatasource('entity:node');
foreach ($expected_roles as $i => $roles) {
$node = $this->nodes[$i];
$item = $fields_helper
->createItemFromObject($this->index, $node
->getTypedData(), NULL, $datasource);
$this->processor
->addFieldValues($item);
$this
->assertEquals($roles, $item
->getField('role_access')
->getValues(), "Wrong roles computed for node \"{$node->label()}\".");
}
}