You are here

public function FieldsProcessorPluginBaseTest::testProcessConditions in Search API 8

Tests whether preprocessing search conditions works correctly.

File

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

Class

FieldsProcessorPluginBaseTest
Tests the base class for fields-based processors.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testProcessConditions() {
  $query = \Drupal::getContainer()
    ->get('search_api.query_helper')
    ->createQuery($this->index);
  $query
    ->addCondition('text_field', 'foo');
  $query
    ->addCondition('text_field', [
    'foo',
    'bar',
  ], 'IN');
  $query
    ->addCondition('string_field', NULL, '<>');
  $query
    ->addCondition('integer_field', 'bar');
  $query2 = clone $query;
  $this->processor
    ->preprocessSearchQuery($query);
  $expected = [
    new Condition('text_field', '*foo'),
    new Condition('text_field', [
      '*foo',
      '*bar',
    ], 'IN'),
    new Condition('string_field', NULL, '<>'),
    new Condition('integer_field', 'bar'),
  ];
  $this
    ->assertEquals($expected, $query
    ->getConditionGroup()
    ->getConditions(), 'Conditions were preprocessed correctly.');
  $this->processor
    ->setMethodOverride('shouldProcess', function () {
    return TRUE;
  });
  $this->processor
    ->preprocessSearchQuery($query2);
  $expected = [
    new Condition('text_field', '*foo'),
    new Condition('text_field', [
      '*foo',
      '*bar',
    ], 'IN'),
    new Condition('string_field', 'undefined', '<>'),
    new Condition('integer_field', 'bar'),
  ];
  $this
    ->assertEquals($expected, $query2
    ->getConditionGroup()
    ->getConditions(), 'Conditions were preprocessed correctly.');
}