You are here

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

Overrides KernelTestBase::setUp

File

tests/src/Kernel/EmailActivationTest.php, line 48

Class

EmailActivationTest
Tests whether activation mails are sent correctly.

Namespace

Drupal\Tests\search_api_saved_searches\Kernel

Code

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

  // Create user accounts.
  $this->users[0] = User::create([
    'uid' => 0,
    'name' => '',
  ]);
  $this->users[0]
    ->save();
  $this->users[1] = $this
    ->createUser([
    SavedSearchAccessControlHandler::ADMIN_PERMISSION,
  ]);
  $this->users[2] = $this
    ->createUser();

  // Use the state system collector mail backend.
  $this
    ->config('system.mail')
    ->set('interface.default', 'test_mail_collector')
    ->save();

  // Set some more site settings used in the test.
  $this
    ->config('system.site')
    ->set('name', 'Saved Searches Test')
    ->set('mail', 'admin@example.net')
    ->save();
  $this
    ->config('user.settings')
    ->set('anonymous', 'Chuck Norris')
    ->save();

  // Add proper activation mail title and body to the default saved search
  // type.
  $title = '[user:display-name], activate your saved search "[search-api-saved-search:label]" at [site:name]';
  $body = <<<END
[user:display-name],

A saved search on [site:name] with this e-mail address was created.
To activate this saved search, click the following link:

[search-api-saved-search:activate-url]
[foo:bar]

--  [site:name] team
END;
  $type = SavedSearchType::load('default');
  $type
    ->getNotificationPlugin('email')
    ->setConfiguration([
    'activate' => [
      'send' => TRUE,
      'title' => $title,
      'body' => $body,
    ],
  ]);
  $type
    ->save();

  // Report all log messages as errors.
  $logger = new TestLogger('');
  $this->container
    ->set('logger.factory', $logger);
  $this->container
    ->set('logger.channel.search_api_saved_searches', $logger);
}