You are here

public function ViewsTest::testDeriver in Search API Autocomplete 8

Tests that the deriver works correctly.

See also

\Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\search\ViewsDeriver

File

tests/src/Kernel/ViewsTest.php, line 227

Class

ViewsTest
Tests Views integration of the Autocomplete module.

Namespace

Drupal\Tests\search_api_autocomplete\Kernel

Code

public function testDeriver() {
  $searches = $this->container
    ->get('plugin.manager.search_api_autocomplete.search')
    ->getDefinitions();
  $expected = [
    'search_api_autocomplete_test',
  ];
  $this
    ->assertEquals($expected, array_keys($searches));
  $this
    ->installConfig('search_api_autocomplete_test');
  $searches = $this->container
    ->get('plugin.manager.search_api_autocomplete.search')
    ->getDefinitions();
  ksort($searches);
  $expected = [
    'search_api_autocomplete_test',
    'views:search_api_autocomplete_test_view',
  ];
  $this
    ->assertEquals($expected, array_keys($searches));
  View::create([
    'id' => 'second_test_view',
    'base_field' => 'search_api_id',
    'base_table' => 'search_api_index_autocomplete_search_index',
    'core' => '8.x',
    'display' => [
      'default' => [
        'display_plugin' => 'default',
        'id' => 'default',
        'display_title' => 'Master',
        'position' => 0,
        'display_options' => [
          'query' => [
            'type' => 'search_api_query',
          ],
        ],
      ],
    ],
  ])
    ->save();
  $searches = $this->container
    ->get('plugin.manager.search_api_autocomplete.search')
    ->getDefinitions();
  ksort($searches);
  $expected = [
    'search_api_autocomplete_test',
    'views:search_api_autocomplete_test_view',
    'views:second_test_view',
  ];
  $this
    ->assertEquals($expected, array_keys($searches));
}