UserRegistrationPasswordMailNotifyTest.php in User registration password 8
File
tests/src/Kernel/UserRegistrationPasswordMailNotifyTest.php
View source
<?php
namespace Drupal\Tests\user_registrationpassword\Kernel;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
class UserRegistrationPasswordMailNotifyTest extends EntityKernelTestBase {
use AssertMailTrait {
getMails as drupalGetMails;
}
public static $modules = [
'user_registrationpassword',
];
public function userRegistrationMailsProvider() {
return [
[
'register_confirmation_with_pass',
[
'register_confirmation_with_pass',
],
],
];
}
public function testUserRegistrationMailsSent($op, array $mail_keys) {
$this
->config('user_registrationpassword.settings')
->set('notify.' . $op, 1)
->save();
$edit = [];
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$edit['pass'] = user_password();
$edit['status'] = 0;
$account = $this
->createUser($edit);
$return = _user_registrationpassword_mail_notify($op, $account);
$this
->assertTrue($return, '_user_registrationpassword_mail_notify() returns TRUE.');
foreach ($mail_keys as $key) {
$filter = [
'key' => $key,
];
$this
->assertNotEmpty($this
->getMails($filter), "Mails with {$key} exists.");
}
$this
->assertCount(count($mail_keys), $this
->getMails(), 'The expected number of emails sent.');
}
}