You are here

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

Tests the correct deletion of saved searches.

@covers ::postDelete

File

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

Class

SavedSearchCrudTest
Tests CRUD functionality for saved searches.

Namespace

Drupal\Tests\search_api_saved_searches\Kernel

Code

public function testPostDelete() {
  $search = SavedSearch::create([
    'type' => 'default',
  ]);
  $search
    ->save();
  \Drupal::database()
    ->insert('search_api_saved_searches_old_results')
    ->fields([
    'search_id' => $search
      ->id(),
    'search_type' => 'default',
    'item_id' => '1',
  ])
    ->execute();

  // Verify that the result was inserted.
  $count = \Drupal::database()
    ->select('search_api_saved_searches_old_results', 't')
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEquals(1, $count);
  $search
    ->delete();

  // Verify that the search can't be loaded anymore.
  $search = SavedSearch::load($search
    ->id());
  $this
    ->assertNull($search);

  // Verify that the saved result was deleted.
  $count = \Drupal::database()
    ->select('search_api_saved_searches_old_results', 't')
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEquals(0, $count);
}