You are here

public function FieldsProcessorPluginBaseTest::testFieldRenaming in Search API 8

Tests whether the processor handles field changes correctly.

File

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

Class

FieldsProcessorPluginBaseTest
Tests the base class for fields-based processors.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

public function testFieldRenaming() {
  $configuration['fields'] = [
    'float_field',
    'float_field_2',
    'string_field',
    'text_field',
    'text_field_2',
  ];
  $this->processor
    ->setConfiguration($configuration);
  $override = function ($type) {
    return in_array($type, [
      'string',
      'text',
    ]);
  };
  $this->processor
    ->setMethodOverride('testType', $override);
  $this->index
    ->method('getFieldRenames')
    ->willReturn([
    'float_field' => 'foo',
    'text_field' => 'bar',
  ]);
  $this->index
    ->method('getField')
    ->willReturnMap([
    [
      'float_field',
      (new Field($this->index, ''))
        ->setType('float'),
    ],
    [
      'float_field_2',
      NULL,
    ],
    [
      'string_field',
      (new Field($this->index, ''))
        ->setType('string'),
    ],
    [
      'bar',
      (new Field($this->index, ''))
        ->setType('text'),
    ],
    [
      'text_field_2',
      (new Field($this->index, ''))
        ->setType('text'),
    ],
  ]);
  $this->processor
    ->preIndexSave();
  $fields = $this->processor
    ->getConfiguration()['fields'];
  sort($fields);
  $expected = [
    'bar',
    'string_field',
    'text_field_2',
  ];
  $this
    ->assertEquals($expected, $fields);
}