You are here

public function SavedSearchCrudTest::testIndexDelete in Search API Saved Searches 8

Tests the correct reaction to the deletion of a search index.

File

tests/src/Kernel/SavedSearchCrudTest.php, line 359

Class

SavedSearchCrudTest
Tests CRUD functionality for saved searches.

Namespace

Drupal\Tests\search_api_saved_searches\Kernel

Code

public function testIndexDelete() {
  $index_id = 'test';
  $index = Index::create([
    'id' => $index_id,
  ]);

  // Act as if the index was already saved, to make things easier.
  $index
    ->enforceIsNew(FALSE);
  $search = SavedSearch::create([
    'type' => 'default',
    'index_id' => $index_id,
  ]);
  $search
    ->save();

  // Verify that the search can be loaded.
  $search = SavedSearch::load($search
    ->id());
  $this
    ->assertNotNull($search);
  $index
    ->delete();

  // Verify that the search was deleted.
  $search = SavedSearch::load($search
    ->id());
  $this
    ->assertNull($search);
}