Commit 72b60ed4 authored by Dries's avatar Dries
Browse files

- Patch #724788 by boombatower: improved code style of some tests in user.test.

parent fb1170e1
......@@ -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.'));
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment