public function SupportedGroupingFieldsTest::testSupportedSortFields in Search API Grouping 8
Check if the supported fields of an index are correct.
File
- tests/
src/ Unit/ SupportedGroupingFieldsTest.php, line 53
Class
- SupportedGroupingFieldsTest
- Test the getSupportedFields method.
Namespace
Drupal\Tests\search_api_grouping\UnitCode
public function testSupportedSortFields() {
$field_list = [
'author' => [
'type' => 'string',
'label' => 'Author Name',
],
'type' => [
'type' => 'integer',
'label' => 'Content Type',
],
'sticky' => [
'type' => 'boolean',
'label' => 'Sticky',
],
];
$fields = [];
foreach ($field_list as $item) {
$field = $this
->getMockBuilder(FieldInterface::class)
->disableOriginalConstructor()
->getMock();
$field
->method('getType')
->willReturn($item['type']);
$field
->method('getLabel')
->willReturn($item['label']);
$fields[] = $field;
}
$this->index
->method('getFields')
->willReturn($fields);
$this->processor
->setIndex($this->index);
$fields = $this->processor
->getSupportedFields();
$this
->assertEquals('Author Name', $fields['field_sorts'][0]);
$this
->assertEquals('Content Type', $fields['field_sorts'][1]);
$this
->assertArrayNotHasKey(2, $fields['field_sorts']);
}