diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-02-25 10:00:38 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-02-25 10:00:38 +0000 |
commit | 72b60ed444c3318abbbe338c37d50486bab4ff6a (patch) | |
tree | fe664036a1cde2fc047586978b4b468f80405851 /modules/user/user.test | |
parent | fb1170e13b0ae16517e0bef643546c2e1a1a91c2 (diff) | |
download | brdo-72b60ed444c3318abbbe338c37d50486bab4ff6a.tar.gz brdo-72b60ed444c3318abbbe338c37d50486bab4ff6a.tar.bz2 |
- Patch #724788 by boombatower: improved code style of some tests in user.test.
Diffstat (limited to 'modules/user/user.test')
-rw-r--r-- | modules/user/user.test | 164 |
1 files changed, 79 insertions, 85 deletions
diff --git a/modules/user/user.test b/modules/user/user.test index f3387069d..8ee7629b7 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -762,30 +762,29 @@ class UserPictureTestCase extends DrupalWebTestCase { * results: The image should be uploaded because ImageGDToolkit resizes the picture */ function testWithGDinvalidDimension() { - if ($this->_directory_test) - if (image_get_toolkit()) { - $this->drupalLogin($this->user); - - $image = current($this->drupalGetTestFiles('image')); - $info = image_get_info($image->uri); - - // Set new variables: invalid 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); - - $pic_path = $this->saveUserPicture($image); - // Check that the image was resized and is being displayed on the - // user's profile page. - $text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim)); - $this->assertRaw($text, t('Image was resized.')); - $alt = t("@user's picture", array('@user' => format_username($this->user))); - $style = variable_get('user_picture_style', ''); - $this->assertRaw(image_style_url($style, $pic_path), t("Image is displayed in user's edit page")); - - // Check if file is located in proper directory. - $this->assertTrue(is_file($pic_path), t("File is located in proper directory")); - } + if ($this->_directory_test && image_get_toolkit()) { + $this->drupalLogin($this->user); + + $image = current($this->drupalGetTestFiles('image')); + $info = image_get_info($image->uri); + + // Set new variables: invalid 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); + + $pic_path = $this->saveUserPicture($image); + // Check that the image was resized and is being displayed on the + // user's profile page. + $text = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $test_dim)); + $this->assertRaw($text, t('Image was resized.')); + $alt = t("@user's picture", array('@user' => format_username($this->user))); + $style = variable_get('user_picture_style', ''); + $this->assertRaw(image_style_url($style, $pic_path), t("Image is displayed in user's edit page")); + + // Check if file is located in proper directory. + $this->assertTrue(is_file($pic_path), t("File is located in proper directory")); + } } /** @@ -796,34 +795,32 @@ class UserPictureTestCase extends DrupalWebTestCase { * results: The image should be uploaded because ImageGDToolkit resizes the picture */ function testWithGDinvalidSize() { - if ($this->_directory_test) - if (image_get_toolkit()) { - - $this->drupalLogin($this->user); + if ($this->_directory_test && image_get_toolkit()) { + $this->drupalLogin($this->user); - // Images are sorted first by size then by name. We need an image - // bigger than 1 KB so we'll grab the last one. - $files = $this->drupalGetTestFiles('image'); - $image = end($files); - $info = image_get_info($image->uri); + // Images are sorted first by size then by name. We need an image + // bigger than 1 KB so we'll grab the last one. + $files = $this->drupalGetTestFiles('image'); + $image = end($files); + $info = image_get_info($image->uri); - // Set new variables: valid dimensions, invalid filesize. - $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); + // Set new variables: valid dimensions, invalid filesize. + $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); + $pic_path = $this->saveUserPicture($image); - // Test that the upload failed and that the correct reason was cited. - $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); - $this->assertRaw($text, t('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, t('File size cited as reason for failure.')); + // Test that the upload failed and that the correct reason was cited. + $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); + $this->assertRaw($text, t('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, t('File size cited as reason for failure.')); - // Check if file is not uploaded. - $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); - } + // Check if file is not uploaded. + $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); + } } /** @@ -834,30 +831,28 @@ class UserPictureTestCase extends DrupalWebTestCase { * results: The image shouldn't be uploaded */ function testWithoutGDinvalidDimension() { - if ($this->_directory_test) - if (!image_get_toolkit()) { - - $this->drupalLogin($this->user); + if ($this->_directory_test && !image_get_toolkit()) { + $this->drupalLogin($this->user); - $image = current($this->drupalGetTestFiles('image')); - $info = image_get_info($image->uri); + $image = current($this->drupalGetTestFiles('image')); + $info = image_get_info($image->uri); - // Set new variables: invalid 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); + // Set new variables: invalid 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); - $pic_path = $this->saveUserPicture($image); + $pic_path = $this->saveUserPicture($image); - // Test that the upload failed and that the correct reason was cited. - $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); - $this->assertRaw($text, t('Upload failed.')); - $text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim)); - $this->assertRaw($text, t('Checking response on invalid image (dimensions).')); + // Test that the upload failed and that the correct reason was cited. + $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); + $this->assertRaw($text, t('Upload failed.')); + $text = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $test_dim)); + $this->assertRaw($text, t('Checking response on invalid image (dimensions).')); - // Check if file is not uploaded. - $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); - } + // Check if file is not uploaded. + $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); + } } /** @@ -868,30 +863,29 @@ class UserPictureTestCase extends DrupalWebTestCase { * results: The image shouldn't be uploaded */ function testWithoutGDinvalidSize() { - if ($this->_directory_test) - if (!image_get_toolkit()) { - $this->drupalLogin($this->user); + if ($this->_directory_test && !image_get_toolkit()) { + $this->drupalLogin($this->user); - $image = current($this->drupalGetTestFiles('image')); - $info = image_get_info($image->uri); + $image = current($this->drupalGetTestFiles('image')); + $info = image_get_info($image->uri); - // Set new variables: valid dimensions, invalid filesize. - $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); + // Set new variables: valid dimensions, invalid filesize. + $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); + $pic_path = $this->saveUserPicture($image); - // Test that the upload failed and that the correct reason was cited. - $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); - $this->assertRaw($text, t('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, t('File size cited as reason for failure.')); + // Test that the upload failed and that the correct reason was cited. + $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename)); + $this->assertRaw($text, t('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, t('File size cited as reason for failure.')); - // Check if file is not uploaded. - $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); - } + // Check if file is not uploaded. + $this->assertFalse(is_file($pic_path), t('File was not uploaded.')); + } } /** |