You are here

protected function EmailTest::registerWithAlreadyExistingEmail in Apigee Edge 8

Tests user registration with email that already exists in Apigee Edge.

1 call to EmailTest::registerWithAlreadyExistingEmail()
EmailTest::testEmailValidator in tests/src/Functional/EmailTest.php
Tests developer email already exists in Apigee Edge.

File

tests/src/Functional/EmailTest.php, line 121

Class

EmailTest
Developer email already exists in Apigee Edge related tests.

Namespace

Drupal\Tests\apigee_edge\Functional

Code

protected function registerWithAlreadyExistingEmail() {
  $user_register_path = Url::fromRoute('user.register')
    ->toString();
  $developer_settings_path = Url::fromRoute('apigee_edge.settings.developer')
    ->toString();
  $edit = [
    'name' => $this->developer
      ->getUserName(),
    'mail' => $this->developer
      ->getEmail(),
    'first_name[0][value]' => $this->developer
      ->getFirstName(),
    'last_name[0][value]' => $this->developer
      ->getLastName(),
  ];

  // Display only an error message to the user.
  $this
    ->drupalLogin($this->rootUser);
  $error_message = trim($this
    ->getRandomGenerator()
    ->paragraphs(1));
  $this
    ->drupalPostForm($developer_settings_path, [
    'verification_action' => DeveloperSettingsForm::VERIFICATION_ACTION_DISPLAY_ERROR_ONLY,
    'display_only_error_message_content[value]' => $error_message,
  ], 'Save configuration');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');
  $this
    ->drupalLogout();
  $this
    ->drupalPostForm($user_register_path, $edit, 'Create new account');
  $this
    ->assertSession()
    ->pageTextContains($error_message);

  // Display an error message and send a verification email to the user.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalPostForm($developer_settings_path, [
    'verification_action' => DeveloperSettingsForm::VERIFICATION_ACTION_VERIFY_EMAIL,
  ], 'Save configuration');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');
  $this
    ->drupalLogout();
  $this
    ->drupalPostForm($user_register_path, $edit, 'Create new account');
  $this
    ->assertSession()
    ->pageTextContains("This email address already exists in our system. We have sent you an verification email to {$this->developer->getEmail()}.");
  $this
    ->assertMail('id', 'apigee_edge_developer_email_verification');
  $this
    ->assertMail('to', $this->developer
    ->getEmail());
  $mails = $this
    ->getMails();
  $mail = end($mails);
  $matches = [];
  preg_match('%https?://[^/]+/user/register\\?[^/\\s]+%', $mail['body'], $matches);
  $link = $matches[0];
  $this
    ->drupalPostForm($link, $edit, 'Create new account');
  $this
    ->assertSession()
    ->pageTextContains('A welcome message with further instructions has been sent to your email address.');
}