Révision b0dc3a2e
Ajouté par Julien Enselme il y a plus de 7 ans
drupal7/modules/user/user.test | ||
---|---|---|
480 | 480 |
$this->assertText(t('Further instructions have been sent to your e-mail address.'), 'Password reset instructions mailed message displayed.'); |
481 | 481 |
} |
482 | 482 |
|
483 |
/** |
|
484 |
* Test user password reset while logged in. |
|
485 |
*/ |
|
486 |
function testUserPasswordResetLoggedIn() { |
|
487 |
$account = $this->drupalCreateUser(); |
|
488 |
$this->drupalLogin($account); |
|
489 |
// Make sure the test account has a valid password. |
|
490 |
user_save($account, array('pass' => user_password())); |
|
491 |
|
|
492 |
// Generate one time login link. |
|
493 |
$reset_url = user_pass_reset_url($account); |
|
494 |
$this->drupalGet($reset_url); |
|
495 |
|
|
496 |
$this->assertText('Reset password'); |
|
497 |
$this->drupalPost(NULL, NULL, t('Log in')); |
|
498 |
|
|
499 |
$this->assertText('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.'); |
|
500 |
|
|
501 |
$pass = user_password(); |
|
502 |
$edit = array( |
|
503 |
'pass[pass1]' => $pass, |
|
504 |
'pass[pass2]' => $pass, |
|
505 |
); |
|
506 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
507 |
|
|
508 |
$this->assertText('The changes have been saved.'); |
|
509 |
} |
|
510 |
|
|
483 | 511 |
/** |
484 | 512 |
* Attempts login using an expired password reset link. |
485 | 513 |
*/ |
... | ... | |
1849 | 1877 |
$this->drupalGet('admin/people'); |
1850 | 1878 |
$this->assertText($edit['name'], 'User found in list of users'); |
1851 | 1879 |
} |
1880 |
|
|
1881 |
// Test that the password '0' is considered a password. |
|
1882 |
$name = $this->randomName(); |
|
1883 |
$edit = array( |
|
1884 |
'name' => $name, |
|
1885 |
'mail' => $name . '@example.com', |
|
1886 |
'pass[pass1]' => 0, |
|
1887 |
'pass[pass2]' => 0, |
|
1888 |
'notify' => FALSE, |
|
1889 |
); |
|
1890 |
$this->drupalPost('admin/people/create', $edit, t('Create new account')); |
|
1891 |
$this->assertText(t('Created a new user account for @name. No e-mail has been sent.', array('@name' => $edit['name'])), 'User created with password 0'); |
|
1892 |
$this->assertNoText('Password field is required'); |
|
1852 | 1893 |
} |
1853 | 1894 |
} |
1854 | 1895 |
|
... | ... | |
1926 | 1967 |
$this->drupalLogin($user1); |
1927 | 1968 |
$this->drupalLogout(); |
1928 | 1969 |
} |
1970 |
|
|
1971 |
/** |
|
1972 |
* Tests setting the password to "0". |
|
1973 |
*/ |
|
1974 |
public function testUserWith0Password() { |
|
1975 |
$admin = $this->drupalCreateUser(array('administer users')); |
|
1976 |
$this->drupalLogin($admin); |
|
1977 |
// Create a regular user. |
|
1978 |
$user1 = $this->drupalCreateUser(array()); |
|
1979 |
|
|
1980 |
$edit = array('pass[pass1]' => '0', 'pass[pass2]' => '0'); |
|
1981 |
$this->drupalPost("user/" . $user1->uid . "/edit", $edit, t('Save')); |
|
1982 |
$this->assertRaw(t("The changes have been saved.")); |
|
1983 |
|
|
1984 |
$this->drupalLogout(); |
|
1985 |
$user1->pass_raw = '0'; |
|
1986 |
$this->drupalLogin($user1); |
|
1987 |
$this->drupalLogout(); |
|
1988 |
} |
|
1989 |
} |
|
1990 |
|
|
1991 |
/** |
|
1992 |
* Tests editing a user account with and without a form rebuild. |
|
1993 |
*/ |
|
1994 |
class UserEditRebuildTestCase extends DrupalWebTestCase { |
|
1995 |
|
|
1996 |
public static function getInfo() { |
|
1997 |
return array( |
|
1998 |
'name' => 'User edit with form rebuild', |
|
1999 |
'description' => 'Test user edit page when a form rebuild is triggered.', |
|
2000 |
'group' => 'User', |
|
2001 |
); |
|
2002 |
} |
|
2003 |
|
|
2004 |
function setUp() { |
|
2005 |
parent::setUp('user_form_test'); |
|
2006 |
} |
|
2007 |
|
|
2008 |
/** |
|
2009 |
* Test user edit page when the form is set to rebuild. |
|
2010 |
*/ |
|
2011 |
function testUserEditFormRebuild() { |
|
2012 |
$user1 = $this->drupalCreateUser(array('change own username')); |
|
2013 |
$this->drupalLogin($user1); |
|
2014 |
|
|
2015 |
$roles = array_keys($user1->roles); |
|
2016 |
// Save the user form twice. |
|
2017 |
$edit = array(); |
|
2018 |
$edit['current_pass'] = $user1->pass_raw; |
|
2019 |
$this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); |
|
2020 |
$this->assertRaw(t("The changes have been saved.")); |
|
2021 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
2022 |
$this->assertRaw(t("The changes have been saved.")); |
|
2023 |
$saved_user1 = entity_load_unchanged('user', $user1->uid); |
|
2024 |
$this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.'); |
|
2025 |
$diff = array_diff(array_keys($saved_user1->roles), $roles); |
|
2026 |
$this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles)))); |
|
2027 |
// Set variable that causes the form to be rebuilt in user_form_test.module. |
|
2028 |
variable_set('user_form_test_user_profile_form_rebuild', TRUE); |
|
2029 |
$this->drupalPost("user/$user1->uid/edit", $edit, t('Save')); |
|
2030 |
$this->assertRaw(t("The changes have been saved.")); |
|
2031 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
2032 |
$this->assertRaw(t("The changes have been saved.")); |
|
2033 |
$saved_user1 = entity_load_unchanged('user', $user1->uid); |
|
2034 |
$this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.'); |
|
2035 |
$diff = array_diff(array_keys($saved_user1->roles), $roles); |
|
2036 |
$this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles)))); |
|
2037 |
} |
|
1929 | 2038 |
} |
1930 | 2039 |
|
1931 | 2040 |
/** |
Formats disponibles : Unified diff
Update to Drupal 7.52