user.test.orig 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574
  1. <?php
  2. /**
  3. * @file
  4. * Tests for user.module.
  5. */
  6. class UserRegistrationTestCase extends DrupalWebTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'User registration',
  10. 'description' => 'Test registration of user under different configurations.',
  11. 'group' => 'User'
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('field_test');
  16. }
  17. function testRegistrationWithEmailVerification() {
  18. // Require e-mail verification.
  19. variable_set('user_email_verification', TRUE);
  20. // Set registration to administrator only.
  21. variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
  22. $this->drupalGet('user/register');
  23. $this->assertResponse(403, 'Registration page is inaccessible when only administrators can create accounts.');
  24. // Allow registration by site visitors without administrator approval.
  25. variable_set('user_register', USER_REGISTER_VISITORS);
  26. $edit = array();
  27. $edit['name'] = $name = $this->randomName();
  28. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  29. $this->drupalPost('user/register', $edit, t('Create new account'));
  30. $this->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), 'User registered successfully.');
  31. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  32. $new_user = reset($accounts);
  33. $this->assertTrue($new_user->status, 'New account is active after registration.');
  34. // Allow registration by site visitors, but require administrator approval.
  35. variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
  36. $edit = array();
  37. $edit['name'] = $name = $this->randomName();
  38. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  39. $this->drupalPost('user/register', $edit, t('Create new account'));
  40. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  41. $new_user = reset($accounts);
  42. $this->assertFalse($new_user->status, 'New account is blocked until approved by an administrator.');
  43. }
  44. function testRegistrationWithoutEmailVerification() {
  45. // Don't require e-mail verification.
  46. variable_set('user_email_verification', FALSE);
  47. // Allow registration by site visitors without administrator approval.
  48. variable_set('user_register', USER_REGISTER_VISITORS);
  49. $edit = array();
  50. $edit['name'] = $name = $this->randomName();
  51. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  52. // Try entering a mismatching password.
  53. $edit['pass[pass1]'] = '99999.0';
  54. $edit['pass[pass2]'] = '99999';
  55. $this->drupalPost('user/register', $edit, t('Create new account'));
  56. $this->assertText(t('The specified passwords do not match.'), 'Typing mismatched passwords displays an error message.');
  57. // Enter a correct password.
  58. $edit['pass[pass1]'] = $new_pass = $this->randomName();
  59. $edit['pass[pass2]'] = $new_pass;
  60. $this->drupalPost('user/register', $edit, t('Create new account'));
  61. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  62. $new_user = reset($accounts);
  63. $this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.');
  64. $this->drupalLogout();
  65. // Allow registration by site visitors, but require administrator approval.
  66. variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
  67. $edit = array();
  68. $edit['name'] = $name = $this->randomName();
  69. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  70. $edit['pass[pass1]'] = $pass = $this->randomName();
  71. $edit['pass[pass2]'] = $pass;
  72. $this->drupalPost('user/register', $edit, t('Create new account'));
  73. $this->assertText(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'), 'Users are notified of pending approval');
  74. // Try to login before administrator approval.
  75. $auth = array(
  76. 'name' => $name,
  77. 'pass' => $pass,
  78. );
  79. $this->drupalPost('user/login', $auth, t('Log in'));
  80. $this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), 'User cannot login yet.');
  81. // Activate the new account.
  82. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  83. $new_user = reset($accounts);
  84. $admin_user = $this->drupalCreateUser(array('administer users'));
  85. $this->drupalLogin($admin_user);
  86. $edit = array(
  87. 'status' => 1,
  88. );
  89. $this->drupalPost('user/' . $new_user->uid . '/edit', $edit, t('Save'));
  90. $this->drupalLogout();
  91. // Login after administrator approval.
  92. $this->drupalPost('user/login', $auth, t('Log in'));
  93. $this->assertText(t('Member for'), 'User can log in after administrator approval.');
  94. }
  95. function testRegistrationEmailDuplicates() {
  96. // Don't require e-mail verification.
  97. variable_set('user_email_verification', FALSE);
  98. // Allow registration by site visitors without administrator approval.
  99. variable_set('user_register', USER_REGISTER_VISITORS);
  100. // Set up a user to check for duplicates.
  101. $duplicate_user = $this->drupalCreateUser();
  102. $edit = array();
  103. $edit['name'] = $this->randomName();
  104. $edit['mail'] = $duplicate_user->mail;
  105. // Attempt to create a new account using an existing e-mail address.
  106. $this->drupalPost('user/register', $edit, t('Create new account'));
  107. $this->assertText(t('The e-mail address @email is already registered.', array('@email' => $duplicate_user->mail)), 'Supplying an exact duplicate email address displays an error message');
  108. // Attempt to bypass duplicate email registration validation by adding spaces.
  109. $edit['mail'] = ' ' . $duplicate_user->mail . ' ';
  110. $this->drupalPost('user/register', $edit, t('Create new account'));
  111. $this->assertText(t('The e-mail address @email is already registered.', array('@email' => $duplicate_user->mail)), 'Supplying a duplicate email address with added whitespace displays an error message');
  112. }
  113. function testRegistrationDefaultValues() {
  114. // Allow registration by site visitors without administrator approval.
  115. variable_set('user_register', USER_REGISTER_VISITORS);
  116. // Don't require e-mail verification.
  117. variable_set('user_email_verification', FALSE);
  118. // Set the default timezone to Brussels.
  119. variable_set('configurable_timezones', 1);
  120. variable_set('date_default_timezone', 'Europe/Brussels');
  121. // Check that the account information fieldset's options are not displayed
  122. // is a fieldset if there is not more than one fieldset in the form.
  123. $this->drupalGet('user/register');
  124. $this->assertNoRaw('<fieldset id="edit-account"><legend>Account information</legend>', 'Account settings fieldset was hidden.');
  125. $edit = array();
  126. $edit['name'] = $name = $this->randomName();
  127. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  128. $edit['pass[pass1]'] = $new_pass = $this->randomName();
  129. $edit['pass[pass2]'] = $new_pass;
  130. $this->drupalPost(NULL, $edit, t('Create new account'));
  131. // Check user fields.
  132. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  133. $new_user = reset($accounts);
  134. $this->assertEqual($new_user->name, $name, 'Username matches.');
  135. $this->assertEqual($new_user->mail, $mail, 'E-mail address matches.');
  136. $this->assertEqual($new_user->theme, '', 'Correct theme field.');
  137. $this->assertEqual($new_user->signature, '', 'Correct signature field.');
  138. $this->assertTrue(($new_user->created > REQUEST_TIME - 20 ), 'Correct creation time.');
  139. $this->assertEqual($new_user->status, variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
  140. $this->assertEqual($new_user->timezone, variable_get('date_default_timezone'), 'Correct time zone field.');
  141. $this->assertEqual($new_user->language, '', 'Correct language field.');
  142. $this->assertEqual($new_user->picture, '', 'Correct picture field.');
  143. $this->assertEqual($new_user->init, $mail, 'Correct init field.');
  144. }
  145. /**
  146. * Tests Field API fields on user registration forms.
  147. */
  148. function testRegistrationWithUserFields() {
  149. // Create a field, and an instance on 'user' entity type.
  150. $field = array(
  151. 'type' => 'test_field',
  152. 'field_name' => 'test_user_field',
  153. 'cardinality' => 1,
  154. );
  155. field_create_field($field);
  156. $instance = array(
  157. 'field_name' => 'test_user_field',
  158. 'entity_type' => 'user',
  159. 'label' => 'Some user field',
  160. 'bundle' => 'user',
  161. 'required' => TRUE,
  162. 'settings' => array('user_register_form' => FALSE),
  163. );
  164. field_create_instance($instance);
  165. // Check that the field does not appear on the registration form.
  166. $this->drupalGet('user/register');
  167. $this->assertNoText($instance['label'], 'The field does not appear on user registration form');
  168. // Have the field appear on the registration form.
  169. $instance['settings']['user_register_form'] = TRUE;
  170. field_update_instance($instance);
  171. $this->drupalGet('user/register');
  172. $this->assertText($instance['label'], 'The field appears on user registration form');
  173. // Check that validation errors are correctly reported.
  174. $edit = array();
  175. $edit['name'] = $name = $this->randomName();
  176. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  177. // Missing input in required field.
  178. $edit['test_user_field[und][0][value]'] = '';
  179. $this->drupalPost(NULL, $edit, t('Create new account'));
  180. $this->assertRaw(t('@name field is required.', array('@name' => $instance['label'])), 'Field validation error was correctly reported.');
  181. // Invalid input.
  182. $edit['test_user_field[und][0][value]'] = '-1';
  183. $this->drupalPost(NULL, $edit, t('Create new account'));
  184. $this->assertRaw(t('%name does not accept the value -1.', array('%name' => $instance['label'])), 'Field validation error was correctly reported.');
  185. // Submit with valid data.
  186. $value = rand(1, 255);
  187. $edit['test_user_field[und][0][value]'] = $value;
  188. $this->drupalPost(NULL, $edit, t('Create new account'));
  189. // Check user fields.
  190. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  191. $new_user = reset($accounts);
  192. $this->assertEqual($new_user->test_user_field[LANGUAGE_NONE][0]['value'], $value, 'The field value was correctly saved.');
  193. // Check that the 'add more' button works.
  194. $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
  195. field_update_field($field);
  196. foreach (array('js', 'nojs') as $js) {
  197. $this->drupalGet('user/register');
  198. // Add two inputs.
  199. $value = rand(1, 255);
  200. $edit = array();
  201. $edit['test_user_field[und][0][value]'] = $value;
  202. if ($js == 'js') {
  203. $this->drupalPostAJAX(NULL, $edit, 'test_user_field_add_more');
  204. $this->drupalPostAJAX(NULL, $edit, 'test_user_field_add_more');
  205. }
  206. else {
  207. $this->drupalPost(NULL, $edit, t('Add another item'));
  208. $this->drupalPost(NULL, $edit, t('Add another item'));
  209. }
  210. // Submit with three values.
  211. $edit['test_user_field[und][1][value]'] = $value + 1;
  212. $edit['test_user_field[und][2][value]'] = $value + 2;
  213. $edit['name'] = $name = $this->randomName();
  214. $edit['mail'] = $mail = $edit['name'] . '@example.com';
  215. $this->drupalPost(NULL, $edit, t('Create new account'));
  216. // Check user fields.
  217. $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  218. $new_user = reset($accounts);
  219. $this->assertEqual($new_user->test_user_field[LANGUAGE_NONE][0]['value'], $value, format_string('@js : The field value was correclty saved.', array('@js' => $js)));
  220. $this->assertEqual($new_user->test_user_field[LANGUAGE_NONE][1]['value'], $value + 1, format_string('@js : The field value was correclty saved.', array('@js' => $js)));
  221. $this->assertEqual($new_user->test_user_field[LANGUAGE_NONE][2]['value'], $value + 2, format_string('@js : The field value was correclty saved.', array('@js' => $js)));
  222. }
  223. }
  224. }
  225. class UserValidationTestCase extends DrupalWebTestCase {
  226. public static function getInfo() {
  227. return array(
  228. 'name' => 'Username/e-mail validation',
  229. 'description' => 'Verify that username/email validity checks behave as designed.',
  230. 'group' => 'User'
  231. );
  232. }
  233. // Username validation.
  234. function testUsernames() {
  235. $test_cases = array( // '<username>' => array('<description>', 'assert<testName>'),
  236. 'foo' => array('Valid username', 'assertNull'),
  237. 'FOO' => array('Valid username', 'assertNull'),
  238. 'Foo O\'Bar' => array('Valid username', 'assertNull'),
  239. 'foo@bar' => array('Valid username', 'assertNull'),
  240. 'foo@example.com' => array('Valid username', 'assertNull'),
  241. 'foo@-example.com' => array('Valid username', 'assertNull'), // invalid domains are allowed in usernames
  242. 'þòøÇߪř€' => array('Valid username', 'assertNull'),
  243. 'ᚠᛇᚻ᛫ᛒᛦᚦ' => array('Valid UTF8 username', 'assertNull'), // runes
  244. ' foo' => array('Invalid username that starts with a space', 'assertNotNull'),
  245. 'foo ' => array('Invalid username that ends with a space', 'assertNotNull'),
  246. 'foo bar' => array('Invalid username that contains 2 spaces \'&nbsp;&nbsp;\'', 'assertNotNull'),
  247. '' => array('Invalid empty username', 'assertNotNull'),
  248. 'foo/' => array('Invalid username containing invalid chars', 'assertNotNull'),
  249. 'foo' . chr(0) . 'bar' => array('Invalid username containing chr(0)', 'assertNotNull'), // NULL
  250. 'foo' . chr(13) . 'bar' => array('Invalid username containing chr(13)', 'assertNotNull'), // CR
  251. str_repeat('x', USERNAME_MAX_LENGTH + 1) => array('Invalid excessively long username', 'assertNotNull'),
  252. );
  253. foreach ($test_cases as $name => $test_case) {
  254. list($description, $test) = $test_case;
  255. $result = user_validate_name($name);
  256. $this->$test($result, $description . ' (' . $name . ')');
  257. }
  258. }
  259. // Mail validation. More extensive tests can be found at common.test
  260. function testMailAddresses() {
  261. $test_cases = array( // '<username>' => array('<description>', 'assert<testName>'),
  262. '' => array('Empty mail address', 'assertNotNull'),
  263. 'foo' => array('Invalid mail address', 'assertNotNull'),
  264. 'foo@example.com' => array('Valid mail address', 'assertNull'),
  265. );
  266. foreach ($test_cases as $name => $test_case) {
  267. list($description, $test) = $test_case;
  268. $result = user_validate_mail($name);
  269. $this->$test($result, $description . ' (' . $name . ')');
  270. }
  271. }
  272. }
  273. /**
  274. * Functional tests for user logins, including rate limiting of login attempts.
  275. */
  276. class UserLoginTestCase extends DrupalWebTestCase {
  277. public static function getInfo() {
  278. return array(
  279. 'name' => 'User login',
  280. 'description' => 'Ensure that login works as expected.',
  281. 'group' => 'User',
  282. );
  283. }
  284. /**
  285. * Test the global login flood control.
  286. */
  287. function testGlobalLoginFloodControl() {
  288. // Set the global login limit.
  289. variable_set('user_failed_login_ip_limit', 10);
  290. // Set a high per-user limit out so that it is not relevant in the test.
  291. variable_set('user_failed_login_user_limit', 4000);
  292. $user1 = $this->drupalCreateUser(array());
  293. $incorrect_user1 = clone $user1;
  294. $incorrect_user1->pass_raw .= 'incorrect';
  295. // Try 2 failed logins.
  296. for ($i = 0; $i < 2; $i++) {
  297. $this->assertFailedLogin($incorrect_user1);
  298. }
  299. // A successful login will not reset the IP-based flood control count.
  300. $this->drupalLogin($user1);
  301. $this->drupalLogout();
  302. // Try 8 more failed logins, they should not trigger the flood control
  303. // mechanism.
  304. for ($i = 0; $i < 8; $i++) {
  305. $this->assertFailedLogin($incorrect_user1);
  306. }
  307. // The next login trial should result in an IP-based flood error message.
  308. $this->assertFailedLogin($incorrect_user1, 'ip');
  309. // A login with the correct password should also result in a flood error
  310. // message.
  311. $this->assertFailedLogin($user1, 'ip');
  312. }
  313. /**
  314. * Test the per-user login flood control.
  315. */
  316. function testPerUserLoginFloodControl() {
  317. // Set a high global limit out so that it is not relevant in the test.
  318. variable_set('user_failed_login_ip_limit', 4000);
  319. // Set the per-user login limit.
  320. variable_set('user_failed_login_user_limit', 3);
  321. $user1 = $this->drupalCreateUser(array());
  322. $incorrect_user1 = clone $user1;
  323. $incorrect_user1->pass_raw .= 'incorrect';
  324. $user2 = $this->drupalCreateUser(array());
  325. // Try 2 failed logins.
  326. for ($i = 0; $i < 2; $i++) {
  327. $this->assertFailedLogin($incorrect_user1);
  328. }
  329. // A successful login will reset the per-user flood control count.
  330. $this->drupalLogin($user1);
  331. $this->drupalLogout();
  332. // Try 3 failed logins for user 1, they will not trigger flood control.
  333. for ($i = 0; $i < 3; $i++) {
  334. $this->assertFailedLogin($incorrect_user1);
  335. }
  336. // Try one successful attempt for user 2, it should not trigger any
  337. // flood control.
  338. $this->drupalLogin($user2);
  339. $this->drupalLogout();
  340. // Try one more attempt for user 1, it should be rejected, even if the
  341. // correct password has been used.
  342. $this->assertFailedLogin($user1, 'user');
  343. }
  344. /**
  345. * Test that user password is re-hashed upon login after changing $count_log2.
  346. */
  347. function testPasswordRehashOnLogin() {
  348. // Load password hashing API.
  349. require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
  350. // Set initial $count_log2 to the default, DRUPAL_HASH_COUNT.
  351. variable_set('password_count_log2', DRUPAL_HASH_COUNT);
  352. // Create a new user and authenticate.
  353. $account = $this->drupalCreateUser(array());
  354. $password = $account->pass_raw;
  355. $this->drupalLogin($account);
  356. $this->drupalLogout();
  357. // Load the stored user. The password hash should reflect $count_log2.
  358. $account = user_load($account->uid);
  359. $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT);
  360. // Change $count_log2 and log in again.
  361. variable_set('password_count_log2', DRUPAL_HASH_COUNT + 1);
  362. $account->pass_raw = $password;
  363. $this->drupalLogin($account);
  364. // Load the stored user, which should have a different password hash now.
  365. $account = user_load($account->uid, TRUE);
  366. $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT + 1);
  367. }
  368. /**
  369. * Make an unsuccessful login attempt.
  370. *
  371. * @param $account
  372. * A user object with name and pass_raw attributes for the login attempt.
  373. * @param $flood_trigger
  374. * Whether or not to expect that the flood control mechanism will be
  375. * triggered.
  376. */
  377. function assertFailedLogin($account, $flood_trigger = NULL) {
  378. $edit = array(
  379. 'name' => $account->name,
  380. 'pass' => $account->pass_raw,
  381. );
  382. $this->drupalPost('user', $edit, t('Log in'));
  383. $this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.');
  384. if (isset($flood_trigger)) {
  385. if ($flood_trigger == 'user') {
  386. $this->assertRaw(format_plural(variable_get('user_failed_login_user_limit', 5), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
  387. }
  388. else {
  389. // No uid, so the limit is IP-based.
  390. $this->assertRaw(t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
  391. }
  392. }
  393. else {
  394. $this->assertText(t('Sorry, unrecognized username or password. Have you forgotten your password?'));
  395. }
  396. }
  397. }
  398. /**
  399. * Tests resetting a user password.
  400. */
  401. class UserPasswordResetTestCase extends DrupalWebTestCase {
  402. protected $profile = 'standard';
  403. public static function getInfo() {
  404. return array(
  405. 'name' => 'Reset password',
  406. 'description' => 'Ensure that password reset methods work as expected.',
  407. 'group' => 'User',
  408. );
  409. }
  410. /**
  411. * Tests password reset functionality.
  412. */
  413. function testUserPasswordReset() {
  414. // Create a user.
  415. $account = $this->drupalCreateUser();
  416. $this->drupalLogin($account);
  417. $this->drupalLogout();
  418. // Attempt to reset password.
  419. $edit = array('name' => $account->name);
  420. $this->drupalPost('user/password', $edit, t('E-mail new password'));
  421. // Confirm the password reset.
  422. $this->assertText(t('Further instructions have been sent to your e-mail address.'), 'Password reset instructions mailed message displayed.');
  423. }
  424. /**
  425. * Test user password reset while logged in.
  426. */
  427. function testUserPasswordResetLoggedIn() {
  428. $account = $this->drupalCreateUser();
  429. $this->drupalLogin($account);
  430. // Make sure the test account has a valid password.
  431. user_save($account, array('pass' => user_password()));
  432. // Generate one time login link.
  433. $reset_url = user_pass_reset_url($account);
  434. $this->drupalGet($reset_url);
  435. $this->assertText('Reset password');
  436. $this->drupalPost(NULL, NULL, t('Log in'));
  437. $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.');
  438. $pass = user_password();
  439. $edit = array(
  440. 'pass[pass1]' => $pass,
  441. 'pass[pass2]' => $pass,
  442. );
  443. $this->drupalPost(NULL, $edit, t('Save'));
  444. $this->assertText('The changes have been saved.');
  445. }
  446. /**
  447. * Attempts login using an expired password reset link.
  448. */
  449. function testUserPasswordResetExpired() {
  450. // Set password reset timeout variable to 43200 seconds = 12 hours.
  451. $timeout = 43200;
  452. variable_set('user_password_reset_timeout', $timeout);
  453. // Create a user.
  454. $account = $this->drupalCreateUser();
  455. $this->drupalLogin($account);
  456. // Load real user object.
  457. $account = user_load($account->uid, TRUE);
  458. $this->drupalLogout();
  459. // To attempt an expired password reset, create a password reset link as if
  460. // its request time was 60 seconds older than the allowed limit of timeout.
  461. $bogus_timestamp = REQUEST_TIME - variable_get('user_password_reset_timeout', 86400) - 60;
  462. $this->drupalGet("user/reset/$account->uid/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid));
  463. $this->assertText(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'), 'Expired password reset request rejected.');
  464. }
  465. /**
  466. * Prefill the text box on incorrect login via link to password reset page.
  467. */
  468. function testUserPasswordTextboxFilled() {
  469. $this->drupalGet('user/login');
  470. $edit = array(
  471. 'name' => $this->randomName(),
  472. 'pass' => $this->randomName(),
  473. );
  474. $this->drupalPost('user', $edit, t('Log in'));
  475. $this->assertRaw(t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>',
  476. array('@password' => url('user/password', array('query' => array('name' => $edit['name']))))));
  477. unset($edit['pass']);
  478. $this->drupalGet('user/password', array('query' => array('name' => $edit['name'])));
  479. $this->assertFieldByName('name', $edit['name'], 'User name found.');
  480. }
  481. /**
  482. * Make sure that users cannot forge password reset URLs of other users.
  483. */
  484. function testResetImpersonation() {
  485. // Make sure user 1 has a valid password, so it does not interfere with the
  486. // test user accounts that are created below.
  487. $account = user_load(1);
  488. user_save($account, array('pass' => user_password()));
  489. // Create two identical user accounts except for the user name. They must
  490. // have the same empty password, so we can't use $this->drupalCreateUser().
  491. $edit = array();
  492. $edit['name'] = $this->randomName();
  493. $edit['mail'] = $edit['name'] . '@example.com';
  494. $edit['status'] = 1;
  495. $user1 = user_save(drupal_anonymous_user(), $edit);
  496. $edit['name'] = $this->randomName();
  497. $user2 = user_save(drupal_anonymous_user(), $edit);
  498. // The password reset URL must not be valid for the second user when only
  499. // the user ID is changed in the URL.
  500. $reset_url = user_pass_reset_url($user1);
  501. $attack_reset_url = str_replace("user/reset/$user1->uid", "user/reset/$user2->uid", $reset_url);
  502. $this->drupalGet($attack_reset_url);
  503. $this->assertNoText($user2->name, 'The invalid password reset page does not show the user name.');
  504. $this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
  505. $this->assertText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.');
  506. // When legacy code calls user_pass_rehash() without providing the $uid
  507. // parameter, neither password reset URL should be valid since it is
  508. // impossible for the system to determine which user account the token was
  509. // intended for.
  510. $timestamp = REQUEST_TIME;
  511. // Pass an explicit NULL for the $uid parameter of user_pass_rehash()
  512. // rather than not passing it at all, to avoid triggering PHP warnings in
  513. // the test.
  514. $reset_url_token = user_pass_rehash($user1->pass, $timestamp, $user1->login, NULL);
  515. $reset_url = url("user/reset/$user1->uid/$timestamp/$reset_url_token", array('absolute' => TRUE));
  516. $this->drupalGet($reset_url);
  517. $this->assertNoText($user1->name, 'The invalid password reset page does not show the user name.');
  518. $this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
  519. $this->assertText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.');
  520. $attack_reset_url = str_replace("user/reset/$user1->uid", "user/reset/$user2->uid", $reset_url);
  521. $this->drupalGet($attack_reset_url);
  522. $this->assertNoText($user2->name, 'The invalid password reset page does not show the user name.');
  523. $this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
  524. $this->assertText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.');
  525. // To verify that user_pass_rehash() never returns a valid result in the
  526. // above situation (even if legacy code also called it to attempt to
  527. // validate the token, rather than just to generate the URL), check that a
  528. // second call with the same parameters produces a different result.
  529. $new_reset_url_token = user_pass_rehash($user1->pass, $timestamp, $user1->login, NULL);
  530. $this->assertNotEqual($reset_url_token, $new_reset_url_token);
  531. // However, when the duplicate account is removed, the password reset URL
  532. // should be valid.
  533. user_delete($user2->uid);
  534. $reset_url_token = user_pass_rehash($user1->pass, $timestamp, $user1->login, NULL);
  535. $reset_url = url("user/reset/$user1->uid/$timestamp/$reset_url_token", array('absolute' => TRUE));
  536. $this->drupalGet($reset_url);
  537. $this->assertText($user1->name, 'The valid password reset page shows the user name.');
  538. $this->assertUrl($reset_url, array(), 'The user remains on the password reset login page.');
  539. $this->assertNoText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.');
  540. }
  541. }
  542. /**
  543. * Test cancelling a user.
  544. */
  545. class UserCancelTestCase extends DrupalWebTestCase {
  546. public static function getInfo() {
  547. return array(
  548. 'name' => 'Cancel account',
  549. 'description' => 'Ensure that account cancellation methods work as expected.',
  550. 'group' => 'User',
  551. );
  552. }
  553. function setUp() {
  554. parent::setUp('comment');
  555. }
  556. /**
  557. * Attempt to cancel account without permission.
  558. */
  559. function testUserCancelWithoutPermission() {
  560. variable_set('user_cancel_method', 'user_cancel_reassign');
  561. // Create a user.
  562. $account = $this->drupalCreateUser(array());
  563. $this->drupalLogin($account);
  564. // Load real user object.
  565. $account = user_load($account->uid, TRUE);
  566. // Create a node.
  567. $node = $this->drupalCreateNode(array('uid' => $account->uid));
  568. // Attempt to cancel account.
  569. $this->drupalGet('user/' . $account->uid . '/edit');
  570. $this->assertNoRaw(t('Cancel account'), 'No cancel account button displayed.');
  571. // Attempt bogus account cancellation request confirmation.
  572. $timestamp = $account->login;
  573. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  574. $this->assertResponse(403, 'Bogus cancelling request rejected.');
  575. $account = user_load($account->uid);
  576. $this->assertTrue($account->status == 1, 'User account was not canceled.');
  577. // Confirm user's content has not been altered.
  578. $test_node = node_load($node->nid, NULL, TRUE);
  579. $this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), 'Node of the user has not been altered.');
  580. }
  581. /**
  582. * Tests that user account for uid 1 cannot be cancelled.
  583. *
  584. * This should never be possible, or the site owner would become unable to
  585. * administer the site.
  586. */
  587. function testUserCancelUid1() {
  588. // Update uid 1's name and password to we know it.
  589. $password = user_password();
  590. require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
  591. $account = array(
  592. 'name' => 'user1',
  593. 'pass' => user_hash_password(trim($password)),
  594. );
  595. // We cannot use user_save() here or the password would be hashed again.
  596. db_update('users')
  597. ->fields($account)
  598. ->condition('uid', 1)
  599. ->execute();
  600. // Reload and log in uid 1.
  601. $user1 = user_load(1, TRUE);
  602. $user1->pass_raw = $password;
  603. // Try to cancel uid 1's account with a different user.
  604. $this->admin_user = $this->drupalCreateUser(array('administer users'));
  605. $this->drupalLogin($this->admin_user);
  606. $edit = array(
  607. 'operation' => 'cancel',
  608. 'accounts[1]' => TRUE,
  609. );
  610. $this->drupalPost('admin/people', $edit, t('Update'));
  611. // Verify that uid 1's account was not cancelled.
  612. $user1 = user_load(1, TRUE);
  613. $this->assertEqual($user1->status, 1, 'User #1 still exists and is not blocked.');
  614. }
  615. /**
  616. * Attempt invalid account cancellations.
  617. */
  618. function testUserCancelInvalid() {
  619. variable_set('user_cancel_method', 'user_cancel_reassign');
  620. // Create a user.
  621. $account = $this->drupalCreateUser(array('cancel account'));
  622. $this->drupalLogin($account);
  623. // Load real user object.
  624. $account = user_load($account->uid, TRUE);
  625. // Create a node.
  626. $node = $this->drupalCreateNode(array('uid' => $account->uid));
  627. // Attempt to cancel account.
  628. $this->drupalPost('user/' . $account->uid . '/edit', NULL, t('Cancel account'));
  629. // Confirm account cancellation.
  630. $timestamp = time();
  631. $this->drupalPost(NULL, NULL, t('Cancel account'));
  632. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
  633. // Attempt bogus account cancellation request confirmation.
  634. $bogus_timestamp = $timestamp + 60;
  635. $this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid));
  636. $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Bogus cancelling request rejected.');
  637. $account = user_load($account->uid);
  638. $this->assertTrue($account->status == 1, 'User account was not canceled.');
  639. // Attempt expired account cancellation request confirmation.
  640. $bogus_timestamp = $timestamp - 86400 - 60;
  641. $this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid));
  642. $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Expired cancel account request rejected.');
  643. $accounts = user_load_multiple(array($account->uid), array('status' => 1));
  644. $this->assertTrue(reset($accounts), 'User account was not canceled.');
  645. // Confirm user's content has not been altered.
  646. $test_node = node_load($node->nid, NULL, TRUE);
  647. $this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), 'Node of the user has not been altered.');
  648. }
  649. /**
  650. * Disable account and keep all content.
  651. */
  652. function testUserBlock() {
  653. variable_set('user_cancel_method', 'user_cancel_block');
  654. // Create a user.
  655. $web_user = $this->drupalCreateUser(array('cancel account'));
  656. $this->drupalLogin($web_user);
  657. // Load real user object.
  658. $account = user_load($web_user->uid, TRUE);
  659. // Attempt to cancel account.
  660. $this->drupalGet('user/' . $account->uid . '/edit');
  661. $this->drupalPost(NULL, NULL, t('Cancel account'));
  662. $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
  663. $this->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your user name.'), 'Informs that all content will be remain as is.');
  664. $this->assertNoText(t('Select the method to cancel the account above.'), 'Does not allow user to select account cancellation method.');
  665. // Confirm account cancellation.
  666. $timestamp = time();
  667. $this->drupalPost(NULL, NULL, t('Cancel account'));
  668. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
  669. // Confirm account cancellation request.
  670. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  671. $account = user_load($account->uid, TRUE);
  672. $this->assertTrue($account->status == 0, 'User has been blocked.');
  673. // Confirm that the confirmation message made it through to the end user.
  674. $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user.");
  675. }
  676. /**
  677. * Disable account and unpublish all content.
  678. */
  679. function testUserBlockUnpublish() {
  680. variable_set('user_cancel_method', 'user_cancel_block_unpublish');
  681. // Create a user.
  682. $account = $this->drupalCreateUser(array('cancel account'));
  683. $this->drupalLogin($account);
  684. // Load real user object.
  685. $account = user_load($account->uid, TRUE);
  686. // Create a node with two revisions.
  687. $node = $this->drupalCreateNode(array('uid' => $account->uid));
  688. $settings = get_object_vars($node);
  689. $settings['revision'] = 1;
  690. $node = $this->drupalCreateNode($settings);
  691. // Attempt to cancel account.
  692. $this->drupalGet('user/' . $account->uid . '/edit');
  693. $this->drupalPost(NULL, NULL, t('Cancel account'));
  694. $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
  695. $this->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'), 'Informs that all content will be unpublished.');
  696. // Confirm account cancellation.
  697. $timestamp = time();
  698. $this->drupalPost(NULL, NULL, t('Cancel account'));
  699. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
  700. // Confirm account cancellation request.
  701. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  702. $account = user_load($account->uid, TRUE);
  703. $this->assertTrue($account->status == 0, 'User has been blocked.');
  704. // Confirm user's content has been unpublished.
  705. $test_node = node_load($node->nid, NULL, TRUE);
  706. $this->assertTrue($test_node->status == 0, 'Node of the user has been unpublished.');
  707. $test_node = node_load($node->nid, $node->vid, TRUE);
  708. $this->assertTrue($test_node->status == 0, 'Node revision of the user has been unpublished.');
  709. // Confirm that the confirmation message made it through to the end user.
  710. $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user.");
  711. }
  712. /**
  713. * Delete account and anonymize all content.
  714. */
  715. function testUserAnonymize() {
  716. variable_set('user_cancel_method', 'user_cancel_reassign');
  717. // Create a user.
  718. $account = $this->drupalCreateUser(array('cancel account'));
  719. $this->drupalLogin($account);
  720. // Load real user object.
  721. $account = user_load($account->uid, TRUE);
  722. // Create a simple node.
  723. $node = $this->drupalCreateNode(array('uid' => $account->uid));
  724. // Create a node with two revisions, the initial one belonging to the
  725. // cancelling user.
  726. $revision_node = $this->drupalCreateNode(array('uid' => $account->uid));
  727. $revision = $revision_node->vid;
  728. $settings = get_object_vars($revision_node);
  729. $settings['revision'] = 1;
  730. $settings['uid'] = 1; // Set new/current revision to someone else.
  731. $revision_node = $this->drupalCreateNode($settings);
  732. // Attempt to cancel account.
  733. $this->drupalGet('user/' . $account->uid . '/edit');
  734. $this->drupalPost(NULL, NULL, t('Cancel account'));
  735. $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
  736. $this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')))), 'Informs that all content will be attributed to anonymous account.');
  737. // Confirm account cancellation.
  738. $timestamp = time();
  739. $this->drupalPost(NULL, NULL, t('Cancel account'));
  740. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
  741. // Confirm account cancellation request.
  742. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  743. $this->assertFalse(user_load($account->uid, TRUE), 'User is not found in the database.');
  744. // Confirm that user's content has been attributed to anonymous user.
  745. $test_node = node_load($node->nid, NULL, TRUE);
  746. $this->assertTrue(($test_node->uid == 0 && $test_node->status == 1), 'Node of the user has been attributed to anonymous user.');
  747. $test_node = node_load($revision_node->nid, $revision, TRUE);
  748. $this->assertTrue(($test_node->revision_uid == 0 && $test_node->status == 1), 'Node revision of the user has been attributed to anonymous user.');
  749. $test_node = node_load($revision_node->nid, NULL, TRUE);
  750. $this->assertTrue(($test_node->uid != 0 && $test_node->status == 1), "Current revision of the user's node was not attributed to anonymous user.");
  751. // Confirm that the confirmation message made it through to the end user.
  752. $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user.");
  753. }
  754. /**
  755. * Delete account and remove all content.
  756. */
  757. function testUserDelete() {
  758. variable_set('user_cancel_method', 'user_cancel_delete');
  759. // Create a user.
  760. $account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
  761. $this->drupalLogin($account);
  762. // Load real user object.
  763. $account = user_load($account->uid, TRUE);
  764. // Create a simple node.
  765. $node = $this->drupalCreateNode(array('uid' => $account->uid));
  766. // Create comment.
  767. $langcode = LANGUAGE_NONE;
  768. $edit = array();
  769. $edit['subject'] = $this->randomName(8);
  770. $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
  771. $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview'));
  772. $this->drupalPost(NULL, array(), t('Save'));
  773. $this->assertText(t('Your comment has been posted.'));
  774. $comments = comment_load_multiple(array(), array('subject' => $edit['subject']));
  775. $comment = reset($comments);
  776. $this->assertTrue($comment->cid, 'Comment found.');
  777. // Create a node with two revisions, the initial one belonging to the
  778. // cancelling user.
  779. $revision_node = $this->drupalCreateNode(array('uid' => $account->uid));
  780. $revision = $revision_node->vid;
  781. $settings = get_object_vars($revision_node);
  782. $settings['revision'] = 1;
  783. $settings['uid'] = 1; // Set new/current revision to someone else.
  784. $revision_node = $this->drupalCreateNode($settings);
  785. // Attempt to cancel account.
  786. $this->drupalGet('user/' . $account->uid . '/edit');
  787. $this->drupalPost(NULL, NULL, t('Cancel account'));
  788. $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
  789. $this->assertText(t('Your account will be removed and all account information deleted. All of your content will also be deleted.'), 'Informs that all content will be deleted.');
  790. // Confirm account cancellation.
  791. $timestamp = time();
  792. $this->drupalPost(NULL, NULL, t('Cancel account'));
  793. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
  794. // Confirm account cancellation request.
  795. $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  796. $this->assertFalse(user_load($account->uid, TRUE), 'User is not found in the database.');
  797. // Confirm that user's content has been deleted.
  798. $this->assertFalse(node_load($node->nid, NULL, TRUE), 'Node of the user has been deleted.');
  799. $this->assertFalse(node_load($node->nid, $revision, TRUE), 'Node revision of the user has been deleted.');
  800. $this->assertTrue(node_load($revision_node->nid, NULL, TRUE), "Current revision of the user's node was not deleted.");
  801. $this->assertFalse(comment_load($comment->cid), 'Comment of the user has been deleted.');
  802. // Confirm that the confirmation message made it through to the end user.
  803. $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user.");
  804. }
  805. /**
  806. * Create an administrative user and delete another user.
  807. */
  808. function testUserCancelByAdmin() {
  809. variable_set('user_cancel_method', 'user_cancel_reassign');
  810. // Create a regular user.
  811. $account = $this->drupalCreateUser(array());
  812. // Create administrative user.
  813. $admin_user = $this->drupalCreateUser(array('administer users'));
  814. $this->drupalLogin($admin_user);
  815. // Delete regular user.
  816. $this->drupalGet('user/' . $account->uid . '/edit');
  817. $this->drupalPost(NULL, NULL, t('Cancel account'));
  818. $this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->name)), 'Confirmation form to cancel account displayed.');
  819. $this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
  820. // Confirm deletion.
  821. $this->drupalPost(NULL, NULL, t('Cancel account'));
  822. $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), 'User deleted.');
  823. $this->assertFalse(user_load($account->uid), 'User is not found in the database.');
  824. }
  825. /**
  826. * Create an administrative user and mass-delete other users.
  827. */
  828. function testMassUserCancelByAdmin() {
  829. variable_set('user_cancel_method', 'user_cancel_reassign');
  830. // Enable account cancellation notification.
  831. variable_set('user_mail_status_canceled_notify', TRUE);
  832. // Create administrative user.
  833. $admin_user = $this->drupalCreateUser(array('administer users'));
  834. $this->drupalLogin($admin_user);
  835. // Create some users.
  836. $users = array();
  837. for ($i = 0; $i < 3; $i++) {
  838. $account = $this->drupalCreateUser(array());
  839. $users[$account->uid] = $account;
  840. }
  841. // Cancel user accounts, including own one.
  842. $edit = array();
  843. $edit['operation'] = 'cancel';
  844. foreach ($users as $uid => $account) {
  845. $edit['accounts[' . $uid . ']'] = TRUE;
  846. }
  847. $edit['accounts[' . $admin_user->uid . ']'] = TRUE;
  848. // Also try to cancel uid 1.
  849. $edit['accounts[1]'] = TRUE;
  850. $this->drupalPost('admin/people', $edit, t('Update'));
  851. $this->assertText(t('Are you sure you want to cancel these user accounts?'), 'Confirmation form to cancel accounts displayed.');
  852. $this->assertText(t('When cancelling these accounts'), 'Allows to select account cancellation method.');
  853. $this->assertText(t('Require e-mail confirmation to cancel account.'), 'Allows to send confirmation mail.');
  854. $this->assertText(t('Notify user when account is canceled.'), 'Allows to send notification mail.');
  855. // Confirm deletion.
  856. $this->drupalPost(NULL, NULL, t('Cancel accounts'));
  857. $status = TRUE;
  858. foreach ($users as $account) {
  859. $status = $status && (strpos($this->content, t('%name has been deleted.', array('%name' => $account->name))) !== FALSE);
  860. $status = $status && !user_load($account->uid, TRUE);
  861. }
  862. $this->assertTrue($status, 'Users deleted and not found in the database.');
  863. // Ensure that admin account was not cancelled.
  864. $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
  865. $admin_user = user_load($admin_user->uid);
  866. $this->assertTrue($admin_user->status == 1, 'Administrative user is found in the database and enabled.');
  867. // Verify that uid 1's account was not cancelled.
  868. $user1 = user_load(1, TRUE);
  869. $this->assertEqual($user1->status, 1, 'User #1 still exists and is not blocked.');
  870. }
  871. }
  872. class UserPictureTestCase extends DrupalWebTestCase {
  873. protected $user;
  874. protected $_directory_test;
  875. public static function getInfo() {
  876. return array(
  877. 'name' => 'Upload user picture',
  878. 'description' => 'Assure that dimension check, extension check and image scaling work as designed.',
  879. 'group' => 'User'
  880. );
  881. }
  882. function setUp() {
  883. parent::setUp();
  884. // Enable user pictures.
  885. variable_set('user_pictures', 1);
  886. $this->user = $this->drupalCreateUser();
  887. // Test if directories specified in settings exist in filesystem.
  888. $file_dir = 'public://';
  889. $file_check = file_prepare_directory($file_dir, FILE_CREATE_DIRECTORY);
  890. // TODO: Test public and private methods?
  891. $picture_dir = variable_get('user_picture_path', 'pictures');
  892. $picture_path = $file_dir . $picture_dir;
  893. $pic_check = file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY);
  894. $this->_directory_test = is_writable($picture_path);
  895. $this->assertTrue($this->_directory_test, "The directory $picture_path doesn't exist or is not writable. Further tests won't be made.");
  896. }
  897. function testNoPicture() {
  898. $this->drupalLogin($this->user);
  899. // Try to upload a file that is not an image for the user picture.
  900. $not_an_image = current($this->drupalGetTestFiles('html'));
  901. $this->saveUserPicture($not_an_image);
  902. $this->assertRaw(t('Only JPEG, PNG and GIF images are allowed.'), 'Non-image files are not accepted.');
  903. }
  904. /**
  905. * Do the test:
  906. * GD Toolkit is installed
  907. * Picture has invalid dimension
  908. *
  909. * results: The image should be uploaded because ImageGDToolkit resizes the picture
  910. */
  911. function testWithGDinvalidDimension() {
  912. if ($this->_directory_test && image_get_toolkit()) {
  913. $this->drupalLogin($this->user);
  914. $image = current($this->drupalGetTestFiles('image'));
  915. $info = image_get_info($image->uri);
  916. // Set new variables: invalid dimensions, valid filesize (0 = no limit).
  917. $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10);
  918. variable_set('user_picture_dimensions', $test_dim);
  919. variable_set('user_picture_file_size', 0);
  920. $pic_path = $this->saveUserPicture($image);
  921. // Check that the image was resized and is being displayed on the
  922. // user's profile page.
  923. $text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim));
  924. $this->assertRaw($text, 'Image was resized.');
  925. $alt = t("@user's picture", array('@user' => format_username($this->user)));
  926. $style = variable_get('user_picture_style', '');
  927. $this->assertRaw(check_plain(image_style_url($style, $pic_path)), "Image is displayed in user's edit page");
  928. // Check if file is located in proper directory.
  929. $this->assertTrue(is_file($pic_path), "File is located in proper directory");
  930. }
  931. }
  932. /**
  933. * Do the test:
  934. * GD Toolkit is installed
  935. * Picture has invalid size
  936. *
  937. * results: The image should be uploaded because ImageGDToolkit resizes the picture
  938. */
  939. function testWithGDinvalidSize() {
  940. if ($this->_directory_test && image_get_toolkit()) {
  941. $this->drupalLogin($this->user);
  942. // Images are sorted first by size then by name. We need an image
  943. // bigger than 1 KB so we'll grab the last one.
  944. $files = $this->drupalGetTestFiles('image');
  945. $image = end($files);
  946. $info = image_get_info($image->uri);
  947. // Set new variables: valid dimensions, invalid filesize.
  948. $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
  949. $test_size = 1;
  950. variable_set('user_picture_dimensions', $test_dim);
  951. variable_set('user_picture_file_size', $test_size);
  952. $pic_path = $this->saveUserPicture($image);
  953. // Test that the upload failed and that the correct reason was cited.
  954. $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
  955. $this->assertRaw($text, 'Upload failed.');
  956. $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024)));
  957. $this->assertRaw($text, 'File size cited as reason for failure.');
  958. // Check if file is not uploaded.
  959. $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
  960. }
  961. }
  962. /**
  963. * Do the test:
  964. * GD Toolkit is not installed
  965. * Picture has invalid size
  966. *
  967. * results: The image shouldn't be uploaded
  968. */
  969. function testWithoutGDinvalidDimension() {
  970. if ($this->_directory_test && !image_get_toolkit()) {
  971. $this->drupalLogin($this->user);
  972. $image = current($this->drupalGetTestFiles('image'));
  973. $info = image_get_info($image->uri);
  974. // Set new variables: invalid dimensions, valid filesize (0 = no limit).
  975. $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10);
  976. variable_set('user_picture_dimensions', $test_dim);
  977. variable_set('user_picture_file_size', 0);
  978. $pic_path = $this->saveUserPicture($image);
  979. // Test that the upload failed and that the correct reason was cited.
  980. $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
  981. $this->assertRaw($text, 'Upload failed.');
  982. $text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim));
  983. $this->assertRaw($text, 'Checking response on invalid image (dimensions).');
  984. // Check if file is not uploaded.
  985. $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
  986. }
  987. }
  988. /**
  989. * Do the test:
  990. * GD Toolkit is not installed
  991. * Picture has invalid size
  992. *
  993. * results: The image shouldn't be uploaded
  994. */
  995. function testWithoutGDinvalidSize() {
  996. if ($this->_directory_test && !image_get_toolkit()) {
  997. $this->drupalLogin($this->user);
  998. $image = current($this->drupalGetTestFiles('image'));
  999. $info = image_get_info($image->uri);
  1000. // Set new variables: valid dimensions, invalid filesize.
  1001. $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
  1002. $test_size = 1;
  1003. variable_set('user_picture_dimensions', $test_dim);
  1004. variable_set('user_picture_file_size', $test_size);
  1005. $pic_path = $this->saveUserPicture($image);
  1006. // Test that the upload failed and that the correct reason was cited.
  1007. $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
  1008. $this->assertRaw($text, 'Upload failed.');
  1009. $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024)));
  1010. $this->assertRaw($text, 'File size cited as reason for failure.');
  1011. // Check if file is not uploaded.
  1012. $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
  1013. }
  1014. }
  1015. /**
  1016. * Do the test:
  1017. * Picture is valid (proper size and dimension)
  1018. *
  1019. * results: The image should be uploaded
  1020. */
  1021. function testPictureIsValid() {
  1022. if ($this->_directory_test) {
  1023. $this->drupalLogin($this->user);
  1024. $image = current($this->drupalGetTestFiles('image'));
  1025. $info = image_get_info($image->uri);
  1026. // Set new variables: valid dimensions, valid filesize (0 = no limit).
  1027. $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
  1028. variable_set('user_picture_dimensions', $test_dim);
  1029. variable_set('user_picture_file_size', 0);
  1030. $pic_path = $this->saveUserPicture($image);
  1031. // Check if image is displayed in user's profile page.
  1032. $this->drupalGet('user');
  1033. $this->assertRaw(file_uri_target($pic_path), "Image is displayed in user's profile page");
  1034. // Check if file is located in proper directory.
  1035. $this->assertTrue(is_file($pic_path), 'File is located in proper directory');
  1036. // Set new picture dimensions.
  1037. $test_dim = ($info['width'] + 5) . 'x' . ($info['height'] + 5);
  1038. variable_set('user_picture_dimensions', $test_dim);
  1039. $pic_path2 = $this->saveUserPicture($image);
  1040. $this->assertNotEqual($pic_path, $pic_path2, 'Filename of second picture is different.');
  1041. // Check if user picture has a valid file ID after saving the user.
  1042. $account = user_load($this->user->uid, TRUE);
  1043. $this->assertTrue(is_object($account->picture), 'User picture object is valid after user load.');
  1044. $this->assertNotNull($account->picture->fid, 'User picture object has a FID after user load.');
  1045. $this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user load.');
  1046. user_save($account);
  1047. // Verify that the user save does not destroy the user picture object.
  1048. $this->assertTrue(is_object($account->picture), 'User picture object is valid after user save.');
  1049. $this->assertNotNull($account->picture->fid, 'User picture object has a FID after user save.');
  1050. $this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user save.');
  1051. }
  1052. }
  1053. /**
  1054. * Test HTTP schema working with user pictures.
  1055. */
  1056. function testExternalPicture() {
  1057. $this->drupalLogin($this->user);
  1058. // Set the default picture to an URI with a HTTP schema.
  1059. $images = $this->drupalGetTestFiles('image');
  1060. $image = $images[0];
  1061. $pic_path = file_create_url($image->uri);
  1062. variable_set('user_picture_default', $pic_path);
  1063. // Check if image is displayed in user's profile page.
  1064. $this->drupalGet('user');
  1065. // Get the user picture image via xpath.
  1066. $elements = $this->xpath('//div[@class="user-picture"]/img');
  1067. $this->assertEqual(count($elements), 1, "There is exactly one user picture on the user's profile page");
  1068. $this->assertEqual($pic_path, (string) $elements[0]['src'], "User picture source is correct.");
  1069. }
  1070. /**
  1071. * Tests deletion of user pictures.
  1072. */
  1073. function testDeletePicture() {
  1074. $this->drupalLogin($this->user);
  1075. $image = current($this->drupalGetTestFiles('image'));
  1076. $info = image_get_info($image->uri);
  1077. // Set new variables: valid dimensions, valid filesize (0 = no limit).
  1078. $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
  1079. variable_set('user_picture_dimensions', $test_dim);
  1080. variable_set('user_picture_file_size', 0);
  1081. // Save a new picture.
  1082. $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
  1083. $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
  1084. // Load actual user data from database.
  1085. $account = user_load($this->user->uid, TRUE);
  1086. $pic_path = isset($account->picture) ? $account->picture->uri : NULL;
  1087. // Check if image is displayed in user's profile page.
  1088. $this->drupalGet('user');
  1089. $this->assertRaw(file_uri_target($pic_path), "Image is displayed in user's profile page");
  1090. // Check if file is located in proper directory.
  1091. $this->assertTrue(is_file($pic_path), 'File is located in proper directory');
  1092. $edit = array('picture_delete' => 1);
  1093. $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
  1094. // Load actual user data from database.
  1095. $account1 = user_load($this->user->uid, TRUE);
  1096. $this->assertNull($account1->picture, 'User object has no picture');
  1097. $file = file_load($account->picture->fid);
  1098. $this->assertFalse($file, 'File is removed from database');
  1099. // Clear out PHP's file stat cache so we see the current value.
  1100. clearstatcache();
  1101. $this->assertFalse(is_file($pic_path), 'File is removed from file system');
  1102. }
  1103. function saveUserPicture($image) {
  1104. $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
  1105. $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
  1106. // Load actual user data from database.
  1107. $account = user_load($this->user->uid, TRUE);
  1108. return isset($account->picture) ? $account->picture->uri : NULL;
  1109. }
  1110. /**
  1111. * Tests the admin form validates user picture settings.
  1112. */
  1113. function testUserPictureAdminFormValidation() {
  1114. $this->drupalLogin($this->drupalCreateUser(array('administer users')));
  1115. // The default values are valid.
  1116. $this->drupalPost('admin/config/people/accounts', array(), t('Save configuration'));
  1117. $this->assertText(t('The configuration options have been saved.'), 'The default values are valid.');
  1118. // The form does not save with an invalid file size.
  1119. $edit = array(
  1120. 'user_picture_file_size' => $this->randomName(),
  1121. );
  1122. $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
  1123. $this->assertNoText(t('The configuration options have been saved.'), 'The form does not save with an invalid file size.');
  1124. }
  1125. }
  1126. class UserPermissionsTestCase extends DrupalWebTestCase {
  1127. protected $admin_user;
  1128. protected $rid;
  1129. public static function getInfo() {
  1130. return array(
  1131. 'name' => 'Role permissions',
  1132. 'description' => 'Verify that role permissions can be added and removed via the permissions page.',
  1133. 'group' => 'User'
  1134. );
  1135. }
  1136. function setUp() {
  1137. parent::setUp();
  1138. $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer users'));
  1139. // Find the new role ID - it must be the maximum.
  1140. $all_rids = array_keys($this->admin_user->roles);
  1141. sort($all_rids);
  1142. $this->rid = array_pop($all_rids);
  1143. }
  1144. /**
  1145. * Change user permissions and check user_access().
  1146. */
  1147. function testUserPermissionChanges() {
  1148. $this->drupalLogin($this->admin_user);
  1149. $rid = $this->rid;
  1150. $account = $this->admin_user;
  1151. // Add a permission.
  1152. $this->assertFalse(user_access('administer nodes', $account), 'User does not have "administer nodes" permission.');
  1153. $edit = array();
  1154. $edit[$rid . '[administer nodes]'] = TRUE;
  1155. $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
  1156. $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
  1157. drupal_static_reset('user_access');
  1158. drupal_static_reset('user_role_permissions');
  1159. $this->assertTrue(user_access('administer nodes', $account), 'User now has "administer nodes" permission.');
  1160. // Remove a permission.
  1161. $this->assertTrue(user_access('access user profiles', $account), 'User has "access user profiles" permission.');
  1162. $edit = array();
  1163. $edit[$rid . '[access user profiles]'] = FALSE;
  1164. $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
  1165. $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
  1166. drupal_static_reset('user_access');
  1167. drupal_static_reset('user_role_permissions');
  1168. $this->assertFalse(user_access('access user profiles', $account), 'User no longer has "access user profiles" permission.');
  1169. }
  1170. /**
  1171. * Test assigning of permissions for the administrator role.
  1172. */
  1173. function testAdministratorRole() {
  1174. $this->drupalLogin($this->admin_user);
  1175. $this->drupalGet('admin/config/people/accounts');
  1176. // Set the user's role to be the administrator role.
  1177. $edit = array();
  1178. $edit['user_admin_role'] = $this->rid;
  1179. $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
  1180. // Enable aggregator module and ensure the 'administer news feeds'
  1181. // permission is assigned by default.
  1182. $edit = array();
  1183. $edit['modules[Core][aggregator][enable]'] = TRUE;
  1184. $this->drupalPost('admin/modules', $edit, t('Save configuration'));
  1185. $this->assertTrue(user_access('administer news feeds', $this->admin_user), 'The permission was automatically assigned to the administrator role');
  1186. }
  1187. /**
  1188. * Verify proper permission changes by user_role_change_permissions().
  1189. */
  1190. function testUserRoleChangePermissions() {
  1191. $rid = $this->rid;
  1192. $account = $this->admin_user;
  1193. // Verify current permissions.
  1194. $this->assertFalse(user_access('administer nodes', $account), 'User does not have "administer nodes" permission.');
  1195. $this->assertTrue(user_access('access user profiles', $account), 'User has "access user profiles" permission.');
  1196. $this->assertTrue(user_access('administer site configuration', $account), 'User has "administer site configuration" permission.');
  1197. // Change permissions.
  1198. $permissions = array(
  1199. 'administer nodes' => 1,
  1200. 'access user profiles' => 0,
  1201. );
  1202. user_role_change_permissions($rid, $permissions);
  1203. // Verify proper permission changes.
  1204. $this->assertTrue(user_access('administer nodes', $account), 'User now has "administer nodes" permission.');
  1205. $this->assertFalse(user_access('access user profiles', $account), 'User no longer has "access user profiles" permission.');
  1206. $this->assertTrue(user_access('administer site configuration', $account), 'User still has "administer site configuration" permission.');
  1207. }
  1208. }
  1209. class UserAdminTestCase extends DrupalWebTestCase {
  1210. public static function getInfo() {
  1211. return array(
  1212. 'name' => 'User administration',
  1213. 'description' => 'Test user administration page functionality.',
  1214. 'group' => 'User'
  1215. );
  1216. }
  1217. /**
  1218. * Registers a user and deletes it.
  1219. */
  1220. function testUserAdmin() {
  1221. $user_a = $this->drupalCreateUser(array());
  1222. $user_b = $this->drupalCreateUser(array('administer taxonomy'));
  1223. $user_c = $this->drupalCreateUser(array('administer taxonomy'));
  1224. // Create admin user to delete registered user.
  1225. $admin_user = $this->drupalCreateUser(array('administer users'));
  1226. $this->drupalLogin($admin_user);
  1227. $this->drupalGet('admin/people');
  1228. $this->assertText($user_a->name, 'Found user A on admin users page');
  1229. $this->assertText($user_b->name, 'Found user B on admin users page');
  1230. $this->assertText($user_c->name, 'Found user C on admin users page');
  1231. $this->assertText($admin_user->name, 'Found Admin user on admin users page');
  1232. // Test for existence of edit link in table.
  1233. $link = l(t('edit'), "user/$user_a->uid/edit", array('query' => array('destination' => 'admin/people')));
  1234. $this->assertRaw($link, 'Found user A edit link on admin users page');
  1235. // Filter the users by permission 'administer taxonomy'.
  1236. $edit = array();
  1237. $edit['permission'] = 'administer taxonomy';
  1238. $this->drupalPost('admin/people', $edit, t('Filter'));
  1239. // Check if the correct users show up.
  1240. $this->assertNoText($user_a->name, 'User A not on filtered by perm admin users page');
  1241. $this->assertText($user_b->name, 'Found user B on filtered by perm admin users page');
  1242. $this->assertText($user_c->name, 'Found user C on filtered by perm admin users page');
  1243. // Filter the users by role. Grab the system-generated role name for User C.
  1244. $edit['role'] = max(array_flip($user_c->roles));
  1245. $this->drupalPost('admin/people', $edit, t('Refine'));
  1246. // Check if the correct users show up when filtered by role.
  1247. $this->assertNoText($user_a->name, 'User A not on filtered by role on admin users page');
  1248. $this->assertNoText($user_b->name, 'User B not on filtered by role on admin users page');
  1249. $this->assertText($user_c->name, 'User C on filtered by role on admin users page');
  1250. // Test blocking of a user.
  1251. $account = user_load($user_c->uid);
  1252. $this->assertEqual($account->status, 1, 'User C not blocked');
  1253. $edit = array();
  1254. $edit['operation'] = 'block';
  1255. $edit['accounts[' . $account->uid . ']'] = TRUE;
  1256. $this->drupalPost('admin/people', $edit, t('Update'));
  1257. $account = user_load($user_c->uid, TRUE);
  1258. $this->assertEqual($account->status, 0, 'User C blocked');
  1259. // Test unblocking of a user from /admin/people page and sending of activation mail
  1260. $editunblock = array();
  1261. $editunblock['operation'] = 'unblock';
  1262. $editunblock['accounts[' . $account->uid . ']'] = TRUE;
  1263. $this->drupalPost('admin/people', $editunblock, t('Update'));
  1264. $account = user_load($user_c->uid, TRUE);
  1265. $this->assertEqual($account->status, 1, 'User C unblocked');
  1266. $this->assertMail("to", $account->mail, "Activation mail sent to user C");
  1267. // Test blocking and unblocking another user from /user/[uid]/edit form and sending of activation mail
  1268. $user_d = $this->drupalCreateUser(array());
  1269. $account1 = user_load($user_d->uid, TRUE);
  1270. $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => 0), t('Save'));
  1271. $account1 = user_load($user_d->uid, TRUE);
  1272. $this->assertEqual($account1->status, 0, 'User D blocked');
  1273. $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => TRUE), t('Save'));
  1274. $account1 = user_load($user_d->uid, TRUE);
  1275. $this->assertEqual($account1->status, 1, 'User D unblocked');
  1276. $this->assertMail("to", $account1->mail, "Activation mail sent to user D");
  1277. }
  1278. }
  1279. /**
  1280. * Tests for user-configurable time zones.
  1281. */
  1282. class UserTimeZoneFunctionalTest extends DrupalWebTestCase {
  1283. public static function getInfo() {
  1284. return array(
  1285. 'name' => 'User time zones',
  1286. 'description' => 'Set a user time zone and verify that dates are displayed in local time.',
  1287. 'group' => 'User',
  1288. );
  1289. }
  1290. /**
  1291. * Tests the display of dates and time when user-configurable time zones are set.
  1292. */
  1293. function testUserTimeZone() {
  1294. // Setup date/time settings for Los Angeles time.
  1295. variable_set('date_default_timezone', 'America/Los_Angeles');
  1296. variable_set('configurable_timezones', 1);
  1297. variable_set('date_format_medium', 'Y-m-d H:i T');
  1298. // Create a user account and login.
  1299. $web_user = $this->drupalCreateUser();
  1300. $this->drupalLogin($web_user);
  1301. // Create some nodes with different authored-on dates.
  1302. // Two dates in PST (winter time):
  1303. $date1 = '2007-03-09 21:00:00 -0800';
  1304. $date2 = '2007-03-11 01:00:00 -0800';
  1305. // One date in PDT (summer time):
  1306. $date3 = '2007-03-20 21:00:00 -0700';
  1307. $node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article'));
  1308. $node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article'));
  1309. $node3 = $this->drupalCreateNode(array('created' => strtotime($date3), 'type' => 'article'));
  1310. // Confirm date format and time zone.
  1311. $this->drupalGet("node/$node1->nid");
  1312. $this->assertText('2007-03-09 21:00 PST', 'Date should be PST.');
  1313. $this->drupalGet("node/$node2->nid");
  1314. $this->assertText('2007-03-11 01:00 PST', 'Date should be PST.');
  1315. $this->drupalGet("node/$node3->nid");
  1316. $this->assertText('2007-03-20 21:00 PDT', 'Date should be PDT.');
  1317. // Change user time zone to Santiago time.
  1318. $edit = array();
  1319. $edit['mail'] = $web_user->mail;
  1320. $edit['timezone'] = 'America/Santiago';
  1321. $this->drupalPost("user/$web_user->uid/edit", $edit, t('Save'));
  1322. $this->assertText(t('The changes have been saved.'), 'Time zone changed to Santiago time.');
  1323. // Confirm date format and time zone.
  1324. $this->drupalGet("node/$node1->nid");
  1325. $this->assertText('2007-03-10 02:00 CLST', 'Date should be Chile summer time; five hours ahead of PST.');
  1326. $this->drupalGet("node/$node2->nid");
  1327. $this->assertText('2007-03-11 05:00 CLT', 'Date should be Chile time; four hours ahead of PST');
  1328. $this->drupalGet("node/$node3->nid");
  1329. $this->assertText('2007-03-21 00:00 CLT', 'Date should be Chile time; three hours ahead of PDT.');
  1330. }
  1331. }
  1332. /**
  1333. * Test user autocompletion.
  1334. */
  1335. class UserAutocompleteTestCase extends DrupalWebTestCase {
  1336. public static function getInfo() {
  1337. return array(
  1338. 'name' => 'User autocompletion',
  1339. 'description' => 'Test user autocompletion functionality.',
  1340. 'group' => 'User'
  1341. );
  1342. }
  1343. function setUp() {
  1344. parent::setUp();
  1345. // Set up two users with different permissions to test access.
  1346. $this->unprivileged_user = $this->drupalCreateUser();
  1347. $this->privileged_user = $this->drupalCreateUser(array('access user profiles'));
  1348. }
  1349. /**
  1350. * Tests access to user autocompletion and verify the correct results.
  1351. */
  1352. function testUserAutocomplete() {
  1353. // Check access from unprivileged user, should be denied.
  1354. $this->drupalLogin($this->unprivileged_user);
  1355. $this->drupalGet('user/autocomplete/' . $this->unprivileged_user->name[0]);
  1356. $this->assertResponse(403, 'Autocompletion access denied to user without permission.');
  1357. // Check access from privileged user.
  1358. $this->drupalLogout();
  1359. $this->drupalLogin($this->privileged_user);
  1360. $this->drupalGet('user/autocomplete/' . $this->unprivileged_user->name[0]);
  1361. $this->assertResponse(200, 'Autocompletion access allowed.');
  1362. // Using first letter of the user's name, make sure the user's full name is in the results.
  1363. $this->assertRaw($this->unprivileged_user->name, 'User name found in autocompletion results.');
  1364. }
  1365. }
  1366. /**
  1367. * Tests user links in the secondary menu.
  1368. */
  1369. class UserAccountLinksUnitTests extends DrupalWebTestCase {
  1370. public static function getInfo() {
  1371. return array(
  1372. 'name' => 'User account links',
  1373. 'description' => 'Test user-account links.',
  1374. 'group' => 'User'
  1375. );
  1376. }
  1377. function setUp() {
  1378. parent::setUp('menu');
  1379. }
  1380. /**
  1381. * Tests the secondary menu.
  1382. */
  1383. function testSecondaryMenu() {
  1384. // Create a regular user.
  1385. $user = $this->drupalCreateUser(array());
  1386. // Log in and get the homepage.
  1387. $this->drupalLogin($user);
  1388. $this->drupalGet('<front>');
  1389. // For a logged-in user, expect the secondary menu to have links for "My
  1390. // account" and "Log out".
  1391. $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
  1392. ':menu_id' => 'secondary-menu-links',
  1393. ':href' => 'user',
  1394. ':text' => 'My account',
  1395. ));
  1396. $this->assertEqual(count($link), 1, 'My account link is in secondary menu.');
  1397. $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
  1398. ':menu_id' => 'secondary-menu-links',
  1399. ':href' => 'user/logout',
  1400. ':text' => 'Log out',
  1401. ));
  1402. $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.');
  1403. // Log out and get the homepage.
  1404. $this->drupalLogout();
  1405. $this->drupalGet('<front>');
  1406. // For a logged-out user, expect no secondary links.
  1407. $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu-links'));
  1408. $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
  1409. }
  1410. /**
  1411. * Tests disabling the 'My account' link.
  1412. */
  1413. function testDisabledAccountLink() {
  1414. // Create an admin user and log in.
  1415. $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));
  1416. // Verify that the 'My account' link is enabled.
  1417. $this->drupalGet('admin/structure/menu/manage/user-menu');
  1418. $label = $this->xpath('//label[contains(.,:text)]/@for', array(':text' => 'Enable My account menu link'));
  1419. $this->assertFieldChecked((string) $label[0], "The 'My account' link is enabled by default.");
  1420. // Disable the 'My account' link.
  1421. $input = $this->xpath('//input[@id=:field_id]/@name', array(':field_id' => (string)$label[0]));
  1422. $edit = array(
  1423. (string) $input[0] => FALSE,
  1424. );
  1425. $this->drupalPost('admin/structure/menu/manage/user-menu', $edit, t('Save configuration'));
  1426. // Get the homepage.
  1427. $this->drupalGet('<front>');
  1428. // Verify that the 'My account' link does not appear when disabled.
  1429. $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
  1430. ':menu_id' => 'secondary-menu-links',
  1431. ':href' => 'user',
  1432. ':text' => 'My account',
  1433. ));
  1434. $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.');
  1435. }
  1436. }
  1437. /**
  1438. * Test user blocks.
  1439. */
  1440. class UserBlocksUnitTests extends DrupalWebTestCase {
  1441. public static function getInfo() {
  1442. return array(
  1443. 'name' => 'User blocks',
  1444. 'description' => 'Test user blocks.',
  1445. 'group' => 'User'
  1446. );
  1447. }
  1448. /**
  1449. * Test the user login block.
  1450. */
  1451. function testUserLoginBlock() {
  1452. // Create a user with some permission that anonymous users lack.
  1453. $user = $this->drupalCreateUser(array('administer permissions'));
  1454. // Log in using the block.
  1455. $edit = array();
  1456. $edit['name'] = $user->name;
  1457. $edit['pass'] = $user->pass_raw;
  1458. $this->drupalPost('admin/people/permissions', $edit, t('Log in'));
  1459. $this->assertNoText(t('User login'), 'Logged in.');
  1460. // Check that we are still on the same page.
  1461. $this->assertEqual(url('admin/people/permissions', array('absolute' => TRUE)), $this->getUrl(), 'Still on the same page after login for access denied page');
  1462. // Now, log out and repeat with a non-403 page.
  1463. $this->drupalLogout();
  1464. $this->drupalPost('filter/tips', $edit, t('Log in'));
  1465. $this->assertNoText(t('User login'), 'Logged in.');
  1466. $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
  1467. // Check that the user login block is not vulnerable to information
  1468. // disclosure to third party sites.
  1469. $this->drupalLogout();
  1470. $this->drupalPost('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
  1471. // Check that we remain on the site after login.
  1472. $this->assertEqual(url('user/' . $user->uid, array('absolute' => TRUE)), $this->getUrl(), 'Redirected to user profile page after login from the frontpage');
  1473. }
  1474. /**
  1475. * Test the Who's Online block.
  1476. */
  1477. function testWhosOnlineBlock() {
  1478. // Generate users and make sure there are no current user sessions.
  1479. $user1 = $this->drupalCreateUser(array());
  1480. $user2 = $this->drupalCreateUser(array());
  1481. $user3 = $this->drupalCreateUser(array());
  1482. $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions}")->fetchField(), 0, 'Sessions table is empty.');
  1483. // Insert a user with two sessions.
  1484. $this->insertSession(array('uid' => $user1->uid));
  1485. $this->insertSession(array('uid' => $user1->uid));
  1486. $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid", array(':uid' => $user1->uid))->fetchField(), 2, 'Duplicate user session has been inserted.');
  1487. // Insert a user with only one session.
  1488. $this->insertSession(array('uid' => $user2->uid, 'timestamp' => REQUEST_TIME + 1));
  1489. // Insert an inactive logged-in user who should not be seen in the block.
  1490. $this->insertSession(array('uid' => $user3->uid, 'timestamp' => (REQUEST_TIME - variable_get('user_block_seconds_online', 900) - 1)));
  1491. // Insert two anonymous user sessions.
  1492. $this->insertSession();
  1493. $this->insertSession();
  1494. // Test block output.
  1495. $block = user_block_view('online');
  1496. $this->drupalSetContent($block['content']);
  1497. $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).');
  1498. $this->assertText($user1->name, 'Active user 1 found in online list.');
  1499. $this->assertText($user2->name, 'Active user 2 found in online list.');
  1500. $this->assertNoText($user3->name, "Inactive user not found in online list.");
  1501. $this->assertTrue(strpos($this->drupalGetContent(), $user1->name) > strpos($this->drupalGetContent(), $user2->name), 'Online users are ordered correctly.');
  1502. }
  1503. /**
  1504. * Insert a user session into the {sessions} table. This function is used
  1505. * since we cannot log in more than one user at the same time in tests.
  1506. */
  1507. private function insertSession(array $fields = array()) {
  1508. $fields += array(
  1509. 'uid' => 0,
  1510. 'sid' => drupal_hash_base64(uniqid(mt_rand(), TRUE)),
  1511. 'timestamp' => REQUEST_TIME,
  1512. );
  1513. db_insert('sessions')
  1514. ->fields($fields)
  1515. ->execute();
  1516. $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid AND sid = :sid AND timestamp = :timestamp", array(':uid' => $fields['uid'], ':sid' => $fields['sid'], ':timestamp' => $fields['timestamp']))->fetchField(), 1, 'Session record inserted.');
  1517. }
  1518. }
  1519. /**
  1520. * Tests saving a user account.
  1521. */
  1522. class UserSaveTestCase extends DrupalWebTestCase {
  1523. public static function getInfo() {
  1524. return array(
  1525. 'name' => 'User save test',
  1526. 'description' => 'Test user_save() for arbitrary new uid.',
  1527. 'group' => 'User',
  1528. );
  1529. }
  1530. /**
  1531. * Test creating a user with arbitrary uid.
  1532. */
  1533. function testUserImport() {
  1534. // User ID must be a number that is not in the database.
  1535. $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField();
  1536. $test_uid = $max_uid + mt_rand(1000, 1000000);
  1537. $test_name = $this->randomName();
  1538. // Create the base user, based on drupalCreateUser().
  1539. $user = array(
  1540. 'name' => $test_name,
  1541. 'uid' => $test_uid,
  1542. 'mail' => $test_name . '@example.com',
  1543. 'is_new' => TRUE,
  1544. 'pass' => user_password(),
  1545. 'status' => 1,
  1546. );
  1547. $user_by_return = user_save(drupal_anonymous_user(), $user);
  1548. $this->assertTrue($user_by_return, 'Loading user by return of user_save().');
  1549. // Test if created user exists.
  1550. $user_by_uid = user_load($test_uid);
  1551. $this->assertTrue($user_by_uid, 'Loading user by uid.');
  1552. $user_by_name = user_load_by_name($test_name);
  1553. $this->assertTrue($user_by_name, 'Loading user by name.');
  1554. }
  1555. }
  1556. /**
  1557. * Test the create user administration page.
  1558. */
  1559. class UserCreateTestCase extends DrupalWebTestCase {
  1560. public static function getInfo() {
  1561. return array(
  1562. 'name' => 'User create',
  1563. 'description' => 'Test the create user administration page.',
  1564. 'group' => 'User',
  1565. );
  1566. }
  1567. /**
  1568. * Create a user through the administration interface and ensure that it
  1569. * displays in the user list.
  1570. */
  1571. protected function testUserAdd() {
  1572. $user = $this->drupalCreateUser(array('administer users'));
  1573. $this->drupalLogin($user);
  1574. foreach (array(FALSE, TRUE) as $notify) {
  1575. $edit = array(
  1576. 'name' => $this->randomName(),
  1577. 'mail' => $this->randomName() . '@example.com',
  1578. 'pass[pass1]' => $pass = $this->randomString(),
  1579. 'pass[pass2]' => $pass,
  1580. 'notify' => $notify,
  1581. );
  1582. $this->drupalPost('admin/people/create', $edit, t('Create new account'));
  1583. if ($notify) {
  1584. $this->assertText(t('A welcome message with further instructions has been e-mailed to the new user @name.', array('@name' => $edit['name'])), 'User created');
  1585. $this->assertEqual(count($this->drupalGetMails()), 1, 'Notification e-mail sent');
  1586. }
  1587. else {
  1588. $this->assertText(t('Created a new user account for @name. No e-mail has been sent.', array('@name' => $edit['name'])), 'User created');
  1589. $this->assertEqual(count($this->drupalGetMails()), 0, 'Notification e-mail not sent');
  1590. }
  1591. $this->drupalGet('admin/people');
  1592. $this->assertText($edit['name'], 'User found in list of users');
  1593. }
  1594. // Test that the password '0' is considered a password.
  1595. $name = $this->randomName();
  1596. $edit = array(
  1597. 'name' => $name,
  1598. 'mail' => $name . '@example.com',
  1599. 'pass[pass1]' => 0,
  1600. 'pass[pass2]' => 0,
  1601. 'notify' => FALSE,
  1602. );
  1603. $this->drupalPost('admin/people/create', $edit, t('Create new account'));
  1604. $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');
  1605. $this->assertNoText('Password field is required');
  1606. }
  1607. }
  1608. /**
  1609. * Tests editing a user account.
  1610. */
  1611. class UserEditTestCase extends DrupalWebTestCase {
  1612. public static function getInfo() {
  1613. return array(
  1614. 'name' => 'User edit',
  1615. 'description' => 'Test user edit page.',
  1616. 'group' => 'User',
  1617. );
  1618. }
  1619. /**
  1620. * Test user edit page.
  1621. */
  1622. function testUserEdit() {
  1623. // Test user edit functionality with user pictures disabled.
  1624. variable_set('user_pictures', 0);
  1625. $user1 = $this->drupalCreateUser(array('change own username'));
  1626. $user2 = $this->drupalCreateUser(array());
  1627. $this->drupalLogin($user1);
  1628. // Test that error message appears when attempting to use a non-unique user name.
  1629. $edit['name'] = $user2->name;
  1630. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1631. $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name'])));
  1632. // Repeat the test with user pictures enabled, which modifies the form.
  1633. variable_set('user_pictures', 1);
  1634. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1635. $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name'])));
  1636. // Check that filling out a single password field does not validate.
  1637. $edit = array();
  1638. $edit['pass[pass1]'] = '';
  1639. $edit['pass[pass2]'] = $this->randomName();
  1640. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1641. $this->assertText(t("The specified passwords do not match."), 'Typing mismatched passwords displays an error message.');
  1642. $edit['pass[pass1]'] = $this->randomName();
  1643. $edit['pass[pass2]'] = '';
  1644. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1645. $this->assertText(t("The specified passwords do not match."), 'Typing mismatched passwords displays an error message.');
  1646. // Test that the error message appears when attempting to change the mail or
  1647. // pass without the current password.
  1648. $edit = array();
  1649. $edit['mail'] = $this->randomName() . '@new.example.com';
  1650. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1651. $this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => t('E-mail address'))));
  1652. $edit['current_pass'] = $user1->pass_raw;
  1653. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1654. $this->assertRaw(t("The changes have been saved."));
  1655. // Test that the user must enter current password before changing passwords.
  1656. $edit = array();
  1657. $edit['pass[pass1]'] = $new_pass = $this->randomName();
  1658. $edit['pass[pass2]'] = $new_pass;
  1659. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1660. $this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => t('Password'))));
  1661. // Try again with the current password.
  1662. $edit['current_pass'] = $user1->pass_raw;
  1663. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1664. $this->assertRaw(t("The changes have been saved."));
  1665. // Make sure the user can log in with their new password.
  1666. $this->drupalLogout();
  1667. $user1->pass_raw = $new_pass;
  1668. $this->drupalLogin($user1);
  1669. $this->drupalLogout();
  1670. }
  1671. /**
  1672. * Tests setting the password to "0".
  1673. */
  1674. public function testUserWith0Password() {
  1675. $admin = $this->drupalCreateUser(array('administer users'));
  1676. $this->drupalLogin($admin);
  1677. // Create a regular user.
  1678. $user1 = $this->drupalCreateUser(array());
  1679. $edit = array('pass[pass1]' => '0', 'pass[pass2]' => '0');
  1680. $this->drupalPost("user/" . $user1->uid . "/edit", $edit, t('Save'));
  1681. $this->assertRaw(t("The changes have been saved."));
  1682. $this->drupalLogout();
  1683. $user1->pass_raw = '0';
  1684. $this->drupalLogin($user1);
  1685. $this->drupalLogout();
  1686. }
  1687. }
  1688. /**
  1689. * Tests editing a user account with and without a form rebuild.
  1690. */
  1691. class UserEditRebuildTestCase extends DrupalWebTestCase {
  1692. public static function getInfo() {
  1693. return array(
  1694. 'name' => 'User edit with form rebuild',
  1695. 'description' => 'Test user edit page when a form rebuild is triggered.',
  1696. 'group' => 'User',
  1697. );
  1698. }
  1699. function setUp() {
  1700. parent::setUp('user_form_test');
  1701. }
  1702. /**
  1703. * Test user edit page when the form is set to rebuild.
  1704. */
  1705. function testUserEditFormRebuild() {
  1706. $user1 = $this->drupalCreateUser(array('change own username'));
  1707. $this->drupalLogin($user1);
  1708. $roles = array_keys($user1->roles);
  1709. // Save the user form twice.
  1710. $edit = array();
  1711. $edit['current_pass'] = $user1->pass_raw;
  1712. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1713. $this->assertRaw(t("The changes have been saved."));
  1714. $this->drupalPost(NULL, $edit, t('Save'));
  1715. $this->assertRaw(t("The changes have been saved."));
  1716. $saved_user1 = entity_load_unchanged('user', $user1->uid);
  1717. $this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.');
  1718. $diff = array_diff(array_keys($saved_user1->roles), $roles);
  1719. $this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles))));
  1720. // Set variable that causes the form to be rebuilt in user_form_test.module.
  1721. variable_set('user_form_test_user_profile_form_rebuild', TRUE);
  1722. $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
  1723. $this->assertRaw(t("The changes have been saved."));
  1724. $this->drupalPost(NULL, $edit, t('Save'));
  1725. $this->assertRaw(t("The changes have been saved."));
  1726. $saved_user1 = entity_load_unchanged('user', $user1->uid);
  1727. $this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.');
  1728. $diff = array_diff(array_keys($saved_user1->roles), $roles);
  1729. $this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles))));
  1730. }
  1731. }
  1732. /**
  1733. * Test case for user signatures.
  1734. */
  1735. class UserSignatureTestCase extends DrupalWebTestCase {
  1736. public static function getInfo() {
  1737. return array(
  1738. 'name' => 'User signatures',
  1739. 'description' => 'Test user signatures.',
  1740. 'group' => 'User',
  1741. );
  1742. }
  1743. function setUp() {
  1744. parent::setUp('comment');
  1745. // Enable user signatures.
  1746. variable_set('user_signatures', 1);
  1747. // Prefetch text formats.
  1748. $this->full_html_format = filter_format_load('full_html');
  1749. $this->plain_text_format = filter_format_load('plain_text');
  1750. // Create regular and administrative users.
  1751. $this->web_user = $this->drupalCreateUser(array());
  1752. $admin_permissions = array('administer comments');
  1753. foreach (filter_formats() as $format) {
  1754. if ($permission = filter_permission_name($format)) {
  1755. $admin_permissions[] = $permission;
  1756. }
  1757. }
  1758. $this->admin_user = $this->drupalCreateUser($admin_permissions);
  1759. }
  1760. /**
  1761. * Test that a user can change their signature format and that it is respected
  1762. * upon display.
  1763. */
  1764. function testUserSignature() {
  1765. // Create a new node with comments on.
  1766. $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN));
  1767. // Verify that user signature field is not displayed on registration form.
  1768. $this->drupalGet('user/register');
  1769. $this->assertNoText(t('Signature'));
  1770. // Log in as a regular user and create a signature.
  1771. $this->drupalLogin($this->web_user);
  1772. $signature_text = "<h1>" . $this->randomName() . "</h1>";
  1773. $edit = array(
  1774. 'signature[value]' => $signature_text,
  1775. 'signature[format]' => $this->plain_text_format->format,
  1776. );
  1777. $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
  1778. // Verify that values were stored.
  1779. $this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');
  1780. $this->assertFieldByName('signature[format]', $edit['signature[format]'], 'Submitted signature format found.');
  1781. // Create a comment.
  1782. $langcode = LANGUAGE_NONE;
  1783. $edit = array();
  1784. $edit['subject'] = $this->randomName(8);
  1785. $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
  1786. $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview'));
  1787. $this->drupalPost(NULL, array(), t('Save'));
  1788. // Get the comment ID. (This technique is the same one used in the Comment
  1789. // module's CommentHelperCase test case.)
  1790. preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
  1791. $comment_id = $match[1];
  1792. // Log in as an administrator and edit the comment to use Full HTML, so
  1793. // that the comment text itself is not filtered at all.
  1794. $this->drupalLogin($this->admin_user);
  1795. $edit['comment_body[' . $langcode . '][0][format]'] = $this->full_html_format->format;
  1796. $this->drupalPost('comment/' . $comment_id . '/edit', $edit, t('Save'));
  1797. // Assert that the signature did not make it through unfiltered.
  1798. $this->drupalGet('node/' . $node->nid);
  1799. $this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
  1800. $this->assertRaw(check_markup($signature_text, $this->plain_text_format->format), 'Filtered signature text found.');
  1801. }
  1802. }
  1803. /*
  1804. * Test that a user, having editing their own account, can still log in.
  1805. */
  1806. class UserEditedOwnAccountTestCase extends DrupalWebTestCase {
  1807. public static function getInfo() {
  1808. return array(
  1809. 'name' => 'User edited own account',
  1810. 'description' => 'Test user edited own account can still log in.',
  1811. 'group' => 'User',
  1812. );
  1813. }
  1814. function testUserEditedOwnAccount() {
  1815. // Change account setting 'Who can register accounts?' to Administrators
  1816. // only.
  1817. variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
  1818. // Create a new user account and log in.
  1819. $account = $this->drupalCreateUser(array('change own username'));
  1820. $this->drupalLogin($account);
  1821. // Change own username.
  1822. $edit = array();
  1823. $edit['name'] = $this->randomName();
  1824. $this->drupalPost('user/' . $account->uid . '/edit', $edit, t('Save'));
  1825. // Log out.
  1826. $this->drupalLogout();
  1827. // Set the new name on the user account and attempt to log back in.
  1828. $account->name = $edit['name'];
  1829. $this->drupalLogin($account);
  1830. }
  1831. }
  1832. /**
  1833. * Test case to test adding, editing and deleting roles.
  1834. */
  1835. class UserRoleAdminTestCase extends DrupalWebTestCase {
  1836. public static function getInfo() {
  1837. return array(
  1838. 'name' => 'User role administration',
  1839. 'description' => 'Test adding, editing and deleting user roles and changing role weights.',
  1840. 'group' => 'User',
  1841. );
  1842. }
  1843. function setUp() {
  1844. parent::setUp();
  1845. $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
  1846. }
  1847. /**
  1848. * Test adding, renaming and deleting roles.
  1849. */
  1850. function testRoleAdministration() {
  1851. $this->drupalLogin($this->admin_user);
  1852. // Test adding a role. (In doing so, we use a role name that happens to
  1853. // correspond to an integer, to test that the role administration pages
  1854. // correctly distinguish between role names and IDs.)
  1855. $role_name = '123';
  1856. $edit = array('name' => $role_name);
  1857. $this->drupalPost('admin/people/permissions/roles', $edit, t('Add role'));
  1858. $this->assertText(t('The role has been added.'), 'The role has been added.');
  1859. $role = user_role_load_by_name($role_name);
  1860. $this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.');
  1861. // Try adding a duplicate role.
  1862. $this->drupalPost(NULL, $edit, t('Add role'));
  1863. $this->assertRaw(t('The role name %name already exists. Choose another role name.', array('%name' => $role_name)), 'Duplicate role warning displayed.');
  1864. // Test renaming a role.
  1865. $old_name = $role_name;
  1866. $role_name = '456';
  1867. $edit = array('name' => $role_name);
  1868. $this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", $edit, t('Save role'));
  1869. $this->assertText(t('The role has been renamed.'), 'The role has been renamed.');
  1870. $this->assertFalse(user_role_load_by_name($old_name), 'The role can no longer be retrieved from the database using its old name.');
  1871. $this->assertTrue(is_object(user_role_load_by_name($role_name)), 'The role can be retrieved from the database using its new name.');
  1872. // Test deleting the default administrator role.
  1873. $role_name = 'administrator';
  1874. $role = user_role_load_by_name($role_name);
  1875. $this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", NULL, t('Delete role'));
  1876. $this->drupalPost(NULL, NULL, t('Delete'));
  1877. $this->assertText(t('The role has been deleted.'), 'The role has been deleted');
  1878. $this->assertNoLinkByHref("admin/people/permissions/roles/edit/{$role->rid}", 'Role edit link removed.');
  1879. $this->assertFalse(user_role_load_by_name($role_name), 'A deleted role can no longer be loaded.');
  1880. // Make sure this role is no longer configured as the administrator role.
  1881. $this->assertNull(variable_get('user_admin_role'), 'The administrator role is no longer configured as the administrator role.');
  1882. // Make sure that the system-defined roles cannot be edited via the user
  1883. // interface.
  1884. $this->drupalGet('admin/people/permissions/roles/edit/' . DRUPAL_ANONYMOUS_RID);
  1885. $this->assertResponse(403, 'Access denied when trying to edit the built-in anonymous role.');
  1886. $this->drupalGet('admin/people/permissions/roles/edit/' . DRUPAL_AUTHENTICATED_RID);
  1887. $this->assertResponse(403, 'Access denied when trying to edit the built-in authenticated role.');
  1888. }
  1889. /**
  1890. * Test user role weight change operation.
  1891. */
  1892. function testRoleWeightChange() {
  1893. $this->drupalLogin($this->admin_user);
  1894. // Pick up a random role and get its weight.
  1895. $rid = array_rand(user_roles());
  1896. $role = user_role_load($rid);
  1897. $old_weight = $role->weight;
  1898. // Change the role weight and submit the form.
  1899. $edit = array('roles['. $rid .'][weight]' => $old_weight + 1);
  1900. $this->drupalPost('admin/people/permissions/roles', $edit, t('Save order'));
  1901. $this->assertText(t('The role settings have been updated.'), 'The role settings form submitted successfully.');
  1902. // Retrieve the saved role and compare its weight.
  1903. $role = user_role_load($rid);
  1904. $new_weight = $role->weight;
  1905. $this->assertTrue(($old_weight + 1) == $new_weight, 'Role weight updated successfully.');
  1906. }
  1907. }
  1908. /**
  1909. * Test user token replacement in strings.
  1910. */
  1911. class UserTokenReplaceTestCase extends DrupalWebTestCase {
  1912. public static function getInfo() {
  1913. return array(
  1914. 'name' => 'User token replacement',
  1915. 'description' => 'Generates text using placeholders for dummy content to check user token replacement.',
  1916. 'group' => 'User',
  1917. );
  1918. }
  1919. /**
  1920. * Creates a user, then tests the tokens generated from it.
  1921. */
  1922. function testUserTokenReplacement() {
  1923. global $language;
  1924. $url_options = array(
  1925. 'absolute' => TRUE,
  1926. 'language' => $language,
  1927. );
  1928. // Create two users and log them in one after another.
  1929. $user1 = $this->drupalCreateUser(array());
  1930. $user2 = $this->drupalCreateUser(array());
  1931. $this->drupalLogin($user1);
  1932. $this->drupalLogout();
  1933. $this->drupalLogin($user2);
  1934. $account = user_load($user1->uid);
  1935. $global_account = user_load($GLOBALS['user']->uid);
  1936. // Generate and test sanitized tokens.
  1937. $tests = array();
  1938. $tests['[user:uid]'] = $account->uid;
  1939. $tests['[user:name]'] = check_plain(format_username($account));
  1940. $tests['[user:mail]'] = check_plain($account->mail);
  1941. $tests['[user:url]'] = url("user/$account->uid", $url_options);
  1942. $tests['[user:edit-url]'] = url("user/$account->uid/edit", $url_options);
  1943. $tests['[user:last-login]'] = format_date($account->login, 'medium', '', NULL, $language->language);
  1944. $tests['[user:last-login:short]'] = format_date($account->login, 'short', '', NULL, $language->language);
  1945. $tests['[user:created]'] = format_date($account->created, 'medium', '', NULL, $language->language);
  1946. $tests['[user:created:short]'] = format_date($account->created, 'short', '', NULL, $language->language);
  1947. $tests['[current-user:name]'] = check_plain(format_username($global_account));
  1948. // Test to make sure that we generated something for each token.
  1949. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
  1950. foreach ($tests as $input => $expected) {
  1951. $output = token_replace($input, array('user' => $account), array('language' => $language));
  1952. $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input)));
  1953. }
  1954. // Generate and test unsanitized tokens.
  1955. $tests['[user:name]'] = format_username($account);
  1956. $tests['[user:mail]'] = $account->mail;
  1957. $tests['[current-user:name]'] = format_username($global_account);
  1958. foreach ($tests as $input => $expected) {
  1959. $output = token_replace($input, array('user' => $account), array('language' => $language, 'sanitize' => FALSE));
  1960. $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input)));
  1961. }
  1962. }
  1963. }
  1964. /**
  1965. * Test user search.
  1966. */
  1967. class UserUserSearchTestCase extends DrupalWebTestCase {
  1968. public static function getInfo() {
  1969. return array(
  1970. 'name' => 'User search',
  1971. 'description' => 'Tests the user search page and verifies that sensitive information is hidden from unauthorized users.',
  1972. 'group' => 'User',
  1973. );
  1974. }
  1975. function testUserSearch() {
  1976. $user1 = $this->drupalCreateUser(array('access user profiles', 'search content', 'use advanced search'));
  1977. $this->drupalLogin($user1);
  1978. $keys = $user1->mail;
  1979. $edit = array('keys' => $keys);
  1980. $this->drupalPost('search/user/', $edit, t('Search'));
  1981. $this->assertNoText($keys);
  1982. $this->drupalLogout();
  1983. $user2 = $this->drupalCreateUser(array('administer users', 'access user profiles', 'search content', 'use advanced search'));
  1984. $this->drupalLogin($user2);
  1985. $keys = $user2->mail;
  1986. $edit = array('keys' => $keys);
  1987. $this->drupalPost('search/user/', $edit, t('Search'));
  1988. $this->assertText($keys);
  1989. // Verify that wildcard search works.
  1990. $keys = $user1->name;
  1991. $keys = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
  1992. $edit = array('keys' => $keys);
  1993. $this->drupalPost('search/user/', $edit, t('Search'));
  1994. $this->assertText($user1->name, 'Search for username wildcard resulted in user name on page for administrative user.');
  1995. // Verify that wildcard search works for email.
  1996. $keys = $user1->mail;
  1997. $keys = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
  1998. $edit = array('keys' => $keys);
  1999. $this->drupalPost('search/user/', $edit, t('Search'));
  2000. $this->assertText($user1->name, 'Search for email wildcard resulted in user name on page for administrative user.');
  2001. // Create a blocked user.
  2002. $blocked_user = $this->drupalCreateUser();
  2003. $edit = array('status' => 0);
  2004. $blocked_user = user_save($blocked_user, $edit);
  2005. // Verify that users with "administer users" permissions can see blocked
  2006. // accounts in search results.
  2007. $edit = array('keys' => $blocked_user->name);
  2008. $this->drupalPost('search/user/', $edit, t('Search'));
  2009. $this->assertText($blocked_user->name, 'Blocked users are listed on the user search results for users with the "administer users" permission.');
  2010. // Verify that users without "administer users" permissions do not see
  2011. // blocked accounts in search results.
  2012. $this->drupalLogin($user1);
  2013. $edit = array('keys' => $blocked_user->name);
  2014. $this->drupalPost('search/user/', $edit, t('Search'));
  2015. $this->assertNoText($blocked_user->name, 'Blocked users are hidden from the user search results.');
  2016. $this->drupalLogout();
  2017. }
  2018. }
  2019. /**
  2020. * Test role assignment.
  2021. */
  2022. class UserRolesAssignmentTestCase extends DrupalWebTestCase {
  2023. protected $admin_user;
  2024. public static function getInfo() {
  2025. return array(
  2026. 'name' => 'Role assignment',
  2027. 'description' => 'Tests that users can be assigned and unassigned roles.',
  2028. 'group' => 'User'
  2029. );
  2030. }
  2031. function setUp() {
  2032. parent::setUp();
  2033. $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
  2034. $this->drupalLogin($this->admin_user);
  2035. }
  2036. /**
  2037. * Tests that a user can be assigned a role and that the role can be removed
  2038. * again.
  2039. */
  2040. function testAssignAndRemoveRole() {
  2041. $rid = $this->drupalCreateRole(array('administer content types'));
  2042. $account = $this->drupalCreateUser();
  2043. // Assign the role to the user.
  2044. $this->drupalPost('user/' . $account->uid . '/edit', array("roles[$rid]" => $rid), t('Save'));
  2045. $this->assertText(t('The changes have been saved.'));
  2046. $this->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
  2047. $this->userLoadAndCheckRoleAssigned($account, $rid);
  2048. // Remove the role from the user.
  2049. $this->drupalPost('user/' . $account->uid . '/edit', array("roles[$rid]" => FALSE), t('Save'));
  2050. $this->assertText(t('The changes have been saved.'));
  2051. $this->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
  2052. $this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
  2053. }
  2054. /**
  2055. * Tests that when creating a user the role can be assigned. And that it can
  2056. * be removed again.
  2057. */
  2058. function testCreateUserWithRole() {
  2059. $rid = $this->drupalCreateRole(array('administer content types'));
  2060. // Create a new user and add the role at the same time.
  2061. $edit = array(
  2062. 'name' => $this->randomName(),
  2063. 'mail' => $this->randomName() . '@example.com',
  2064. 'pass[pass1]' => $pass = $this->randomString(),
  2065. 'pass[pass2]' => $pass,
  2066. "roles[$rid]" => $rid,
  2067. );
  2068. $this->drupalPost('admin/people/create', $edit, t('Create new account'));
  2069. $this->assertText(t('Created a new user account for !name.', array('!name' => $edit['name'])));
  2070. // Get the newly added user.
  2071. $account = user_load_by_name($edit['name']);
  2072. $this->drupalGet('user/' . $account->uid . '/edit');
  2073. $this->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
  2074. $this->userLoadAndCheckRoleAssigned($account, $rid);
  2075. // Remove the role again.
  2076. $this->drupalPost('user/' . $account->uid . '/edit', array("roles[$rid]" => FALSE), t('Save'));
  2077. $this->assertText(t('The changes have been saved.'));
  2078. $this->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
  2079. $this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
  2080. }
  2081. /**
  2082. * Check role on user object.
  2083. *
  2084. * @param object $account
  2085. * The user account to check.
  2086. * @param string $rid
  2087. * The role ID to search for.
  2088. * @param bool $is_assigned
  2089. * (optional) Whether to assert that $rid exists (TRUE) or not (FALSE).
  2090. * Defaults to TRUE.
  2091. */
  2092. private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) {
  2093. $account = user_load($account->uid, TRUE);
  2094. if ($is_assigned) {
  2095. $this->assertTrue(array_key_exists($rid, $account->roles), 'The role is present in the user object.');
  2096. }
  2097. else {
  2098. $this->assertFalse(array_key_exists($rid, $account->roles), 'The role is not present in the user object.');
  2099. }
  2100. }
  2101. }
  2102. /**
  2103. * Unit test for authmap assignment.
  2104. */
  2105. class UserAuthmapAssignmentTestCase extends DrupalWebTestCase {
  2106. public static function getInfo() {
  2107. return array(
  2108. 'name' => 'Authmap assignment',
  2109. 'description' => 'Tests that users can be assigned and unassigned authmaps.',
  2110. 'group' => 'User'
  2111. );
  2112. }
  2113. /**
  2114. * Test authmap assignment and retrieval.
  2115. */
  2116. function testAuthmapAssignment() {
  2117. $account = $this->drupalCreateUser();
  2118. // Assign authmaps to the user.
  2119. $authmaps = array(
  2120. 'authname_poll' => 'external username one',
  2121. 'authname_book' => 'external username two',
  2122. );
  2123. user_set_authmaps($account, $authmaps);
  2124. // Test for expected authmaps.
  2125. $expected_authmaps = array(
  2126. 'external username one' => array(
  2127. 'poll' => 'external username one',
  2128. ),
  2129. 'external username two' => array(
  2130. 'book' => 'external username two',
  2131. ),
  2132. );
  2133. foreach ($expected_authmaps as $authname => $expected_output) {
  2134. $this->assertIdentical(user_get_authmaps($authname), $expected_output, format_string('Authmap for authname %authname was set correctly.', array('%authname' => $authname)));
  2135. }
  2136. // Remove authmap for module poll, add authmap for module blog.
  2137. $authmaps = array(
  2138. 'authname_poll' => NULL,
  2139. 'authname_blog' => 'external username three',
  2140. );
  2141. user_set_authmaps($account, $authmaps);
  2142. // Assert that external username one does not have authmaps.
  2143. $remove_username = 'external username one';
  2144. unset($expected_authmaps[$remove_username]);
  2145. $this->assertFalse(user_get_authmaps($remove_username), format_string('Authmap for %authname was removed.', array('%authname' => $remove_username)));
  2146. // Assert that a new authmap was created for external username three, and
  2147. // existing authmaps for external username two were unchanged.
  2148. $expected_authmaps['external username three'] = array('blog' => 'external username three');
  2149. foreach ($expected_authmaps as $authname => $expected_output) {
  2150. $this->assertIdentical(user_get_authmaps($authname), $expected_output, format_string('Authmap for authname %authname was set correctly.', array('%authname' => $authname)));
  2151. }
  2152. }
  2153. }
  2154. /**
  2155. * Tests user_validate_current_pass on a custom form.
  2156. */
  2157. class UserValidateCurrentPassCustomForm extends DrupalWebTestCase {
  2158. public static function getInfo() {
  2159. return array(
  2160. 'name' => 'User validate current pass custom form',
  2161. 'description' => 'Test that user_validate_current_pass is usable on a custom form.',
  2162. 'group' => 'User',
  2163. );
  2164. }
  2165. /**
  2166. * User with permission to view content.
  2167. */
  2168. protected $accessUser;
  2169. /**
  2170. * User permission to administer users.
  2171. */
  2172. protected $adminUser;
  2173. function setUp() {
  2174. parent::setUp('user_form_test');
  2175. // Create two users
  2176. $this->accessUser = $this->drupalCreateUser(array('access content'));
  2177. $this->adminUser = $this->drupalCreateUser(array('administer users'));
  2178. }
  2179. /**
  2180. * Tests that user_validate_current_pass can be reused on a custom form.
  2181. */
  2182. function testUserValidateCurrentPassCustomForm() {
  2183. $this->drupalLogin($this->adminUser);
  2184. // Submit the custom form with the admin user using the access user's password.
  2185. $edit = array();
  2186. $edit['user_form_test_field'] = $this->accessUser->name;
  2187. $edit['current_pass'] = $this->accessUser->pass_raw;
  2188. $this->drupalPost('user_form_test_current_password/' . $this->accessUser->uid, $edit, t('Test'));
  2189. $this->assertText(t('The password has been validated and the form submitted successfully.'));
  2190. }
  2191. }