public function AggregatedFieldsTest::testGetPropertyDefinitions in Search API 8
Tests whether the properties are correctly altered.
See also
\Drupal\search_api\Plugin\search_api\processor\AggregatedFields::getPropertyDefinitions()
File
- tests/
src/ Unit/ Processor/ AggregatedFieldsTest.php, line 298
Class
- AggregatedFieldsTest
- Tests the "Aggregated fields" processor.
Namespace
Drupal\Tests\search_api\Unit\ProcessorCode
public function testGetPropertyDefinitions() {
/** @var \Drupal\Core\StringTranslation\TranslationInterface $translation */
$translation = $this
->getStringTranslationStub();
$this->processor
->setStringTranslation($translation);
// Check for added properties when no datasource is given.
/** @var \Drupal\search_api\Processor\ProcessorPropertyInterface[] $properties */
$properties = $this->processor
->getPropertyDefinitions(NULL);
$this
->assertArrayHasKey('aggregated_field', $properties, 'The "aggregated_field" property was added to the properties.');
$this
->assertInstanceOf(AggregatedFieldProperty::class, $properties['aggregated_field'], 'The "aggregated_field" property has the correct class.');
$this
->assertEquals('string', $properties['aggregated_field']
->getDataType(), 'Correct data type set in the data definition.');
$this
->assertEquals($translation
->translate('Aggregated field'), $properties['aggregated_field']
->getLabel(), 'Correct label set in the data definition.');
$expected_description = $translation
->translate('An aggregation of multiple other fields.');
$this
->assertEquals($expected_description, $properties['aggregated_field']
->getDescription(), 'Correct description set in the data definition.');
// Verify that there are no properties if a datasource is given.
$datasource = $this
->createMock(DatasourceInterface::class);
$properties = $this->processor
->getPropertyDefinitions($datasource);
$this
->assertEmpty($properties, 'Datasource-specific properties did not get changed.');
}