You are here

public function SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternPlaceholders in SMS Framework 2.x

Same name and namespace in other branches
  1. 8 modules/sms_user/tests/src/Kernel/SmsFrameworkUserAccountRegistrationServiceTest.php \Drupal\Tests\sms_user\Kernel\SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternPlaceholders()
  2. 2.1.x modules/sms_user/tests/src/Kernel/SmsFrameworkUserAccountRegistrationServiceTest.php \Drupal\Tests\sms_user\Kernel\SmsFrameworkUserAccountRegistrationServiceTest::testIncomingPatternPlaceholders()

Test all placeholders make their way into the user object.

File

modules/sms_user/tests/src/Kernel/SmsFrameworkUserAccountRegistrationServiceTest.php, line 248

Class

SmsFrameworkUserAccountRegistrationServiceTest
Tests account registration.

Namespace

Drupal\Tests\sms_user\Kernel

Code

public function testIncomingPatternPlaceholders() {
  $this
    ->config('sms_user.settings')
    ->set('account_registration.incoming_pattern.status', 1)
    ->set('account_registration.incoming_pattern.reply.status', 1)
    ->set('account_registration.incoming_pattern.incoming_messages.0', "[email] [username] [password]")
    ->save();
  $email = 'email@domain.tld';
  $username = $this
    ->randomMachineName();
  $password = $this
    ->randomMachineName();
  $message = "{$email} {$username} {$password}";
  $this
    ->sendIncomingMessage('+123123123', $message);
  $user = $this
    ->getLastUser();
  $this
    ->assertEquals($email, $user
    ->getEmail());
  $this
    ->assertEquals($username, $user
    ->getAccountName());

  // Ensure password is correct:

  /** @var \Drupal\user\UserAuthInterface $userAuth */
  $userAuth = \Drupal::service('user.auth');
  $this
    ->assertNotFalse($userAuth
    ->authenticate($username, $password));
}