email_registration.test 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @file
  4. * Contains EmailRegistrationTestCase.
  5. */
  6. class EmailRegistrationTestCase extends DrupalWebTestCase {
  7. /**
  8. * Implementation of getInfo().
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => t('Email registration.'),
  13. 'description' => t('Test the email registration module.'),
  14. 'group' => t('Email registration'),
  15. );
  16. }
  17. /**
  18. * Implementation of setUp().
  19. */
  20. public function setUp() {
  21. parent::setUp('email_registration');
  22. // Configure to allow set password.
  23. variable_set('user_email_verification', FALSE);
  24. }
  25. /**
  26. * Test various behaviors for anonymous users.
  27. */
  28. public function testRegistration() {
  29. variable_set('user_register', USER_REGISTER_VISITORS);
  30. // Try to register a user.
  31. $name = $this->randomName();
  32. $pass = $this->randomName(10);
  33. $register = array(
  34. 'mail' => $name . '@example.com',
  35. 'pass[pass1]' => $pass,
  36. 'pass[pass2]' => $pass,
  37. );
  38. $this->drupalPost('/user/register', $register, t('Create new account'));
  39. $this->drupalLogout();
  40. $login = array(
  41. 'name' => $name . '@example.com',
  42. 'pass' => $pass,
  43. );
  44. $this->drupalPost('user/login', $login, t('Log in'));
  45. // Get the uid.
  46. $accounts = user_load_multiple(array(), array('mail' => $name . '@example.com'));
  47. $new_user = reset($accounts);
  48. // Confirm the user was created and logged in with expected username.
  49. $this->assertRaw('<title>' . $name . '_' . $new_user->uid . ' | Drupal</title>', t('User properly created, logged in.'));
  50. // Now try the immediate login.
  51. $this->drupalLogout();
  52. variable_set('user_email_verification', 0);
  53. $name = $this->randomName();
  54. $pass = $this->randomName(10);
  55. $register = array(
  56. 'mail' => $name . '@example.com',
  57. 'pass[pass1]' => $pass,
  58. 'pass[pass2]' => $pass,
  59. );
  60. $this->drupalPost('/user/register', $register, t('Create new account'));
  61. $this->assertRaw('Registration successful. You are now logged in.', t('User properly created, immediately logged in.'));
  62. }
  63. }