public function UserCrudReactionTest::testUserMailChange in Search API Saved Searches 8
Verifies correct reaction to a user changing their mail address.
Tested on behalf of the "E-Mail" notification plugin.
See also
search_api_saved_searches_user_update()
_search_api_saved_searches_adapt_mail()
\Drupal\search_api_saved_searches\Plugin\search_api_saved_searches\notification\Email
File
- tests/
src/ Kernel/ UserCrudReactionTest.php, line 234
Class
- UserCrudReactionTest
- Verifies that the module reacts correctly to user CRUD operations.
Namespace
Drupal\Tests\search_api_saved_searches\KernelCode
public function testUserMailChange() {
// Add a second saved search type that doesn't use the "E-Mail" notification
// plugin.
SavedSearchType::create([
'id' => 'non_default',
'status' => TRUE,
'label' => 'Non-default',
])
->save();
// Add a saved search for the test user using a different mail address.
$this->savedSearches[] = SavedSearch::create([
'type' => 'default',
'uid' => $this->testUser
->id(),
'status' => TRUE,
'notify_interval' => 3600 * 24,
'mail' => 'foobar@example.com',
]);
end($this->savedSearches)
->save();
// Add a saved search with a different type.
$this->savedSearches[] = SavedSearch::create([
'type' => 'non_default',
'uid' => $this->testUser
->id(),
'status' => TRUE,
'notify_interval' => 3600 * 24,
]);
end($this->savedSearches)
->save();
// Now change the user's e-mail address and see what happens.
$this->testUser
->setEmail('test@example.net')
->save();
$this
->reloadSavedSearches();
$this
->assertEquals('test@example.net', $this->savedSearches[0]
->get('mail')->value);
$this
->assertEquals('foobar@example.com', $this->savedSearches[4]
->get('mail')->value);
}