You are here

public function ReverseEntityReferencesTest::testGetPropertyDefinitions in Search API 8

Tests that property definitions are created correctly.

@covers ::getPropertyDefinitions

File

tests/src/Kernel/Processor/ReverseEntityReferencesTest.php, line 112

Class

ReverseEntityReferencesTest
Tests the "Reverse entity references" processor.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function testGetPropertyDefinitions() {
  $properties = $this->processor
    ->getPropertyDefinitions(NULL);
  $this
    ->assertEmpty($properties);
  $datasource = $this
    ->createMock(DatasourceInterface::class);
  $datasource
    ->method('getEntityTypeId')
    ->willReturn(NULL);
  $properties = $this->processor
    ->getPropertyDefinitions($datasource);
  $this
    ->assertEmpty($properties);
  $datasource = $this->index
    ->getDatasource('entity:user');
  $properties = $this->processor
    ->getPropertyDefinitions($datasource);
  $this
    ->assertArrayHasKey('search_api_reverse_entity_references_node__uid', $properties);

  /** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface|\Drupal\search_api\Processor\ProcessorPropertyInterface $property */
  $property = $properties['search_api_reverse_entity_references_node__uid'];
  $this
    ->assertInstanceOf(EntityDataDefinitionInterface::class, $property);
  $this
    ->assertInstanceOf(ProcessorPropertyInterface::class, $property);
  $this
    ->assertEquals('node', $property
    ->getEntityTypeId());
  $this
    ->assertEquals('reverse_entity_references', $property
    ->getProcessorId());
  $this
    ->assertTrue($property
    ->isList());
}