You are here

protected function ViewsTest::checkExposedSearchFields in Search API 8

Verifies that exposed fulltext fields work correctly.

1 call to ViewsTest::checkExposedSearchFields()
ViewsTest::testSearchView in tests/src/Functional/ViewsTest.php
Tests a view with exposed filters.

File

tests/src/Functional/ViewsTest.php, line 571

Class

ViewsTest
Tests the Views integration of the Search API.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function checkExposedSearchFields() {
  $key = 'display.default.display_options.filters.search_api_fulltext.expose.expose_fields';
  $view = \Drupal::configFactory()
    ->getEditable('views.view.search_api_test_view');
  $view
    ->set($key, TRUE);
  $view
    ->save();
  $query = [
    'search_api_fulltext' => 'foo',
    'search_api_fulltext_searched_fields' => [
      'name',
    ],
  ];
  $this
    ->checkResults($query, [
    1,
    2,
    4,
  ], 'Search for results in name field only');
  $query = [
    'search_api_fulltext' => 'foo',
    'search_api_fulltext_searched_fields' => [
      'body',
    ],
  ];
  $this
    ->checkResults($query, [
    5,
  ], 'Search for results in body field only');
  $view
    ->set($key, FALSE);
  $view
    ->save();
}