You are here

public function GroupingSolrTest::testPreProcessSearchQuery in Search API Grouping 8

Test if the setOption Method is called with the expected values.

File

tests/src/Unit/GroupingSolrTest.php, line 30

Class

GroupingSolrTest
Test the getSupportedFields method.

Namespace

Drupal\Tests\search_api_grouping\Unit

Code

public function testPreProcessSearchQuery() {
  $query = $this
    ->getMockBuilder(Query::class)
    ->disableOriginalConstructor()
    ->getMock();

  // Set configurations for the Grouping processor.
  $config = [
    'grouping_fields' => [
      'type' => 'type',
    ],
    'truncate' => TRUE,
    'group_limit' => 3,
    'group_sort' => 'type',
  ];
  $this->processor
    ->setConfiguration($config);

  // Set expected option array.
  $query_option = [
    'use_grouping' => TRUE,
    'grouping_fields' => [
      'type' => 'type',
    ],
    'truncate' => TRUE,
    'group_limit' => 3,
    'group_sort' => [
      'type' => 'asc',
    ],
  ];
  $query
    ->expects($this
    ->once())
    ->method('setOption')
    ->with($this
    ->identicalTo('search_api_grouping'), $this
    ->identicalTo($query_option));
  $this->processor
    ->preprocessSearchQuery($query);
}