protected function ViewsFieldTraitTest::setUp in Search API 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Views/ ViewsFieldTraitTest.php, line 70
Class
- ViewsFieldTraitTest
- Tests the functionality of our Views field plugin trait.
Namespace
Drupal\Tests\search_api\Kernel\ViewsCode
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('entity_test_mulrev_changed');
$this
->installEntitySchema('user');
$this
->installConfig([
'search_api_test_example_content',
'user',
]);
for ($i = 1; $i <= 3; ++$i) {
$this->users[$i] = User::create([
'uid' => $i,
'name' => "User {$i}",
]);
$this->users[$i]
->save();
$this->entities[$i] = EntityTestMulRevChanged::create([
'id' => $i,
'user_id' => $i,
'name' => "Test entity {$i} name",
'body' => "Test entity {$i} body",
]);
$this->entities[$i]
->save();
}
// Create the test index, but don't save it. We don't need it saved for this
// test and saving it would need more time and additional code (e.g., would
// track all the entities we create).
$datasource_id = 'entity:entity_test_mulrev_changed';
$this->index = Index::create([
'field_settings' => [
'aggregated_field' => [
'label' => 'Aggregated field',
'property_path' => 'aggregated_field',
'type' => 'string',
'configuration' => [
'type' => 'union',
'fields' => [
Utility::createCombinedId($datasource_id, 'name'),
Utility::createCombinedId($datasource_id, 'body'),
Utility::createCombinedId('entity:user', 'name'),
],
],
],
],
'datasource_settings' => [
$datasource_id => [],
'entity:user' => [],
],
'processor_settings' => [
'aggregated_field' => [],
],
]);
$this->field = new ViewsTestField([], 'search_api', []);
/** @var \Drupal\search_api\Plugin\views\query\SearchApiQuery|\PHPUnit\Framework\MockObject\MockObject $query */
$query = $this
->getMockBuilder(SearchApiQuery::class)
->disableOriginalConstructor()
->getMock();
$query
->method('getIndex')
->willReturn($this->index);
$query
->method('getAccessAccount')
->willReturn($this->users[1]);
$this->field
->setQuery($query);
}