function UploadPictureTests::testPictureIsValid in SimpleTest 6
Same name and namespace in other branches
- 5 tests/upload_tests.test \UploadPictureTests::testPictureIsValid()
File
- tests/
upload_tests.test, line 271
Class
Code
function testPictureIsValid() {
if ($this->_directory_test) {
// 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(drupal_get_path('module', 'simpletest') . "/tests/pictureTesting.jpg");
$info = image_get_info($img_path);
// valid size & dimensions
// restore one and set another
$test_dim = $info['width'] + 10 . 'x' . ($info['height'] + 10);
$test_size = floor(filesize($img_path) / 1000) + 1;
variable_set('user_picture_dimensions', $test_dim);
variable_set('user_picture_file_size', $test_size);
// TEST:
$edit = array(
'files[picture_upload]' => $img_path,
);
$this
->drupalPost('user/' . $user->uid . '/edit', $edit, 'Save');
$picture_dir = variable_get('user_picture_path', 'pictures');
$pic_path = file_directory_path() . '/' . $picture_dir . '/picture-' . $user->uid . '.jpg';
// get full url to the user's image
$picture = file_create_url($pic_path);
// check if image is displayed in user's profile page
$content = $this
->drupalGetContent();
$this
->assertTrue(strpos($content, $picture), "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");
// RESTORING:
variable_set('user_picture_file_size', $old_size);
variable_set('user_picture_dimensions', $old_dim);
variable_set('user_pictures', $old_pic_set);
// DELETING UPLOADED PIC
file_delete($pic_path);
}
}