You are here

public function FieldsProcessorPluginBaseTest::testProcessFieldRemoveValue in Search API 8

Tests whether removing values in processFieldValue() works correctly.

File

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

Class

FieldsProcessorPluginBaseTest
Tests the base class for fields-based processors.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testProcessFieldRemoveValue() {
  $override = function (&$value) {
    if ($value != 'bar') {
      $value = "*{$value}";
    }
    else {
      $value = '';
    }
  };
  $this->processor
    ->setMethodOverride('processFieldValue', $override);
  $fields = [
    'field1' => [
      'type' => 'string',
      'values' => [
        'foo',
        'bar',
      ],
    ],
  ];
  $items = $this
    ->createItems($this->index, 1, $fields);
  $this->processor
    ->preprocessIndexItems($items);
  $item_fields = $items[$this->itemIds[0]]
    ->getFields();
  $this
    ->assertEquals([
    '*foo',
  ], $item_fields['field1']
    ->getValues(), 'Field value was correctly removed.');
}