You are here

function UploadPictureTests::testWithGDinvalidSize in SimpleTest 6

Same name and namespace in other branches
  1. 5 tests/upload_tests.test \UploadPictureTests::testWithGDinvalidSize()

File

tests/upload_tests.test, line 117

Class

UploadPictureTests

Code

function testWithGDinvalidSize() {
  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_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(
        'picture' => $img_path,
      );
      $this
        ->drupalPost('user/' . $user->uid . '/edit', $edit, 'Save');
      $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';

      // 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->_browser
        ->getContent();
      $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);
    }
  }
}