You are here

public function SearchApiBackendUnitTest::testIndexField in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
  2. 8 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
  3. 8.2 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()

@covers ::addIndexField

@dataProvider addIndexFieldDataProvider

Parameters

mixed $input: Field value.

string $type: Field type.

mixed $expected: Expected result.

File

tests/src/Unit/SearchApiBackendUnitTest.php, line 97

Class

SearchApiBackendUnitTest
Tests functionality of the backend.

Namespace

Drupal\Tests\search_api_solr\Unit

Code

public function testIndexField($input, $type, $expected) {
  $field = 'testField';
  $document = $this
    ->prophesize(Document::class);
  if (NULL !== $expected) {
    if (is_array($expected)) {
      $document
        ->addField($field, $expected[0], $expected[1])
        ->shouldBeCalled();
    }
    else {
      $document
        ->addField($field, $expected)
        ->shouldBeCalled();
    }
  }
  else {
    $document
      ->addField($field, $expected)
      ->shouldNotBeCalled();
  }
  $boost_terms = [];
  $args = [
    $document
      ->reveal(),
    $field,
    [
      $input,
    ],
    $type,
    &$boost_terms,
  ];

  // addIndexField() should convert the $input according to $type and call
  // Document::addField() with the correctly converted $input.
  $this
    ->invokeMethod($this->backend, 'addIndexField', $args, []);
}