public function EntityStatusTest::testSupportsIndex in Search API 8
Tests whether supportsIndex() returns TRUE for an index containing nodes.
@dataProvider supportsIndexDataProvider
Parameters
string[]|null $datasource_ids: The IDs of datasources the index should have, or NULL if it should have all of them.
bool $expected: Whether the processor is supposed to support that index.
File
- tests/
src/ Unit/ Processor/ EntityStatusTest.php, line 83
Class
- EntityStatusTest
- Tests the "Entity status" processor.
Namespace
Drupal\Tests\search_api\Unit\ProcessorCode
public function testSupportsIndex(array $datasource_ids = NULL, $expected) {
if ($datasource_ids !== NULL) {
$datasource_ids = array_flip($datasource_ids);
$this->datasources = array_intersect_key($this->datasources, $datasource_ids);
}
$this->index
->method('getDatasources')
->will($this
->returnValue($this->datasources));
// In supportsIndex(), the entity status processor will use the entity type
// manager to get the definition of each datasource's entity type and then
// check whether it implements \Drupal\Core\Entity\EntityPublishedInterface.
// We therefore need to ensure each of these calls returns an appropriate
// value.
$self = $this;
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->method('getDefinition')
->willReturnCallback(function ($entity_type_id) use ($self) {
$entity_type = $self
->createMock(EntityTypeInterface::class);
$publishable = in_array($entity_type_id, [
'node',
'comment',
]);
$entity_type
->method('entityClassImplements')
->willReturnMap([
[
EntityPublishedInterface::class,
$publishable,
],
]);
return $entity_type;
});
$this->container
->set('entity_type.manager', $entity_type_manager);
$this
->assertEquals($expected, EntityStatus::supportsIndex($this->index));
}