email_registration.test 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @file
  4. * Contains EmailRegistrationTestCase.
  5. */
  6. class EmailRegistrationTestCase extends DrupalWebTestCase {
  7. /**
  8. * Implement getInfo().
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Email registration.',
  13. 'description' => 'Test the email registration module.',
  14. 'group' => 'Email registration',
  15. );
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function setUp() {
  21. parent::setUp('email_registration');
  22. // Allow user registration.
  23. variable_set('user_register', USER_REGISTER_VISITORS);
  24. // Configure to allow set password.
  25. variable_set('user_email_verification', FALSE);
  26. }
  27. /**
  28. * Test various behaviors for anonymous users.
  29. */
  30. public function testRegistration() {
  31. // Try to register a user.
  32. $name = $this->randomName();
  33. $pass = $this->randomName(10);
  34. $register = array(
  35. 'mail' => $name . '@example.com',
  36. 'pass[pass1]' => $pass,
  37. 'pass[pass2]' => $pass,
  38. );
  39. $this->drupalPost('/user/register', $register, t('Create new account'));
  40. $this->drupalLogout();
  41. $login = array(
  42. 'name' => $name . '@example.com',
  43. 'pass' => $pass,
  44. );
  45. $this->drupalPost('user/login', $login, t('Log in'));
  46. // Get the account to get uid.
  47. $new_user = user_load_by_mail($name . '@example.com');
  48. $new_name = $name . '_' . $new_user->uid;
  49. // Confirm the user was created and logged in with expected username.
  50. $this->assertTitle($new_name . ' | Drupal', 'User properly created, logged in.');
  51. // Now try the immediate login.
  52. $this->drupalLogout();
  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.', 'User properly created, immediately logged in.');
  62. // Try to login with just username, should succeed by default.
  63. $this->drupalLogout();
  64. // User name appended with UID see email_registration_cleanup_username().
  65. $new_user = user_load_by_mail($name . '@example.com');
  66. $new_name = $name . '_' . $new_user->uid;
  67. $login = array(
  68. 'name' => $new_name,
  69. 'pass' => $pass,
  70. );
  71. $this->drupalPost('user/login', $login, t('Log in'));
  72. $this->assertTitle($new_name . ' | Drupal', 'By default, username can log in.');
  73. $this->drupalLogout();
  74. // Disallow logins with username and try to login with just username, should fail.
  75. variable_set('email_registration_login_with_username', FALSE);
  76. $this->drupalPost('user/login', $login, t('Log in'));
  77. $this->assertTitle('User account | Drupal', 'When disabled, a user cannot login with just their username.');
  78. }
  79. }