You are here

protected function UserCrudReactionTest::setUp in Search API Saved Searches 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/UserCrudReactionTest.php, line 46

Class

UserCrudReactionTest
Verifies that the module reacts correctly to user CRUD operations.

Namespace

Drupal\Tests\search_api_saved_searches\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installConfig('search_api_saved_searches');
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('search_api_saved_search');
  $this
    ->installEntitySchema('search_api_task');
  $this
    ->installSchema('system', [
    'key_value_expire',
    'sequences',
  ]);
  $this
    ->installSchema('user', [
    'users_data',
  ]);
  $this
    ->installSchema('search_api_saved_searches', 'search_api_saved_searches_old_results');

  // Add a test user that will become the owner of our saved searches.
  $this->testUser = User::create([
    'uid' => 5,
    'name' => 'test',
    'status' => TRUE,
    'mail' => 'test@example.com',
  ]);
  $this->testUser
    ->save();

  // Add a saved search for that user.
  $this->savedSearches[] = SavedSearch::create([
    'type' => 'default',
    'uid' => $this->testUser
      ->id(),
    'status' => TRUE,
    'notify_interval' => 3600 * 24,
    'mail' => $this->testUser
      ->getEmail(),
  ]);

  // Add some anonymously created saved searches.
  $this->savedSearches[] = SavedSearch::create([
    'type' => 'default',
    'uid' => 0,
    'status' => TRUE,
    'notify_interval' => 3600 * 24,
    'mail' => 'foo@example.com',
  ]);
  $this->savedSearches[] = SavedSearch::create([
    'type' => 'default',
    'uid' => 0,
    'status' => TRUE,
    'notify_interval' => 3600 * 24,
    'mail' => 'foo@example.com',
  ]);
  $this->savedSearches[] = SavedSearch::create([
    'type' => 'default',
    'uid' => 0,
    'status' => TRUE,
    'notify_interval' => 3600 * 24,
    'mail' => 'bar@example.com',
  ]);
  foreach ($this->savedSearches as $search) {
    $search
      ->save();
  }
}