You are here

function UploadPictureTests::testWithoutGDinvalidSize in SimpleTest 6

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

File

tests/upload_tests.test, line 222

Class

UploadPictureTests

Code

function testWithoutGDinvalidSize() {
  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);

      // invalid size
      // 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);
      $edit = array(
        'picture' => $img_path,
      );
      $this
        ->drupalPost('user/' . $user->uid . '/edit', $edit, 'Save');
      $text = t('The uploaded image is too large; the maximum file size is %size kB.', array(
        '%size' => variable_get('user_picture_file_size', '30'),
      ));
      $this
        ->assertWantedText($text, 'Checking response on invalid image size.');

      // 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);
    }
  }
}