You are here

public function SearchApiBackendUnitTest::testIndexField in Search API Solr 8

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.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 40

Class

SearchApiBackendUnitTest
Tests functionality of the backend.

Namespace

Drupal\Tests\search_api_solr\Unit

Code

public function testIndexField($input, $type, $expected) {
  $connector = $this
    ->prophesize(SolrConnectorInterface::class);
  $connector
    ->getQueryHelper()
    ->willReturn(new Helper());
  $field = 'testField';
  $document = $this
    ->prophesize(Document::class);
  $document
    ->addField($field, $expected)
    ->shouldBeCalled();
  $backend = $this
    ->prophesize(SearchApiSolrBackend::class);
  $backend
    ->getSolrConnector()
    ->willReturn($connector
    ->reveal());
  $args = [
    $document
      ->reveal(),
    $field,
    [
      $input,
    ],
    $type,
  ];
  $backend_instance = $backend
    ->reveal();

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