You are here

public function ProtectedNodeMail::testRandomPassword in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x tests/protected_node.mail_test.test \ProtectedNodeMail::testRandomPassword()

Test that a random password is created and saved when sending an email.

File

tests/protected_node.mail_test.test, line 68
Test protected node email functionality.

Class

ProtectedNodeMail
Configure protected_node to send email.

Code

public function testRandomPassword() {

  // Log in as Admin.
  $this
    ->drupalLogin($this->adminUser);

  // Don't set a password.
  $password = '';

  // To parameter.
  $to = 'example@example.com';

  // Create a new page node.
  $node = $this
    ->createProtectedNode($password, $to);

  // Once the node created logout the User.
  $this
    ->drupalLogout();

  // Check that a password has been generated.
  $generated_password = $node->protected_node_passwd;
  $this
    ->assertTrue(!empty($generated_password), "Generated password exists.");
  $mails = $this
    ->drupalGetMails();

  // Check that the default mail body contains the password.
  $generated_password_in_mail = FALSE;
  $clear_password = $mails[0]['params']['node']->protected_node_clear_passwd;
  if (strpos($mails[0]['body'], $clear_password)) {
    $generated_password_in_mail = TRUE;
  }
  $this
    ->assertTrue($generated_password_in_mail, "The mail's body contains the randomly generated password.", $this->group);
}