summaryrefslogtreecommitdiff
path: root/modules/user/user.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user/user.test')
-rw-r--r--modules/user/user.test68
1 files changed, 65 insertions, 3 deletions
diff --git a/modules/user/user.test b/modules/user/user.test
index 40e6ec333..2efe5b070 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -1080,6 +1080,50 @@ class UserPictureTestCase extends DrupalWebTestCase {
$this->assertEqual($pic_path, (string) $elements[0]['src'], t("User picture source is correct."));
}
+ /**
+ * Tests deletion of user pictures.
+ */
+ function testDeletePicture() {
+ $this->drupalLogin($this->user);
+
+ $image = current($this->drupalGetTestFiles('image'));
+ $info = image_get_info($image->uri);
+
+ // Set new variables: valid dimensions, valid filesize (0 = no limit).
+ $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
+ variable_set('user_picture_dimensions', $test_dim);
+ variable_set('user_picture_file_size', 0);
+
+ // Save a new picture.
+ $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
+ $this->drupalPost('user/' . $this->user->uid . '/edit', $edit, t('Save'));
+
+ // Load actual user data from database.
+ $account = user_load($this->user->uid, TRUE);
+ $pic_path = isset($account->picture) ? $account->picture->uri : NULL;
+
+ // Check if image is displayed in user's profile page.
+ $this->drupalGet('user');
+ $this->assertRaw(file_uri_target($pic_path), "Image is displayed in user's profile page");
+
+ // Check if file is located in proper directory.
+ $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'));
+
+ // Load actual user data from database.
+ $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');
+
+ // Clear out PHP's file stat cache so we see the current value.
+ 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'));
@@ -1088,6 +1132,24 @@ class UserPictureTestCase extends DrupalWebTestCase {
$account = user_load($this->user->uid, TRUE);
return isset($account->picture) ? $account->picture->uri : NULL;
}
+
+ /**
+ * Tests the admin form validates user picture settings.
+ */
+ function testUserPictureAdminFormValidation() {
+ $this->drupalLogin($this->drupalCreateUser(array('administer users')));
+
+ // The default values are valid.
+ $this->drupalPost('admin/config/people/accounts', array(), t('Save configuration'));
+ $this->assertText(t('The configuration options have been saved.'), 'The default values are valid.');
+
+ // The form does not save with an invalid file size.
+ $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.');
+ }
}
@@ -1385,7 +1447,7 @@ class UserAccountLinksUnitTests extends DrupalWebTestCase {
}
/**
- * Test the user login block.
+ * Tests the secondary menu.
*/
function testSecondaryMenu() {
// Create a regular user.
@@ -1517,7 +1579,7 @@ class UserBlocksUnitTests extends DrupalWebTestCase {
}
/**
- * Test case to test user_save() behaviour.
+ * Tests saving a user account.
*/
class UserSaveTestCase extends DrupalWebTestCase {
@@ -1606,7 +1668,7 @@ class UserCreateTestCase extends DrupalWebTestCase {
}
/**
- * Test case to test user_save() behaviour.
+ * Tests editing a user account.
*/
class UserEditTestCase extends DrupalWebTestCase {