You are here

public function FieldsProcessorPluginBaseTest::testProcessConditionsNestedConditions in Search API 8

Tests whether preprocessing nested search conditions works correctly.

File

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

Class

FieldsProcessorPluginBaseTest
Tests the base class for fields-based processors.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testProcessConditionsNestedConditions() {
  $query = \Drupal::getContainer()
    ->get('search_api.query_helper')
    ->createQuery($this->index);
  $conditions = $query
    ->createConditionGroup();
  $conditions
    ->addCondition('text_field', 'foo');
  $conditions
    ->addCondition('text_field', [
    'foo',
    'bar',
  ], 'IN');
  $conditions
    ->addCondition('string_field', NULL, '<>');
  $conditions
    ->addCondition('integer_field', 'bar');
  $query
    ->addConditionGroup($conditions);
  $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()[0]
    ->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()[0]
    ->getConditions(), 'Conditions were preprocessed correctly.');
}