You are here

public function FieldsProcessorPluginBaseTest::testProcessConditionValueOverride in Search API 8

Tests whether overriding processConditionValue() works correctly.

File

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

Class

FieldsProcessorPluginBaseTest
Tests the base class for fields-based processors.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testProcessConditionValueOverride() {
  $override = function (&$value) {
    if (isset($value)) {
      $value = '';
    }
  };
  $this->processor
    ->setMethodOverride('processConditionValue', $override);
  $query = \Drupal::getContainer()
    ->get('search_api.query_helper')
    ->createQuery($this->index);
  $query
    ->addCondition('text_field', 'foo');
  $query
    ->addCondition('string_field', NULL, '<>');
  $query
    ->addCondition('integer_field', 'bar');
  $this->processor
    ->preprocessSearchQuery($query);
  $expected = [
    new Condition('string_field', NULL, '<>'),
    new Condition('integer_field', 'bar'),
  ];
  $this
    ->assertEquals($expected, array_merge($query
    ->getConditionGroup()
    ->getConditions()), 'Conditions were preprocessed correctly.');
}