public function AggregatedFieldTest::setUp in Facets 8
Overrides FacetsTestBase::setUp
File
- tests/
src/ Functional/ AggregatedFieldTest.php, line 28
Class
- AggregatedFieldTest
- Class AggregatedFieldTest.
Namespace
Drupal\Tests\facets\FunctionalCode
public function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this
->setUpExampleStructure();
$this
->insertExampleContent();
foreach ([
7 => 'Owl',
8 => 'Robin',
9 => 'Hawk',
] as $i => $value) {
$this->users[$i] = User::create([
'uid' => $i,
'name' => "User {$value}",
]);
$this->users[$i]
->save();
$this->entities[$i] = EntityTestMulRevChanged::create([
'id' => $i,
'user_id' => $i,
'name' => "Test entity {$value} name",
'body' => "Test entity {$value} body",
]);
$this->entities[$i]
->save();
}
$plugin_creation_helper = \Drupal::getContainer()
->get('search_api.plugin_helper');
$fields_helper = \Drupal::getContainer()
->get('search_api.fields_helper');
/** @var \Drupal\search_api\IndexInterface $index */
$index = Index::load($this->indexId);
// Add the user as a datasource.
$index
->addDatasource($plugin_creation_helper
->createDatasourcePlugin($index, 'entity:user'));
// Create the aggregated field property.
$property = AggregatedFieldProperty::create('string');
// Add and configure the aggregated field.
$field = $fields_helper
->createFieldFromProperty($index, $property, NULL, 'aggregated_field', 'aggregated_field', 'string');
$field
->setLabel('Aggregated field');
$field
->setConfiguration([
'type' => 'union',
'fields' => [
Utility::createCombinedId('entity:entity_test_mulrev_changed', 'name'),
Utility::createCombinedId('entity:user', 'name'),
],
]);
$index
->addField($field);
$index
->save();
// Index all items, users and content.
$this
->assertEquals(16, $this
->indexItems($this->indexId));
}