You are here

public function SearchCrudTest::testCreate in Search API Autocomplete 8

Tests whether saving a new search entity works correctly.

File

tests/src/Kernel/SearchCrudTest.php, line 80

Class

SearchCrudTest
Tests saving a Search API autocomplete config entity.

Namespace

Drupal\Tests\search_api_autocomplete\Kernel

Code

public function testCreate() {
  $this
    ->setMethodOverride('search', 'calculateDependencies', function () {
    return [
      'config' => [
        'search_api.server.server',
      ],
      'module' => [
        'user',
      ],
    ];
  });
  $values = $this
    ->getSearchTestValues();

  /** @var \Drupal\search_api_autocomplete\SearchInterface $search */
  $search = Search::create($values);
  $search
    ->save();
  $this
    ->assertInstanceOf(SearchInterface::class, $search);
  $this
    ->assertEquals($values['id'], $search
    ->id());
  $this
    ->assertEquals($values['label'], $search
    ->label());
  $this
    ->assertEquals($values['index_id'], $search
    ->getIndexId());
  $actual = $search
    ->getSuggesterIds();
  $this
    ->assertEquals(array_keys($values['suggester_settings']), $actual);
  $actual = $search
    ->getSuggester('server')
    ->getConfiguration();
  $this
    ->assertEquals($values['suggester_settings']['server'], $actual);
  $actual = $search
    ->getSuggesterWeights();
  $this
    ->assertEquals($values['suggester_weights'], $actual);
  $actual = $search
    ->getSuggesterLimits();
  $this
    ->assertEquals($values['suggester_limits'], $actual);
  $this
    ->assertEquals('search_api_autocomplete_test', $search
    ->getSearchPluginId());
  $actual = $search
    ->getSearchPlugin()
    ->getConfiguration();
  $this
    ->assertEquals($values['search_settings']['search_api_autocomplete_test'], $actual);
  $this
    ->assertEquals($values['options'], $search
    ->getOptions());
  $expected = [
    'config' => [
      'search_api.index.autocomplete_search_index',
      'search_api.server.server',
    ],
    'module' => [
      'search_api_autocomplete',
      'search_api_autocomplete_test',
      'user',
    ],
  ];
  $dependencies = $search
    ->getDependencies();
  ksort($dependencies);
  sort($dependencies['config']);
  sort($dependencies['module']);
  $this
    ->assertEquals($expected, $dependencies);
}