function UploadPictureTests::testWithoutGDinvalidDimension in SimpleTest 6
Same name and namespace in other branches
- 5 tests/upload_tests.test \UploadPictureTests::testWithoutGDinvalidDimension()
File
- tests/
upload_tests.test, line 173
Class
Code
function testWithoutGDinvalidDimension() {
if ($this->_directory_test) {
if (!image_get_toolkit()) {
// PREPARE:
$old_pic_set = variable_get('user_pictures', 0);
variable_set('user_pictures', 1);
/* Prepare a user to do the stuff */
$user = $this
->drupalCreateUserRolePerm(array(
'access content',
));
$this
->drupalLoginUser($user);
// changing actual setting;
$old_dim = variable_get('user_picture_dimensions', '85x85');
$old_size = variable_get('user_picture_file_size', '30');
$img_path = realpath("modules/tests/pictureTesting.jpg");
$info = image_get_info($img_path);
// set new variables;
$test_size = floor(filesize($img_path) / 1000) + 1;
$test_dim = $info['width'] - 10 . 'x' . ($info['height'] - 10);
variable_set('user_picture_dimensions', $test_dim);
variable_set('user_picture_file_size', $test_size);
// TEST:
$edit = array(
'picture' => $img_path,
);
$this
->drupalPost('user/' . $user->uid . '/edit', $edit, 'Save');
$text = t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array(
'%dimensions' => variable_get('user_picture_dimensions', '85x85'),
));
$this
->assertWantedText($text, 'Checking response on invalid image (dimensions).');
// check if file is not uploaded
$file_dir = variable_get('file_directory_path', 'files');
$picture_dir = variable_get('user_picture_path', 'pictures');
$pic_path = $file_dir . '/' . $picture_dir . '/picture-' . $user->uid . '.jpg';
$this
->assertFalse(is_file($pic_path), "File is not uploaded");
// restore variables;
variable_set('user_picture_file_size', $old_size);
variable_set('user_picture_dimensions', $old_dim);
variable_set('user_pictures', $old_pic_set);
}
}
}