You are here

public function FieldsProcessorPluginBaseTest::testProcessKeyOverride in Search API 8

Tests whether overriding of processKey() works correctly.

File

tests/src/Unit/Processor/FieldsProcessorPluginBaseTest.php, line 459

Class

FieldsProcessorPluginBaseTest
Tests the base class for fields-based processors.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testProcessKeyOverride() {
  $override = function (&$value) {
    if ($value != 'baz') {
      $value = "&{$value}";
    }
    else {
      $value = '';
    }
  };
  $this->processor
    ->setMethodOverride('processKey', $override);
  $query = \Drupal::getContainer()
    ->get('search_api.query_helper')
    ->createQuery($this->index);
  $keys =& $query
    ->getKeys();
  $keys = [
    '#conjunction' => 'OR',
    'foo',
    [
      '#conjunction' => 'AND',
      'bar',
      'baz',
      '#negation' => TRUE,
    ],
  ];
  $this->processor
    ->preprocessSearchQuery($query);
  $expected = [
    '#conjunction' => 'OR',
    '&foo',
    [
      '#conjunction' => 'AND',
      '&bar',
      '#negation' => TRUE,
    ],
  ];
  $this
    ->assertEquals($expected, $query
    ->getKeys(), 'Search keys were correctly preprocessed.');
}