123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574 |
- <?php
- class UserRegistrationTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User registration',
- 'description' => 'Test registration of user under different configurations.',
- 'group' => 'User'
- );
- }
- function setUp() {
- parent::setUp('field_test');
- }
- function testRegistrationWithEmailVerification() {
-
- variable_set('user_email_verification', TRUE);
-
- variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
- $this->drupalGet('user/register');
- $this->assertResponse(403, 'Registration page is inaccessible when only administrators can create accounts.');
-
- variable_set('user_register', USER_REGISTER_VISITORS);
- $edit = array();
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $this->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), 'User registered successfully.');
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $this->assertTrue($new_user->status, 'New account is active after registration.');
-
- variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
- $edit = array();
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $this->assertFalse($new_user->status, 'New account is blocked until approved by an administrator.');
- }
- function testRegistrationWithoutEmailVerification() {
-
- variable_set('user_email_verification', FALSE);
-
- variable_set('user_register', USER_REGISTER_VISITORS);
- $edit = array();
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
-
- $edit['pass[pass1]'] = '99999.0';
- $edit['pass[pass2]'] = '99999';
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $this->assertText(t('The specified passwords do not match.'), 'Typing mismatched passwords displays an error message.');
-
- $edit['pass[pass1]'] = $new_pass = $this->randomName();
- $edit['pass[pass2]'] = $new_pass;
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.');
- $this->drupalLogout();
-
- variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
- $edit = array();
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
- $edit['pass[pass1]'] = $pass = $this->randomName();
- $edit['pass[pass2]'] = $pass;
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $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');
-
- $auth = array(
- 'name' => $name,
- 'pass' => $pass,
- );
- $this->drupalPost('user/login', $auth, t('Log in'));
- $this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), 'User cannot login yet.');
-
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $admin_user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($admin_user);
- $edit = array(
- 'status' => 1,
- );
- $this->drupalPost('user/' . $new_user->uid . '/edit', $edit, t('Save'));
- $this->drupalLogout();
-
- $this->drupalPost('user/login', $auth, t('Log in'));
- $this->assertText(t('Member for'), 'User can log in after administrator approval.');
- }
- function testRegistrationEmailDuplicates() {
-
- variable_set('user_email_verification', FALSE);
-
- variable_set('user_register', USER_REGISTER_VISITORS);
-
- $duplicate_user = $this->drupalCreateUser();
- $edit = array();
- $edit['name'] = $this->randomName();
- $edit['mail'] = $duplicate_user->mail;
-
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $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');
-
- $edit['mail'] = ' ' . $duplicate_user->mail . ' ';
- $this->drupalPost('user/register', $edit, t('Create new account'));
- $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');
- }
- function testRegistrationDefaultValues() {
-
- variable_set('user_register', USER_REGISTER_VISITORS);
-
- variable_set('user_email_verification', FALSE);
-
- variable_set('configurable_timezones', 1);
- variable_set('date_default_timezone', 'Europe/Brussels');
-
-
- $this->drupalGet('user/register');
- $this->assertNoRaw('<fieldset id="edit-account"><legend>Account information</legend>', 'Account settings fieldset was hidden.');
- $edit = array();
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
- $edit['pass[pass1]'] = $new_pass = $this->randomName();
- $edit['pass[pass2]'] = $new_pass;
- $this->drupalPost(NULL, $edit, t('Create new account'));
-
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $this->assertEqual($new_user->name, $name, 'Username matches.');
- $this->assertEqual($new_user->mail, $mail, 'E-mail address matches.');
- $this->assertEqual($new_user->theme, '', 'Correct theme field.');
- $this->assertEqual($new_user->signature, '', 'Correct signature field.');
- $this->assertTrue(($new_user->created > REQUEST_TIME - 20 ), 'Correct creation time.');
- $this->assertEqual($new_user->status, variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
- $this->assertEqual($new_user->timezone, variable_get('date_default_timezone'), 'Correct time zone field.');
- $this->assertEqual($new_user->language, '', 'Correct language field.');
- $this->assertEqual($new_user->picture, '', 'Correct picture field.');
- $this->assertEqual($new_user->init, $mail, 'Correct init field.');
- }
-
- function testRegistrationWithUserFields() {
-
- $field = array(
- 'type' => 'test_field',
- 'field_name' => 'test_user_field',
- 'cardinality' => 1,
- );
- field_create_field($field);
- $instance = array(
- 'field_name' => 'test_user_field',
- 'entity_type' => 'user',
- 'label' => 'Some user field',
- 'bundle' => 'user',
- 'required' => TRUE,
- 'settings' => array('user_register_form' => FALSE),
- );
- field_create_instance($instance);
-
- $this->drupalGet('user/register');
- $this->assertNoText($instance['label'], 'The field does not appear on user registration form');
-
- $instance['settings']['user_register_form'] = TRUE;
- field_update_instance($instance);
- $this->drupalGet('user/register');
- $this->assertText($instance['label'], 'The field appears on user registration form');
-
- $edit = array();
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
-
- $edit['test_user_field[und][0][value]'] = '';
- $this->drupalPost(NULL, $edit, t('Create new account'));
- $this->assertRaw(t('@name field is required.', array('@name' => $instance['label'])), 'Field validation error was correctly reported.');
-
- $edit['test_user_field[und][0][value]'] = '-1';
- $this->drupalPost(NULL, $edit, t('Create new account'));
- $this->assertRaw(t('%name does not accept the value -1.', array('%name' => $instance['label'])), 'Field validation error was correctly reported.');
-
- $value = rand(1, 255);
- $edit['test_user_field[und][0][value]'] = $value;
- $this->drupalPost(NULL, $edit, t('Create new account'));
-
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $this->assertEqual($new_user->test_user_field[LANGUAGE_NONE][0]['value'], $value, 'The field value was correctly saved.');
-
- $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED;
- field_update_field($field);
- foreach (array('js', 'nojs') as $js) {
- $this->drupalGet('user/register');
-
- $value = rand(1, 255);
- $edit = array();
- $edit['test_user_field[und][0][value]'] = $value;
- if ($js == 'js') {
- $this->drupalPostAJAX(NULL, $edit, 'test_user_field_add_more');
- $this->drupalPostAJAX(NULL, $edit, 'test_user_field_add_more');
- }
- else {
- $this->drupalPost(NULL, $edit, t('Add another item'));
- $this->drupalPost(NULL, $edit, t('Add another item'));
- }
-
- $edit['test_user_field[und][1][value]'] = $value + 1;
- $edit['test_user_field[und][2][value]'] = $value + 2;
- $edit['name'] = $name = $this->randomName();
- $edit['mail'] = $mail = $edit['name'] . '@example.com';
- $this->drupalPost(NULL, $edit, t('Create new account'));
-
- $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
- $new_user = reset($accounts);
- $this->assertEqual($new_user->test_user_field[LANGUAGE_NONE][0]['value'], $value, format_string('@js : The field value was correclty saved.', array('@js' => $js)));
- $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)));
- $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)));
- }
- }
- }
- class UserValidationTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Username/e-mail validation',
- 'description' => 'Verify that username/email validity checks behave as designed.',
- 'group' => 'User'
- );
- }
-
- function testUsernames() {
- $test_cases = array(
- 'foo' => array('Valid username', 'assertNull'),
- 'FOO' => array('Valid username', 'assertNull'),
- 'Foo O\'Bar' => array('Valid username', 'assertNull'),
- 'foo@bar' => array('Valid username', 'assertNull'),
- 'foo@example.com' => array('Valid username', 'assertNull'),
- 'foo@-example.com' => array('Valid username', 'assertNull'),
- 'þòøÇߪř€' => array('Valid username', 'assertNull'),
- 'ᚠᛇᚻ᛫ᛒᛦᚦ' => array('Valid UTF8 username', 'assertNull'),
- ' foo' => array('Invalid username that starts with a space', 'assertNotNull'),
- 'foo ' => array('Invalid username that ends with a space', 'assertNotNull'),
- 'foo bar' => array('Invalid username that contains 2 spaces \' \'', 'assertNotNull'),
- '' => array('Invalid empty username', 'assertNotNull'),
- 'foo/' => array('Invalid username containing invalid chars', 'assertNotNull'),
- 'foo' . chr(0) . 'bar' => array('Invalid username containing chr(0)', 'assertNotNull'),
- 'foo' . chr(13) . 'bar' => array('Invalid username containing chr(13)', 'assertNotNull'),
- str_repeat('x', USERNAME_MAX_LENGTH + 1) => array('Invalid excessively long username', 'assertNotNull'),
- );
- foreach ($test_cases as $name => $test_case) {
- list($description, $test) = $test_case;
- $result = user_validate_name($name);
- $this->$test($result, $description . ' (' . $name . ')');
- }
- }
-
- function testMailAddresses() {
- $test_cases = array(
- '' => array('Empty mail address', 'assertNotNull'),
- 'foo' => array('Invalid mail address', 'assertNotNull'),
- 'foo@example.com' => array('Valid mail address', 'assertNull'),
- );
- foreach ($test_cases as $name => $test_case) {
- list($description, $test) = $test_case;
- $result = user_validate_mail($name);
- $this->$test($result, $description . ' (' . $name . ')');
- }
- }
- }
- class UserLoginTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User login',
- 'description' => 'Ensure that login works as expected.',
- 'group' => 'User',
- );
- }
-
- function testGlobalLoginFloodControl() {
-
- variable_set('user_failed_login_ip_limit', 10);
-
- variable_set('user_failed_login_user_limit', 4000);
- $user1 = $this->drupalCreateUser(array());
- $incorrect_user1 = clone $user1;
- $incorrect_user1->pass_raw .= 'incorrect';
-
- for ($i = 0; $i < 2; $i++) {
- $this->assertFailedLogin($incorrect_user1);
- }
-
- $this->drupalLogin($user1);
- $this->drupalLogout();
-
-
- for ($i = 0; $i < 8; $i++) {
- $this->assertFailedLogin($incorrect_user1);
- }
-
- $this->assertFailedLogin($incorrect_user1, 'ip');
-
-
- $this->assertFailedLogin($user1, 'ip');
- }
-
- function testPerUserLoginFloodControl() {
-
- variable_set('user_failed_login_ip_limit', 4000);
-
- variable_set('user_failed_login_user_limit', 3);
- $user1 = $this->drupalCreateUser(array());
- $incorrect_user1 = clone $user1;
- $incorrect_user1->pass_raw .= 'incorrect';
- $user2 = $this->drupalCreateUser(array());
-
- for ($i = 0; $i < 2; $i++) {
- $this->assertFailedLogin($incorrect_user1);
- }
-
- $this->drupalLogin($user1);
- $this->drupalLogout();
-
- for ($i = 0; $i < 3; $i++) {
- $this->assertFailedLogin($incorrect_user1);
- }
-
-
- $this->drupalLogin($user2);
- $this->drupalLogout();
-
-
- $this->assertFailedLogin($user1, 'user');
- }
-
- function testPasswordRehashOnLogin() {
-
- require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
-
- variable_set('password_count_log2', DRUPAL_HASH_COUNT);
-
- $account = $this->drupalCreateUser(array());
- $password = $account->pass_raw;
- $this->drupalLogin($account);
- $this->drupalLogout();
-
- $account = user_load($account->uid);
- $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT);
-
- variable_set('password_count_log2', DRUPAL_HASH_COUNT + 1);
- $account->pass_raw = $password;
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
- $this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_HASH_COUNT + 1);
- }
-
- function assertFailedLogin($account, $flood_trigger = NULL) {
- $edit = array(
- 'name' => $account->name,
- 'pass' => $account->pass_raw,
- );
- $this->drupalPost('user', $edit, t('Log in'));
- $this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.');
- if (isset($flood_trigger)) {
- if ($flood_trigger == 'user') {
- $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'))));
- }
- else {
-
- $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'))));
- }
- }
- else {
- $this->assertText(t('Sorry, unrecognized username or password. Have you forgotten your password?'));
- }
- }
- }
- class UserPasswordResetTestCase extends DrupalWebTestCase {
- protected $profile = 'standard';
- public static function getInfo() {
- return array(
- 'name' => 'Reset password',
- 'description' => 'Ensure that password reset methods work as expected.',
- 'group' => 'User',
- );
- }
-
- function testUserPasswordReset() {
-
- $account = $this->drupalCreateUser();
- $this->drupalLogin($account);
- $this->drupalLogout();
-
- $edit = array('name' => $account->name);
- $this->drupalPost('user/password', $edit, t('E-mail new password'));
-
- $this->assertText(t('Further instructions have been sent to your e-mail address.'), 'Password reset instructions mailed message displayed.');
- }
-
- function testUserPasswordResetLoggedIn() {
- $account = $this->drupalCreateUser();
- $this->drupalLogin($account);
-
- user_save($account, array('pass' => user_password()));
-
- $reset_url = user_pass_reset_url($account);
- $this->drupalGet($reset_url);
- $this->assertText('Reset password');
- $this->drupalPost(NULL, NULL, t('Log in'));
- $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.');
- $pass = user_password();
- $edit = array(
- 'pass[pass1]' => $pass,
- 'pass[pass2]' => $pass,
- );
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertText('The changes have been saved.');
- }
-
- function testUserPasswordResetExpired() {
-
- $timeout = 43200;
- variable_set('user_password_reset_timeout', $timeout);
-
- $account = $this->drupalCreateUser();
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
- $this->drupalLogout();
-
-
- $bogus_timestamp = REQUEST_TIME - variable_get('user_password_reset_timeout', 86400) - 60;
- $this->drupalGet("user/reset/$account->uid/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid));
- $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.');
- }
-
- function testUserPasswordTextboxFilled() {
- $this->drupalGet('user/login');
- $edit = array(
- 'name' => $this->randomName(),
- 'pass' => $this->randomName(),
- );
- $this->drupalPost('user', $edit, t('Log in'));
- $this->assertRaw(t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>',
- array('@password' => url('user/password', array('query' => array('name' => $edit['name']))))));
- unset($edit['pass']);
- $this->drupalGet('user/password', array('query' => array('name' => $edit['name'])));
- $this->assertFieldByName('name', $edit['name'], 'User name found.');
- }
-
- function testResetImpersonation() {
-
-
- $account = user_load(1);
- user_save($account, array('pass' => user_password()));
-
-
- $edit = array();
- $edit['name'] = $this->randomName();
- $edit['mail'] = $edit['name'] . '@example.com';
- $edit['status'] = 1;
- $user1 = user_save(drupal_anonymous_user(), $edit);
- $edit['name'] = $this->randomName();
- $user2 = user_save(drupal_anonymous_user(), $edit);
-
-
- $reset_url = user_pass_reset_url($user1);
- $attack_reset_url = str_replace("user/reset/$user1->uid", "user/reset/$user2->uid", $reset_url);
- $this->drupalGet($attack_reset_url);
- $this->assertNoText($user2->name, 'The invalid password reset page does not show the user name.');
- $this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
- $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.');
-
-
-
-
- $timestamp = REQUEST_TIME;
-
-
-
- $reset_url_token = user_pass_rehash($user1->pass, $timestamp, $user1->login, NULL);
- $reset_url = url("user/reset/$user1->uid/$timestamp/$reset_url_token", array('absolute' => TRUE));
- $this->drupalGet($reset_url);
- $this->assertNoText($user1->name, 'The invalid password reset page does not show the user name.');
- $this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
- $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.');
- $attack_reset_url = str_replace("user/reset/$user1->uid", "user/reset/$user2->uid", $reset_url);
- $this->drupalGet($attack_reset_url);
- $this->assertNoText($user2->name, 'The invalid password reset page does not show the user name.');
- $this->assertUrl('user/password', array(), 'The user is redirected to the password reset request page.');
- $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.');
-
-
-
-
- $new_reset_url_token = user_pass_rehash($user1->pass, $timestamp, $user1->login, NULL);
- $this->assertNotEqual($reset_url_token, $new_reset_url_token);
-
-
- user_delete($user2->uid);
- $reset_url_token = user_pass_rehash($user1->pass, $timestamp, $user1->login, NULL);
- $reset_url = url("user/reset/$user1->uid/$timestamp/$reset_url_token", array('absolute' => TRUE));
- $this->drupalGet($reset_url);
- $this->assertText($user1->name, 'The valid password reset page shows the user name.');
- $this->assertUrl($reset_url, array(), 'The user remains on the password reset login page.');
- $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.');
- }
- }
- class UserCancelTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Cancel account',
- 'description' => 'Ensure that account cancellation methods work as expected.',
- 'group' => 'User',
- );
- }
- function setUp() {
- parent::setUp('comment');
- }
-
- function testUserCancelWithoutPermission() {
- variable_set('user_cancel_method', 'user_cancel_reassign');
-
- $account = $this->drupalCreateUser(array());
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
-
- $node = $this->drupalCreateNode(array('uid' => $account->uid));
-
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->assertNoRaw(t('Cancel account'), 'No cancel account button displayed.');
-
- $timestamp = $account->login;
- $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
- $this->assertResponse(403, 'Bogus cancelling request rejected.');
- $account = user_load($account->uid);
- $this->assertTrue($account->status == 1, 'User account was not canceled.');
-
- $test_node = node_load($node->nid, NULL, TRUE);
- $this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), 'Node of the user has not been altered.');
- }
-
- function testUserCancelUid1() {
-
- $password = user_password();
- require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
- $account = array(
- 'name' => 'user1',
- 'pass' => user_hash_password(trim($password)),
- );
-
- db_update('users')
- ->fields($account)
- ->condition('uid', 1)
- ->execute();
-
- $user1 = user_load(1, TRUE);
- $user1->pass_raw = $password;
-
- $this->admin_user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($this->admin_user);
- $edit = array(
- 'operation' => 'cancel',
- 'accounts[1]' => TRUE,
- );
- $this->drupalPost('admin/people', $edit, t('Update'));
-
- $user1 = user_load(1, TRUE);
- $this->assertEqual($user1->status, 1, 'User #1 still exists and is not blocked.');
- }
-
- function testUserCancelInvalid() {
- variable_set('user_cancel_method', 'user_cancel_reassign');
-
- $account = $this->drupalCreateUser(array('cancel account'));
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
-
- $node = $this->drupalCreateNode(array('uid' => $account->uid));
-
- $this->drupalPost('user/' . $account->uid . '/edit', NULL, t('Cancel account'));
-
- $timestamp = time();
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
-
- $bogus_timestamp = $timestamp + 60;
- $this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid));
- $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.');
- $account = user_load($account->uid);
- $this->assertTrue($account->status == 1, 'User account was not canceled.');
-
- $bogus_timestamp = $timestamp - 86400 - 60;
- $this->drupalGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid));
- $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.');
- $accounts = user_load_multiple(array($account->uid), array('status' => 1));
- $this->assertTrue(reset($accounts), 'User account was not canceled.');
-
- $test_node = node_load($node->nid, NULL, TRUE);
- $this->assertTrue(($test_node->uid == $account->uid && $test_node->status == 1), 'Node of the user has not been altered.');
- }
-
- function testUserBlock() {
- variable_set('user_cancel_method', 'user_cancel_block');
-
- $web_user = $this->drupalCreateUser(array('cancel account'));
- $this->drupalLogin($web_user);
-
- $account = user_load($web_user->uid, TRUE);
-
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
- $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.');
- $this->assertNoText(t('Select the method to cancel the account above.'), 'Does not allow user to select account cancellation method.');
-
- $timestamp = time();
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
-
- $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
- $account = user_load($account->uid, TRUE);
- $this->assertTrue($account->status == 0, 'User has been blocked.');
-
- $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user.");
- }
-
- function testUserBlockUnpublish() {
- variable_set('user_cancel_method', 'user_cancel_block_unpublish');
-
- $account = $this->drupalCreateUser(array('cancel account'));
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
-
- $node = $this->drupalCreateNode(array('uid' => $account->uid));
- $settings = get_object_vars($node);
- $settings['revision'] = 1;
- $node = $this->drupalCreateNode($settings);
-
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
- $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.');
-
- $timestamp = time();
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
-
- $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
- $account = user_load($account->uid, TRUE);
- $this->assertTrue($account->status == 0, 'User has been blocked.');
-
- $test_node = node_load($node->nid, NULL, TRUE);
- $this->assertTrue($test_node->status == 0, 'Node of the user has been unpublished.');
- $test_node = node_load($node->nid, $node->vid, TRUE);
- $this->assertTrue($test_node->status == 0, 'Node revision of the user has been unpublished.');
-
- $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user.");
- }
-
- function testUserAnonymize() {
- variable_set('user_cancel_method', 'user_cancel_reassign');
-
- $account = $this->drupalCreateUser(array('cancel account'));
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
-
- $node = $this->drupalCreateNode(array('uid' => $account->uid));
-
-
- $revision_node = $this->drupalCreateNode(array('uid' => $account->uid));
- $revision = $revision_node->vid;
- $settings = get_object_vars($revision_node);
- $settings['revision'] = 1;
- $settings['uid'] = 1;
- $revision_node = $this->drupalCreateNode($settings);
-
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
- $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.');
-
- $timestamp = time();
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
-
- $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
- $this->assertFalse(user_load($account->uid, TRUE), 'User is not found in the database.');
-
- $test_node = node_load($node->nid, NULL, TRUE);
- $this->assertTrue(($test_node->uid == 0 && $test_node->status == 1), 'Node of the user has been attributed to anonymous user.');
- $test_node = node_load($revision_node->nid, $revision, TRUE);
- $this->assertTrue(($test_node->revision_uid == 0 && $test_node->status == 1), 'Node revision of the user has been attributed to anonymous user.');
- $test_node = node_load($revision_node->nid, NULL, TRUE);
- $this->assertTrue(($test_node->uid != 0 && $test_node->status == 1), "Current revision of the user's node was not attributed to anonymous user.");
-
- $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user.");
- }
-
- function testUserDelete() {
- variable_set('user_cancel_method', 'user_cancel_delete');
-
- $account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
- $this->drupalLogin($account);
-
- $account = user_load($account->uid, TRUE);
-
- $node = $this->drupalCreateNode(array('uid' => $account->uid));
-
- $langcode = LANGUAGE_NONE;
- $edit = array();
- $edit['subject'] = $this->randomName(8);
- $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
- $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview'));
- $this->drupalPost(NULL, array(), t('Save'));
- $this->assertText(t('Your comment has been posted.'));
- $comments = comment_load_multiple(array(), array('subject' => $edit['subject']));
- $comment = reset($comments);
- $this->assertTrue($comment->cid, 'Comment found.');
-
-
- $revision_node = $this->drupalCreateNode(array('uid' => $account->uid));
- $revision = $revision_node->vid;
- $settings = get_object_vars($revision_node);
- $settings['revision'] = 1;
- $settings['uid'] = 1;
- $revision_node = $this->drupalCreateNode($settings);
-
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
- $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.');
-
- $timestamp = time();
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
-
- $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
- $this->assertFalse(user_load($account->uid, TRUE), 'User is not found in the database.');
-
- $this->assertFalse(node_load($node->nid, NULL, TRUE), 'Node of the user has been deleted.');
- $this->assertFalse(node_load($node->nid, $revision, TRUE), 'Node revision of the user has been deleted.');
- $this->assertTrue(node_load($revision_node->nid, NULL, TRUE), "Current revision of the user's node was not deleted.");
- $this->assertFalse(comment_load($comment->cid), 'Comment of the user has been deleted.');
-
- $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user.");
- }
-
- function testUserCancelByAdmin() {
- variable_set('user_cancel_method', 'user_cancel_reassign');
-
- $account = $this->drupalCreateUser(array());
-
- $admin_user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($admin_user);
-
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->name)), 'Confirmation form to cancel account displayed.');
- $this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
-
- $this->drupalPost(NULL, NULL, t('Cancel account'));
- $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), 'User deleted.');
- $this->assertFalse(user_load($account->uid), 'User is not found in the database.');
- }
-
- function testMassUserCancelByAdmin() {
- variable_set('user_cancel_method', 'user_cancel_reassign');
-
- variable_set('user_mail_status_canceled_notify', TRUE);
-
- $admin_user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($admin_user);
-
- $users = array();
- for ($i = 0; $i < 3; $i++) {
- $account = $this->drupalCreateUser(array());
- $users[$account->uid] = $account;
- }
-
- $edit = array();
- $edit['operation'] = 'cancel';
- foreach ($users as $uid => $account) {
- $edit['accounts[' . $uid . ']'] = TRUE;
- }
- $edit['accounts[' . $admin_user->uid . ']'] = TRUE;
-
- $edit['accounts[1]'] = TRUE;
- $this->drupalPost('admin/people', $edit, t('Update'));
- $this->assertText(t('Are you sure you want to cancel these user accounts?'), 'Confirmation form to cancel accounts displayed.');
- $this->assertText(t('When cancelling these accounts'), 'Allows to select account cancellation method.');
- $this->assertText(t('Require e-mail confirmation to cancel account.'), 'Allows to send confirmation mail.');
- $this->assertText(t('Notify user when account is canceled.'), 'Allows to send notification mail.');
-
- $this->drupalPost(NULL, NULL, t('Cancel accounts'));
- $status = TRUE;
- foreach ($users as $account) {
- $status = $status && (strpos($this->content, t('%name has been deleted.', array('%name' => $account->name))) !== FALSE);
- $status = $status && !user_load($account->uid, TRUE);
- }
- $this->assertTrue($status, 'Users deleted and not found in the database.');
-
- $this->assertText(t('A confirmation request to cancel your account has been sent to your e-mail address.'), 'Account cancellation request mailed message displayed.');
- $admin_user = user_load($admin_user->uid);
- $this->assertTrue($admin_user->status == 1, 'Administrative user is found in the database and enabled.');
-
- $user1 = user_load(1, TRUE);
- $this->assertEqual($user1->status, 1, 'User #1 still exists and is not blocked.');
- }
- }
- class UserPictureTestCase extends DrupalWebTestCase {
- protected $user;
- protected $_directory_test;
- public static function getInfo() {
- return array(
- 'name' => 'Upload user picture',
- 'description' => 'Assure that dimension check, extension check and image scaling work as designed.',
- 'group' => 'User'
- );
- }
- function setUp() {
- parent::setUp();
-
- variable_set('user_pictures', 1);
- $this->user = $this->drupalCreateUser();
-
- $file_dir = 'public://';
- $file_check = file_prepare_directory($file_dir, FILE_CREATE_DIRECTORY);
-
- $picture_dir = variable_get('user_picture_path', 'pictures');
- $picture_path = $file_dir . $picture_dir;
- $pic_check = file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY);
- $this->_directory_test = is_writable($picture_path);
- $this->assertTrue($this->_directory_test, "The directory $picture_path doesn't exist or is not writable. Further tests won't be made.");
- }
- function testNoPicture() {
- $this->drupalLogin($this->user);
-
- $not_an_image = current($this->drupalGetTestFiles('html'));
- $this->saveUserPicture($not_an_image);
- $this->assertRaw(t('Only JPEG, PNG and GIF images are allowed.'), 'Non-image files are not accepted.');
- }
-
- function testWithGDinvalidDimension() {
- if ($this->_directory_test && image_get_toolkit()) {
- $this->drupalLogin($this->user);
- $image = current($this->drupalGetTestFiles('image'));
- $info = image_get_info($image->uri);
-
- $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10);
- variable_set('user_picture_dimensions', $test_dim);
- variable_set('user_picture_file_size', 0);
- $pic_path = $this->saveUserPicture($image);
-
-
- $text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim));
- $this->assertRaw($text, 'Image was resized.');
- $alt = t("@user's picture", array('@user' => format_username($this->user)));
- $style = variable_get('user_picture_style', '');
- $this->assertRaw(check_plain(image_style_url($style, $pic_path)), "Image is displayed in user's edit page");
-
- $this->assertTrue(is_file($pic_path), "File is located in proper directory");
- }
- }
-
- function testWithGDinvalidSize() {
- if ($this->_directory_test && image_get_toolkit()) {
- $this->drupalLogin($this->user);
-
-
- $files = $this->drupalGetTestFiles('image');
- $image = end($files);
- $info = image_get_info($image->uri);
-
- $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
- $test_size = 1;
- variable_set('user_picture_dimensions', $test_dim);
- variable_set('user_picture_file_size', $test_size);
- $pic_path = $this->saveUserPicture($image);
-
- $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
- $this->assertRaw($text, 'Upload failed.');
- $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)));
- $this->assertRaw($text, 'File size cited as reason for failure.');
-
- $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
- }
- }
-
- function testWithoutGDinvalidDimension() {
- if ($this->_directory_test && !image_get_toolkit()) {
- $this->drupalLogin($this->user);
- $image = current($this->drupalGetTestFiles('image'));
- $info = image_get_info($image->uri);
-
- $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10);
- variable_set('user_picture_dimensions', $test_dim);
- variable_set('user_picture_file_size', 0);
- $pic_path = $this->saveUserPicture($image);
-
- $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
- $this->assertRaw($text, 'Upload failed.');
- $text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim));
- $this->assertRaw($text, 'Checking response on invalid image (dimensions).');
-
- $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
- }
- }
-
- function testWithoutGDinvalidSize() {
- if ($this->_directory_test && !image_get_toolkit()) {
- $this->drupalLogin($this->user);
- $image = current($this->drupalGetTestFiles('image'));
- $info = image_get_info($image->uri);
-
- $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
- $test_size = 1;
- variable_set('user_picture_dimensions', $test_dim);
- variable_set('user_picture_file_size', $test_size);
- $pic_path = $this->saveUserPicture($image);
-
- $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
- $this->assertRaw($text, 'Upload failed.');
- $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)));
- $this->assertRaw($text, 'File size cited as reason for failure.');
-
- $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
- }
- }
-
- function testPictureIsValid() {
- if ($this->_directory_test) {
- $this->drupalLogin($this->user);
- $image = current($this->drupalGetTestFiles('image'));
- $info = image_get_info($image->uri);
-
- $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
- variable_set('user_picture_dimensions', $test_dim);
- variable_set('user_picture_file_size', 0);
- $pic_path = $this->saveUserPicture($image);
-
- $this->drupalGet('user');
- $this->assertRaw(file_uri_target($pic_path), "Image is displayed in user's profile page");
-
- $this->assertTrue(is_file($pic_path), 'File is located in proper directory');
-
- $test_dim = ($info['width'] + 5) . 'x' . ($info['height'] + 5);
- variable_set('user_picture_dimensions', $test_dim);
- $pic_path2 = $this->saveUserPicture($image);
- $this->assertNotEqual($pic_path, $pic_path2, 'Filename of second picture is different.');
-
- $account = user_load($this->user->uid, TRUE);
- $this->assertTrue(is_object($account->picture), 'User picture object is valid after user load.');
- $this->assertNotNull($account->picture->fid, 'User picture object has a FID after user load.');
- $this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user load.');
- user_save($account);
-
- $this->assertTrue(is_object($account->picture), 'User picture object is valid after user save.');
- $this->assertNotNull($account->picture->fid, 'User picture object has a FID after user save.');
- $this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user save.');
- }
- }
-
- function testExternalPicture() {
- $this->drupalLogin($this->user);
-
- $images = $this->drupalGetTestFiles('image');
- $image = $images[0];
- $pic_path = file_create_url($image->uri);
- variable_set('user_picture_default', $pic_path);
-
- $this->drupalGet('user');
-
- $elements = $this->xpath('//div[@class="user-picture"]/img');
- $this->assertEqual(count($elements), 1, "There is exactly one user picture on the user's profile page");
- $this->assertEqual($pic_path, (string) $elements[0]['src'], "User picture source is correct.");
- }
-
- function testDeletePicture() {
- $this->drupalLogin($this->user);
- $image = current($this->drupalGetTestFiles('image'));
- $info = image_get_info($image->uri);
-
- $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
- variable_set('user_picture_dimensions', $test_dim);
- variable_set('user_picture_file_size', 0);
-
- $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
- $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
-
- $account = user_load($this->user->uid, TRUE);
- $pic_path = isset($account->picture) ? $account->picture->uri : NULL;
-
- $this->drupalGet('user');
- $this->assertRaw(file_uri_target($pic_path), "Image is displayed in user's profile page");
-
- $this->assertTrue(is_file($pic_path), 'File is located in proper directory');
- $edit = array('picture_delete' => 1);
- $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
-
- $account1 = user_load($this->user->uid, TRUE);
- $this->assertNull($account1->picture, 'User object has no picture');
- $file = file_load($account->picture->fid);
- $this->assertFalse($file, 'File is removed from database');
-
- clearstatcache();
- $this->assertFalse(is_file($pic_path), 'File is removed from file system');
- }
- function saveUserPicture($image) {
- $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
- $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
-
- $account = user_load($this->user->uid, TRUE);
- return isset($account->picture) ? $account->picture->uri : NULL;
- }
-
- function testUserPictureAdminFormValidation() {
- $this->drupalLogin($this->drupalCreateUser(array('administer users')));
-
- $this->drupalPost('admin/config/people/accounts', array(), t('Save configuration'));
- $this->assertText(t('The configuration options have been saved.'), 'The default values are valid.');
-
- $edit = array(
- 'user_picture_file_size' => $this->randomName(),
- );
- $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
- $this->assertNoText(t('The configuration options have been saved.'), 'The form does not save with an invalid file size.');
- }
- }
- class UserPermissionsTestCase extends DrupalWebTestCase {
- protected $admin_user;
- protected $rid;
- public static function getInfo() {
- return array(
- 'name' => 'Role permissions',
- 'description' => 'Verify that role permissions can be added and removed via the permissions page.',
- 'group' => 'User'
- );
- }
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer users'));
-
- $all_rids = array_keys($this->admin_user->roles);
- sort($all_rids);
- $this->rid = array_pop($all_rids);
- }
-
- function testUserPermissionChanges() {
- $this->drupalLogin($this->admin_user);
- $rid = $this->rid;
- $account = $this->admin_user;
-
- $this->assertFalse(user_access('administer nodes', $account), 'User does not have "administer nodes" permission.');
- $edit = array();
- $edit[$rid . '[administer nodes]'] = TRUE;
- $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
- $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
- drupal_static_reset('user_access');
- drupal_static_reset('user_role_permissions');
- $this->assertTrue(user_access('administer nodes', $account), 'User now has "administer nodes" permission.');
-
- $this->assertTrue(user_access('access user profiles', $account), 'User has "access user profiles" permission.');
- $edit = array();
- $edit[$rid . '[access user profiles]'] = FALSE;
- $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
- $this->assertText(t('The changes have been saved.'), 'Successful save message displayed.');
- drupal_static_reset('user_access');
- drupal_static_reset('user_role_permissions');
- $this->assertFalse(user_access('access user profiles', $account), 'User no longer has "access user profiles" permission.');
- }
-
- function testAdministratorRole() {
- $this->drupalLogin($this->admin_user);
- $this->drupalGet('admin/config/people/accounts');
-
- $edit = array();
- $edit['user_admin_role'] = $this->rid;
- $this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
-
-
- $edit = array();
- $edit['modules[Core][aggregator][enable]'] = TRUE;
- $this->drupalPost('admin/modules', $edit, t('Save configuration'));
- $this->assertTrue(user_access('administer news feeds', $this->admin_user), 'The permission was automatically assigned to the administrator role');
- }
-
- function testUserRoleChangePermissions() {
- $rid = $this->rid;
- $account = $this->admin_user;
-
- $this->assertFalse(user_access('administer nodes', $account), 'User does not have "administer nodes" permission.');
- $this->assertTrue(user_access('access user profiles', $account), 'User has "access user profiles" permission.');
- $this->assertTrue(user_access('administer site configuration', $account), 'User has "administer site configuration" permission.');
-
- $permissions = array(
- 'administer nodes' => 1,
- 'access user profiles' => 0,
- );
- user_role_change_permissions($rid, $permissions);
-
- $this->assertTrue(user_access('administer nodes', $account), 'User now has "administer nodes" permission.');
- $this->assertFalse(user_access('access user profiles', $account), 'User no longer has "access user profiles" permission.');
- $this->assertTrue(user_access('administer site configuration', $account), 'User still has "administer site configuration" permission.');
- }
- }
- class UserAdminTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User administration',
- 'description' => 'Test user administration page functionality.',
- 'group' => 'User'
- );
- }
-
- function testUserAdmin() {
- $user_a = $this->drupalCreateUser(array());
- $user_b = $this->drupalCreateUser(array('administer taxonomy'));
- $user_c = $this->drupalCreateUser(array('administer taxonomy'));
-
- $admin_user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($admin_user);
- $this->drupalGet('admin/people');
- $this->assertText($user_a->name, 'Found user A on admin users page');
- $this->assertText($user_b->name, 'Found user B on admin users page');
- $this->assertText($user_c->name, 'Found user C on admin users page');
- $this->assertText($admin_user->name, 'Found Admin user on admin users page');
-
- $link = l(t('edit'), "user/$user_a->uid/edit", array('query' => array('destination' => 'admin/people')));
- $this->assertRaw($link, 'Found user A edit link on admin users page');
-
- $edit = array();
- $edit['permission'] = 'administer taxonomy';
- $this->drupalPost('admin/people', $edit, t('Filter'));
-
- $this->assertNoText($user_a->name, 'User A not on filtered by perm admin users page');
- $this->assertText($user_b->name, 'Found user B on filtered by perm admin users page');
- $this->assertText($user_c->name, 'Found user C on filtered by perm admin users page');
-
- $edit['role'] = max(array_flip($user_c->roles));
- $this->drupalPost('admin/people', $edit, t('Refine'));
-
- $this->assertNoText($user_a->name, 'User A not on filtered by role on admin users page');
- $this->assertNoText($user_b->name, 'User B not on filtered by role on admin users page');
- $this->assertText($user_c->name, 'User C on filtered by role on admin users page');
-
- $account = user_load($user_c->uid);
- $this->assertEqual($account->status, 1, 'User C not blocked');
- $edit = array();
- $edit['operation'] = 'block';
- $edit['accounts[' . $account->uid . ']'] = TRUE;
- $this->drupalPost('admin/people', $edit, t('Update'));
- $account = user_load($user_c->uid, TRUE);
- $this->assertEqual($account->status, 0, 'User C blocked');
-
- $editunblock = array();
- $editunblock['operation'] = 'unblock';
- $editunblock['accounts[' . $account->uid . ']'] = TRUE;
- $this->drupalPost('admin/people', $editunblock, t('Update'));
- $account = user_load($user_c->uid, TRUE);
- $this->assertEqual($account->status, 1, 'User C unblocked');
- $this->assertMail("to", $account->mail, "Activation mail sent to user C");
-
- $user_d = $this->drupalCreateUser(array());
- $account1 = user_load($user_d->uid, TRUE);
- $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => 0), t('Save'));
- $account1 = user_load($user_d->uid, TRUE);
- $this->assertEqual($account1->status, 0, 'User D blocked');
- $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => TRUE), t('Save'));
- $account1 = user_load($user_d->uid, TRUE);
- $this->assertEqual($account1->status, 1, 'User D unblocked');
- $this->assertMail("to", $account1->mail, "Activation mail sent to user D");
- }
- }
- class UserTimeZoneFunctionalTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User time zones',
- 'description' => 'Set a user time zone and verify that dates are displayed in local time.',
- 'group' => 'User',
- );
- }
-
- function testUserTimeZone() {
-
- variable_set('date_default_timezone', 'America/Los_Angeles');
- variable_set('configurable_timezones', 1);
- variable_set('date_format_medium', 'Y-m-d H:i T');
-
- $web_user = $this->drupalCreateUser();
- $this->drupalLogin($web_user);
-
-
- $date1 = '2007-03-09 21:00:00 -0800';
- $date2 = '2007-03-11 01:00:00 -0800';
-
- $date3 = '2007-03-20 21:00:00 -0700';
- $node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article'));
- $node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article'));
- $node3 = $this->drupalCreateNode(array('created' => strtotime($date3), 'type' => 'article'));
-
- $this->drupalGet("node/$node1->nid");
- $this->assertText('2007-03-09 21:00 PST', 'Date should be PST.');
- $this->drupalGet("node/$node2->nid");
- $this->assertText('2007-03-11 01:00 PST', 'Date should be PST.');
- $this->drupalGet("node/$node3->nid");
- $this->assertText('2007-03-20 21:00 PDT', 'Date should be PDT.');
-
- $edit = array();
- $edit['mail'] = $web_user->mail;
- $edit['timezone'] = 'America/Santiago';
- $this->drupalPost("user/$web_user->uid/edit", $edit, t('Save'));
- $this->assertText(t('The changes have been saved.'), 'Time zone changed to Santiago time.');
-
- $this->drupalGet("node/$node1->nid");
- $this->assertText('2007-03-10 02:00 CLST', 'Date should be Chile summer time; five hours ahead of PST.');
- $this->drupalGet("node/$node2->nid");
- $this->assertText('2007-03-11 05:00 CLT', 'Date should be Chile time; four hours ahead of PST');
- $this->drupalGet("node/$node3->nid");
- $this->assertText('2007-03-21 00:00 CLT', 'Date should be Chile time; three hours ahead of PDT.');
- }
- }
- class UserAutocompleteTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User autocompletion',
- 'description' => 'Test user autocompletion functionality.',
- 'group' => 'User'
- );
- }
- function setUp() {
- parent::setUp();
-
- $this->unprivileged_user = $this->drupalCreateUser();
- $this->privileged_user = $this->drupalCreateUser(array('access user profiles'));
- }
-
- function testUserAutocomplete() {
-
- $this->drupalLogin($this->unprivileged_user);
- $this->drupalGet('user/autocomplete/' . $this->unprivileged_user->name[0]);
- $this->assertResponse(403, 'Autocompletion access denied to user without permission.');
-
- $this->drupalLogout();
- $this->drupalLogin($this->privileged_user);
- $this->drupalGet('user/autocomplete/' . $this->unprivileged_user->name[0]);
- $this->assertResponse(200, 'Autocompletion access allowed.');
-
- $this->assertRaw($this->unprivileged_user->name, 'User name found in autocompletion results.');
- }
- }
- class UserAccountLinksUnitTests extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User account links',
- 'description' => 'Test user-account links.',
- 'group' => 'User'
- );
- }
- function setUp() {
- parent::setUp('menu');
- }
-
- function testSecondaryMenu() {
-
- $user = $this->drupalCreateUser(array());
-
- $this->drupalLogin($user);
- $this->drupalGet('<front>');
-
-
- $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
- ':menu_id' => 'secondary-menu-links',
- ':href' => 'user',
- ':text' => 'My account',
- ));
- $this->assertEqual(count($link), 1, 'My account link is in secondary menu.');
- $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
- ':menu_id' => 'secondary-menu-links',
- ':href' => 'user/logout',
- ':text' => 'Log out',
- ));
- $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.');
-
- $this->drupalLogout();
- $this->drupalGet('<front>');
-
- $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu-links'));
- $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
- }
-
- function testDisabledAccountLink() {
-
- $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));
-
- $this->drupalGet('admin/structure/menu/manage/user-menu');
- $label = $this->xpath('//label[contains(.,:text)]/@for', array(':text' => 'Enable My account menu link'));
- $this->assertFieldChecked((string) $label[0], "The 'My account' link is enabled by default.");
-
- $input = $this->xpath('//input[@id=:field_id]/@name', array(':field_id' => (string)$label[0]));
- $edit = array(
- (string) $input[0] => FALSE,
- );
- $this->drupalPost('admin/structure/menu/manage/user-menu', $edit, t('Save configuration'));
-
- $this->drupalGet('<front>');
-
- $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
- ':menu_id' => 'secondary-menu-links',
- ':href' => 'user',
- ':text' => 'My account',
- ));
- $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.');
- }
- }
- class UserBlocksUnitTests extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User blocks',
- 'description' => 'Test user blocks.',
- 'group' => 'User'
- );
- }
-
- function testUserLoginBlock() {
-
- $user = $this->drupalCreateUser(array('administer permissions'));
-
- $edit = array();
- $edit['name'] = $user->name;
- $edit['pass'] = $user->pass_raw;
- $this->drupalPost('admin/people/permissions', $edit, t('Log in'));
- $this->assertNoText(t('User login'), 'Logged in.');
-
- $this->assertEqual(url('admin/people/permissions', array('absolute' => TRUE)), $this->getUrl(), 'Still on the same page after login for access denied page');
-
- $this->drupalLogout();
- $this->drupalPost('filter/tips', $edit, t('Log in'));
- $this->assertNoText(t('User login'), 'Logged in.');
- $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
-
-
- $this->drupalLogout();
- $this->drupalPost('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
-
- $this->assertEqual(url('user/' . $user->uid, array('absolute' => TRUE)), $this->getUrl(), 'Redirected to user profile page after login from the frontpage');
- }
-
- function testWhosOnlineBlock() {
-
- $user1 = $this->drupalCreateUser(array());
- $user2 = $this->drupalCreateUser(array());
- $user3 = $this->drupalCreateUser(array());
- $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions}")->fetchField(), 0, 'Sessions table is empty.');
-
- $this->insertSession(array('uid' => $user1->uid));
- $this->insertSession(array('uid' => $user1->uid));
- $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid", array(':uid' => $user1->uid))->fetchField(), 2, 'Duplicate user session has been inserted.');
-
- $this->insertSession(array('uid' => $user2->uid, 'timestamp' => REQUEST_TIME + 1));
-
- $this->insertSession(array('uid' => $user3->uid, 'timestamp' => (REQUEST_TIME - variable_get('user_block_seconds_online', 900) - 1)));
-
- $this->insertSession();
- $this->insertSession();
-
- $block = user_block_view('online');
- $this->drupalSetContent($block['content']);
- $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).');
- $this->assertText($user1->name, 'Active user 1 found in online list.');
- $this->assertText($user2->name, 'Active user 2 found in online list.');
- $this->assertNoText($user3->name, "Inactive user not found in online list.");
- $this->assertTrue(strpos($this->drupalGetContent(), $user1->name) > strpos($this->drupalGetContent(), $user2->name), 'Online users are ordered correctly.');
- }
-
- private function insertSession(array $fields = array()) {
- $fields += array(
- 'uid' => 0,
- 'sid' => drupal_hash_base64(uniqid(mt_rand(), TRUE)),
- 'timestamp' => REQUEST_TIME,
- );
- db_insert('sessions')
- ->fields($fields)
- ->execute();
- $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.');
- }
- }
- class UserSaveTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User save test',
- 'description' => 'Test user_save() for arbitrary new uid.',
- 'group' => 'User',
- );
- }
-
- function testUserImport() {
-
- $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField();
- $test_uid = $max_uid + mt_rand(1000, 1000000);
- $test_name = $this->randomName();
-
- $user = array(
- 'name' => $test_name,
- 'uid' => $test_uid,
- 'mail' => $test_name . '@example.com',
- 'is_new' => TRUE,
- 'pass' => user_password(),
- 'status' => 1,
- );
- $user_by_return = user_save(drupal_anonymous_user(), $user);
- $this->assertTrue($user_by_return, 'Loading user by return of user_save().');
-
- $user_by_uid = user_load($test_uid);
- $this->assertTrue($user_by_uid, 'Loading user by uid.');
- $user_by_name = user_load_by_name($test_name);
- $this->assertTrue($user_by_name, 'Loading user by name.');
- }
- }
- class UserCreateTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User create',
- 'description' => 'Test the create user administration page.',
- 'group' => 'User',
- );
- }
-
- protected function testUserAdd() {
- $user = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($user);
- foreach (array(FALSE, TRUE) as $notify) {
- $edit = array(
- 'name' => $this->randomName(),
- 'mail' => $this->randomName() . '@example.com',
- 'pass[pass1]' => $pass = $this->randomString(),
- 'pass[pass2]' => $pass,
- 'notify' => $notify,
- );
- $this->drupalPost('admin/people/create', $edit, t('Create new account'));
- if ($notify) {
- $this->assertText(t('A welcome message with further instructions has been e-mailed to the new user @name.', array('@name' => $edit['name'])), 'User created');
- $this->assertEqual(count($this->drupalGetMails()), 1, 'Notification e-mail sent');
- }
- else {
- $this->assertText(t('Created a new user account for @name. No e-mail has been sent.', array('@name' => $edit['name'])), 'User created');
- $this->assertEqual(count($this->drupalGetMails()), 0, 'Notification e-mail not sent');
- }
- $this->drupalGet('admin/people');
- $this->assertText($edit['name'], 'User found in list of users');
- }
-
- $name = $this->randomName();
- $edit = array(
- 'name' => $name,
- 'mail' => $name . '@example.com',
- 'pass[pass1]' => 0,
- 'pass[pass2]' => 0,
- 'notify' => FALSE,
- );
- $this->drupalPost('admin/people/create', $edit, t('Create new account'));
- $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');
- $this->assertNoText('Password field is required');
- }
- }
- class UserEditTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User edit',
- 'description' => 'Test user edit page.',
- 'group' => 'User',
- );
- }
-
- function testUserEdit() {
-
- variable_set('user_pictures', 0);
- $user1 = $this->drupalCreateUser(array('change own username'));
- $user2 = $this->drupalCreateUser(array());
- $this->drupalLogin($user1);
-
- $edit['name'] = $user2->name;
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name'])));
-
- variable_set('user_pictures', 1);
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t('The name %name is already taken.', array('%name' => $edit['name'])));
-
- $edit = array();
- $edit['pass[pass1]'] = '';
- $edit['pass[pass2]'] = $this->randomName();
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertText(t("The specified passwords do not match."), 'Typing mismatched passwords displays an error message.');
- $edit['pass[pass1]'] = $this->randomName();
- $edit['pass[pass2]'] = '';
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertText(t("The specified passwords do not match."), 'Typing mismatched passwords displays an error message.');
-
-
- $edit = array();
- $edit['mail'] = $this->randomName() . '@new.example.com';
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => t('E-mail address'))));
- $edit['current_pass'] = $user1->pass_raw;
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
-
- $edit = array();
- $edit['pass[pass1]'] = $new_pass = $this->randomName();
- $edit['pass[pass2]'] = $new_pass;
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => t('Password'))));
-
- $edit['current_pass'] = $user1->pass_raw;
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
-
- $this->drupalLogout();
- $user1->pass_raw = $new_pass;
- $this->drupalLogin($user1);
- $this->drupalLogout();
- }
-
- public function testUserWith0Password() {
- $admin = $this->drupalCreateUser(array('administer users'));
- $this->drupalLogin($admin);
-
- $user1 = $this->drupalCreateUser(array());
- $edit = array('pass[pass1]' => '0', 'pass[pass2]' => '0');
- $this->drupalPost("user/" . $user1->uid . "/edit", $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
- $this->drupalLogout();
- $user1->pass_raw = '0';
- $this->drupalLogin($user1);
- $this->drupalLogout();
- }
- }
- class UserEditRebuildTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User edit with form rebuild',
- 'description' => 'Test user edit page when a form rebuild is triggered.',
- 'group' => 'User',
- );
- }
- function setUp() {
- parent::setUp('user_form_test');
- }
-
- function testUserEditFormRebuild() {
- $user1 = $this->drupalCreateUser(array('change own username'));
- $this->drupalLogin($user1);
- $roles = array_keys($user1->roles);
-
- $edit = array();
- $edit['current_pass'] = $user1->pass_raw;
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
- $saved_user1 = entity_load_unchanged('user', $user1->uid);
- $this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.');
- $diff = array_diff(array_keys($saved_user1->roles), $roles);
- $this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles))));
-
- variable_set('user_form_test_user_profile_form_rebuild', TRUE);
- $this->drupalPost("user/$user1->uid/edit", $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
- $this->drupalPost(NULL, $edit, t('Save'));
- $this->assertRaw(t("The changes have been saved."));
- $saved_user1 = entity_load_unchanged('user', $user1->uid);
- $this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.');
- $diff = array_diff(array_keys($saved_user1->roles), $roles);
- $this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles))));
- }
- }
- class UserSignatureTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User signatures',
- 'description' => 'Test user signatures.',
- 'group' => 'User',
- );
- }
- function setUp() {
- parent::setUp('comment');
-
- variable_set('user_signatures', 1);
-
- $this->full_html_format = filter_format_load('full_html');
- $this->plain_text_format = filter_format_load('plain_text');
-
- $this->web_user = $this->drupalCreateUser(array());
- $admin_permissions = array('administer comments');
- foreach (filter_formats() as $format) {
- if ($permission = filter_permission_name($format)) {
- $admin_permissions[] = $permission;
- }
- }
- $this->admin_user = $this->drupalCreateUser($admin_permissions);
- }
-
- function testUserSignature() {
-
- $node = $this->drupalCreateNode(array('comment' => COMMENT_NODE_OPEN));
-
- $this->drupalGet('user/register');
- $this->assertNoText(t('Signature'));
-
- $this->drupalLogin($this->web_user);
- $signature_text = "<h1>" . $this->randomName() . "</h1>";
- $edit = array(
- 'signature[value]' => $signature_text,
- 'signature[format]' => $this->plain_text_format->format,
- );
- $this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
-
- $this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');
- $this->assertFieldByName('signature[format]', $edit['signature[format]'], 'Submitted signature format found.');
-
- $langcode = LANGUAGE_NONE;
- $edit = array();
- $edit['subject'] = $this->randomName(8);
- $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
- $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Preview'));
- $this->drupalPost(NULL, array(), t('Save'));
-
-
- preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
- $comment_id = $match[1];
-
-
- $this->drupalLogin($this->admin_user);
- $edit['comment_body[' . $langcode . '][0][format]'] = $this->full_html_format->format;
- $this->drupalPost('comment/' . $comment_id . '/edit', $edit, t('Save'));
-
- $this->drupalGet('node/' . $node->nid);
- $this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
- $this->assertRaw(check_markup($signature_text, $this->plain_text_format->format), 'Filtered signature text found.');
- }
- }
- class UserEditedOwnAccountTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User edited own account',
- 'description' => 'Test user edited own account can still log in.',
- 'group' => 'User',
- );
- }
- function testUserEditedOwnAccount() {
-
-
- variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
-
- $account = $this->drupalCreateUser(array('change own username'));
- $this->drupalLogin($account);
-
- $edit = array();
- $edit['name'] = $this->randomName();
- $this->drupalPost('user/' . $account->uid . '/edit', $edit, t('Save'));
-
- $this->drupalLogout();
-
- $account->name = $edit['name'];
- $this->drupalLogin($account);
- }
- }
- class UserRoleAdminTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User role administration',
- 'description' => 'Test adding, editing and deleting user roles and changing role weights.',
- 'group' => 'User',
- );
- }
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
- }
-
- function testRoleAdministration() {
- $this->drupalLogin($this->admin_user);
-
-
-
- $role_name = '123';
- $edit = array('name' => $role_name);
- $this->drupalPost('admin/people/permissions/roles', $edit, t('Add role'));
- $this->assertText(t('The role has been added.'), 'The role has been added.');
- $role = user_role_load_by_name($role_name);
- $this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.');
-
- $this->drupalPost(NULL, $edit, t('Add role'));
- $this->assertRaw(t('The role name %name already exists. Choose another role name.', array('%name' => $role_name)), 'Duplicate role warning displayed.');
-
- $old_name = $role_name;
- $role_name = '456';
- $edit = array('name' => $role_name);
- $this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", $edit, t('Save role'));
- $this->assertText(t('The role has been renamed.'), 'The role has been renamed.');
- $this->assertFalse(user_role_load_by_name($old_name), 'The role can no longer be retrieved from the database using its old name.');
- $this->assertTrue(is_object(user_role_load_by_name($role_name)), 'The role can be retrieved from the database using its new name.');
-
- $role_name = 'administrator';
- $role = user_role_load_by_name($role_name);
- $this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", NULL, t('Delete role'));
- $this->drupalPost(NULL, NULL, t('Delete'));
- $this->assertText(t('The role has been deleted.'), 'The role has been deleted');
- $this->assertNoLinkByHref("admin/people/permissions/roles/edit/{$role->rid}", 'Role edit link removed.');
- $this->assertFalse(user_role_load_by_name($role_name), 'A deleted role can no longer be loaded.');
-
- $this->assertNull(variable_get('user_admin_role'), 'The administrator role is no longer configured as the administrator role.');
-
-
- $this->drupalGet('admin/people/permissions/roles/edit/' . DRUPAL_ANONYMOUS_RID);
- $this->assertResponse(403, 'Access denied when trying to edit the built-in anonymous role.');
- $this->drupalGet('admin/people/permissions/roles/edit/' . DRUPAL_AUTHENTICATED_RID);
- $this->assertResponse(403, 'Access denied when trying to edit the built-in authenticated role.');
- }
-
- function testRoleWeightChange() {
- $this->drupalLogin($this->admin_user);
-
- $rid = array_rand(user_roles());
- $role = user_role_load($rid);
- $old_weight = $role->weight;
-
- $edit = array('roles['. $rid .'][weight]' => $old_weight + 1);
- $this->drupalPost('admin/people/permissions/roles', $edit, t('Save order'));
- $this->assertText(t('The role settings have been updated.'), 'The role settings form submitted successfully.');
-
- $role = user_role_load($rid);
- $new_weight = $role->weight;
- $this->assertTrue(($old_weight + 1) == $new_weight, 'Role weight updated successfully.');
- }
- }
- class UserTokenReplaceTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User token replacement',
- 'description' => 'Generates text using placeholders for dummy content to check user token replacement.',
- 'group' => 'User',
- );
- }
-
- function testUserTokenReplacement() {
- global $language;
- $url_options = array(
- 'absolute' => TRUE,
- 'language' => $language,
- );
-
- $user1 = $this->drupalCreateUser(array());
- $user2 = $this->drupalCreateUser(array());
- $this->drupalLogin($user1);
- $this->drupalLogout();
- $this->drupalLogin($user2);
- $account = user_load($user1->uid);
- $global_account = user_load($GLOBALS['user']->uid);
-
- $tests = array();
- $tests['[user:uid]'] = $account->uid;
- $tests['[user:name]'] = check_plain(format_username($account));
- $tests['[user:mail]'] = check_plain($account->mail);
- $tests['[user:url]'] = url("user/$account->uid", $url_options);
- $tests['[user:edit-url]'] = url("user/$account->uid/edit", $url_options);
- $tests['[user:last-login]'] = format_date($account->login, 'medium', '', NULL, $language->language);
- $tests['[user:last-login:short]'] = format_date($account->login, 'short', '', NULL, $language->language);
- $tests['[user:created]'] = format_date($account->created, 'medium', '', NULL, $language->language);
- $tests['[user:created:short]'] = format_date($account->created, 'short', '', NULL, $language->language);
- $tests['[current-user:name]'] = check_plain(format_username($global_account));
-
- $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('user' => $account), array('language' => $language));
- $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input)));
- }
-
- $tests['[user:name]'] = format_username($account);
- $tests['[user:mail]'] = $account->mail;
- $tests['[current-user:name]'] = format_username($global_account);
- foreach ($tests as $input => $expected) {
- $output = token_replace($input, array('user' => $account), array('language' => $language, 'sanitize' => FALSE));
- $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input)));
- }
- }
- }
- class UserUserSearchTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User search',
- 'description' => 'Tests the user search page and verifies that sensitive information is hidden from unauthorized users.',
- 'group' => 'User',
- );
- }
- function testUserSearch() {
- $user1 = $this->drupalCreateUser(array('access user profiles', 'search content', 'use advanced search'));
- $this->drupalLogin($user1);
- $keys = $user1->mail;
- $edit = array('keys' => $keys);
- $this->drupalPost('search/user/', $edit, t('Search'));
- $this->assertNoText($keys);
- $this->drupalLogout();
- $user2 = $this->drupalCreateUser(array('administer users', 'access user profiles', 'search content', 'use advanced search'));
- $this->drupalLogin($user2);
- $keys = $user2->mail;
- $edit = array('keys' => $keys);
- $this->drupalPost('search/user/', $edit, t('Search'));
- $this->assertText($keys);
-
- $keys = $user1->name;
- $keys = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
- $edit = array('keys' => $keys);
- $this->drupalPost('search/user/', $edit, t('Search'));
- $this->assertText($user1->name, 'Search for username wildcard resulted in user name on page for administrative user.');
-
- $keys = $user1->mail;
- $keys = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
- $edit = array('keys' => $keys);
- $this->drupalPost('search/user/', $edit, t('Search'));
- $this->assertText($user1->name, 'Search for email wildcard resulted in user name on page for administrative user.');
-
- $blocked_user = $this->drupalCreateUser();
- $edit = array('status' => 0);
- $blocked_user = user_save($blocked_user, $edit);
-
-
- $edit = array('keys' => $blocked_user->name);
- $this->drupalPost('search/user/', $edit, t('Search'));
- $this->assertText($blocked_user->name, 'Blocked users are listed on the user search results for users with the "administer users" permission.');
-
-
- $this->drupalLogin($user1);
- $edit = array('keys' => $blocked_user->name);
- $this->drupalPost('search/user/', $edit, t('Search'));
- $this->assertNoText($blocked_user->name, 'Blocked users are hidden from the user search results.');
- $this->drupalLogout();
- }
- }
- class UserRolesAssignmentTestCase extends DrupalWebTestCase {
- protected $admin_user;
- public static function getInfo() {
- return array(
- 'name' => 'Role assignment',
- 'description' => 'Tests that users can be assigned and unassigned roles.',
- 'group' => 'User'
- );
- }
- function setUp() {
- parent::setUp();
- $this->admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
- $this->drupalLogin($this->admin_user);
- }
-
- function testAssignAndRemoveRole() {
- $rid = $this->drupalCreateRole(array('administer content types'));
- $account = $this->drupalCreateUser();
-
- $this->drupalPost('user/' . $account->uid . '/edit', array("roles[$rid]" => $rid), t('Save'));
- $this->assertText(t('The changes have been saved.'));
- $this->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
- $this->userLoadAndCheckRoleAssigned($account, $rid);
-
- $this->drupalPost('user/' . $account->uid . '/edit', array("roles[$rid]" => FALSE), t('Save'));
- $this->assertText(t('The changes have been saved.'));
- $this->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
- $this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
- }
-
- function testCreateUserWithRole() {
- $rid = $this->drupalCreateRole(array('administer content types'));
-
- $edit = array(
- 'name' => $this->randomName(),
- 'mail' => $this->randomName() . '@example.com',
- 'pass[pass1]' => $pass = $this->randomString(),
- 'pass[pass2]' => $pass,
- "roles[$rid]" => $rid,
- );
- $this->drupalPost('admin/people/create', $edit, t('Create new account'));
- $this->assertText(t('Created a new user account for !name.', array('!name' => $edit['name'])));
-
- $account = user_load_by_name($edit['name']);
- $this->drupalGet('user/' . $account->uid . '/edit');
- $this->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
- $this->userLoadAndCheckRoleAssigned($account, $rid);
-
- $this->drupalPost('user/' . $account->uid . '/edit', array("roles[$rid]" => FALSE), t('Save'));
- $this->assertText(t('The changes have been saved.'));
- $this->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
- $this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
- }
-
- private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) {
- $account = user_load($account->uid, TRUE);
- if ($is_assigned) {
- $this->assertTrue(array_key_exists($rid, $account->roles), 'The role is present in the user object.');
- }
- else {
- $this->assertFalse(array_key_exists($rid, $account->roles), 'The role is not present in the user object.');
- }
- }
- }
- class UserAuthmapAssignmentTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Authmap assignment',
- 'description' => 'Tests that users can be assigned and unassigned authmaps.',
- 'group' => 'User'
- );
- }
-
- function testAuthmapAssignment() {
- $account = $this->drupalCreateUser();
-
- $authmaps = array(
- 'authname_poll' => 'external username one',
- 'authname_book' => 'external username two',
- );
- user_set_authmaps($account, $authmaps);
-
- $expected_authmaps = array(
- 'external username one' => array(
- 'poll' => 'external username one',
- ),
- 'external username two' => array(
- 'book' => 'external username two',
- ),
- );
- foreach ($expected_authmaps as $authname => $expected_output) {
- $this->assertIdentical(user_get_authmaps($authname), $expected_output, format_string('Authmap for authname %authname was set correctly.', array('%authname' => $authname)));
- }
-
- $authmaps = array(
- 'authname_poll' => NULL,
- 'authname_blog' => 'external username three',
- );
- user_set_authmaps($account, $authmaps);
-
- $remove_username = 'external username one';
- unset($expected_authmaps[$remove_username]);
- $this->assertFalse(user_get_authmaps($remove_username), format_string('Authmap for %authname was removed.', array('%authname' => $remove_username)));
-
-
- $expected_authmaps['external username three'] = array('blog' => 'external username three');
- foreach ($expected_authmaps as $authname => $expected_output) {
- $this->assertIdentical(user_get_authmaps($authname), $expected_output, format_string('Authmap for authname %authname was set correctly.', array('%authname' => $authname)));
- }
- }
- }
- class UserValidateCurrentPassCustomForm extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'User validate current pass custom form',
- 'description' => 'Test that user_validate_current_pass is usable on a custom form.',
- 'group' => 'User',
- );
- }
-
- protected $accessUser;
-
- protected $adminUser;
- function setUp() {
- parent::setUp('user_form_test');
-
- $this->accessUser = $this->drupalCreateUser(array('access content'));
- $this->adminUser = $this->drupalCreateUser(array('administer users'));
- }
-
- function testUserValidateCurrentPassCustomForm() {
- $this->drupalLogin($this->adminUser);
-
- $edit = array();
- $edit['user_form_test_field'] = $this->accessUser->name;
- $edit['current_pass'] = $this->accessUser->pass_raw;
- $this->drupalPost('user_form_test_current_password/' . $this->accessUser->uid, $edit, t('Test'));
- $this->assertText(t('The password has been validated and the form submitted successfully.'));
- }
- }
|