You are here

public function SearchApiBackendUnitTest::testIndexField in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
  2. 8.2 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
  3. 4.x 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 95

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();
  }
  $args = [
    $document
      ->reveal(),
    $field,
    [
      $input,
    ],
    $type,
  ];

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