1.20.x user.test UserPictureTestCase::testWithGDinvalidSize()

Do the test: GD Toolkit is installed Picture has invalid size

results: The image should be uploaded because ImageGDToolkit resizes the picture

File

modules/user/tests/user.test, line 1055
Tests for user.module.

Class

UserPictureTestCase

Code

function testWithGDinvalidSize() {
  if ($this->_directory_test && image_get_toolkit()) {
    $this->backdropLogin($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->backdropGetTestFiles('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;
    config('system.core')
      ->set('user_picture_dimensions', $test_dim)
      ->set('user_picture_file_size', $test_size)
      ->save();

    $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, '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, 'File size cited as reason for failure.');

    // Check if file is not uploaded.
    $this->assertFalse(is_file($pic_path), 'File was not uploaded.');
  }
}