You are here

protected function IntegrationTest::addField in Search API 8

Adds a field for a specific property to the index.

Parameters

string|null $datasource_id: The property's datasource's ID, or NULL if it is a datasource-independent property.

string $property_path: The property path.

string|null $label: (optional) If given, the label to check for in the success message.

6 calls to IntegrationTest::addField()
IntegrationTest::addFieldsToIndex in tests/src/Functional/IntegrationTest.php
Tests whether adding fields to the index works correctly.
IntegrationTest::addFieldsWithDependenciesToIndex in tests/src/Functional/IntegrationTest.php
Tests field dependencies.
IntegrationTest::changeProcessorFieldBoost in tests/src/Functional/IntegrationTest.php
Tests that a field added by a processor can be changed.
IntegrationTest::checkFieldLabels in tests/src/Functional/IntegrationTest.php
Tests that field labels are always properly escaped.
IntegrationTest::checkReferenceFieldsNonBaseFields in tests/src/Functional/IntegrationTest.php
Tests if non-base fields of referenced entities can be added.

... See full list

File

tests/src/Functional/IntegrationTest.php, line 958

Class

IntegrationTest
Tests the overall functionality of the Search API framework and admin UI.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function addField($datasource_id, $property_path, $label = NULL) {
  $path = $this
    ->getIndexPath('fields/add/nojs');
  $url_options = [
    'query' => [
      'datasource' => $datasource_id,
    ],
  ];
  list($parent_path) = Utility::splitPropertyPath($property_path);
  if ($parent_path) {
    $url_options['query']['property_path'] = $parent_path;
  }
  if ($this
    ->getUrl() !== $this
    ->buildUrl($path, $url_options)) {
    $this
      ->drupalGet($path, $url_options);
  }

  // Unfortunately it doesn't seem possible to specify the clicked button by
  // anything other than label, so we have to pass it as extra POST data.
  $combined_property_path = Utility::createCombinedId($datasource_id, $property_path);
  $this
    ->assertSession()
    ->responseContains('name="' . $combined_property_path . '"');
  $this
    ->submitForm([], $combined_property_path);
  if ($label) {
    $args['%label'] = $label;
    $this
      ->assertSession()
      ->responseContains(new FormattableMarkup('Field %label was added to the index.', $args));
  }
}