You are here

public function GroupingTest::testGrouping in Search API Grouping 8

Tests grouping backend.

File

tests/src/Kernel/Processor/GroupingTest.php, line 37

Class

GroupingTest
Tests the "Grouping" processor.

Namespace

Drupal\Tests\search_api_grouping\Kernel

Code

public function testGrouping() {
  $processor = $this->index
    ->getProcessor('grouping');
  $configuration = $processor
    ->getConfiguration();

  // Check if default values are correct.
  $grouping_field = $configuration['grouping_fields'];
  $this
    ->assertEmpty($grouping_field);
  $group_sort = $configuration['group_sort'];
  $this
    ->assertEmpty($group_sort);
  $group_sort_direction = $configuration['group_sort_direction'];
  $this
    ->assertEquals('asc', $group_sort_direction);
  $truncate = $configuration['truncate'];
  $this
    ->assertEquals(0, $truncate);
  $group_limit = $configuration['group_limit'];
  $this
    ->assertEquals('1', $group_limit);

  // Set fields to process.
  $configuration['grouping_fields'] = [
    'field_tags',
  ];
  $configuration['group_sort'] = [
    'None',
  ];
  $configuration['group_sort_direction'] = 'desc';
  $configuration['truncate'] = 1;
  $configuration['group_limit'] = '4';
  $processor
    ->setConfiguration($configuration);
  $this->index
    ->setProcessors([
    'grouping' => $processor,
  ]);
  $this->index
    ->save();
  $processor = $this->index
    ->getProcessor('grouping');
  $configuration = $processor
    ->getConfiguration();

  // Check if the new values are correct.
  $grouping_field = $configuration['grouping_fields'][0];
  $this
    ->assertEquals('field_tags', $grouping_field);
  $group_sort = $configuration['group_sort'][0];
  $this
    ->assertEquals('None', $group_sort);
  $group_sort_direction = $configuration['group_sort_direction'];
  $this
    ->assertEquals('desc', $group_sort_direction);
  $truncate = $configuration['truncate'];
  $this
    ->assertEquals(1, $truncate);
  $group_limit = $configuration['group_limit'];
  $this
    ->assertEquals('4', $group_limit);
}