diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index 39e0d50..ea13176 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -28,19 +28,22 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { */ public function testDefaultImages() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); - // Create files to use as the default images. - $files = $this->drupalGetTestFiles('image'); - // Create 10 files so the default image fids are not a single value. + + // Create 10 file entities so the default image fids are not a single + // value. for ($i = 1; $i <= 10; $i++) { $filename = $this->randomMachineName() . "$i"; $desired_filepath = 'public://' . $filename; - file_unmanaged_copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR); + file_unmanaged_copy($this->drupalGetTestImageFile()->uri, $desired_filepath, FILE_EXISTS_ERROR); $file = entity_create('file', array('uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename)); $file->save(); } + + // Create file entities to use as the default images. + $files = ['image-1.png', 'image-test.jpg', 'image-2.jpg', 'image-test-no-transparency.gif', 'image-test-transparent-out-of-range.gif']; $default_images = array(); foreach (array('field', 'field', 'field2', 'field_new', 'field_new') as $image_target) { - $file = entity_create('file', (array) array_pop($files)); + $file = entity_create('file', (array) $this->drupalGetTestImageFile(array_shift($files))); $file->save(); $default_images[$image_target] = $file; } diff --git a/core/modules/image/src/Tests/ImageFieldValidateTest.php b/core/modules/image/src/Tests/ImageFieldValidateTest.php index 2552248..f659e3b 100644 --- a/core/modules/image/src/Tests/ImageFieldValidateTest.php +++ b/core/modules/image/src/Tests/ImageFieldValidateTest.php @@ -20,39 +20,28 @@ function testValid() { $field_name = strtolower($this->randomMachineName()); $this->createImageField($field_name, 'article', array(), array()); - // Get test image files. - foreach ($this->drupalGetTestFiles('image') as $image) { - if ($image->filename == 'image-1.png') { - $valid = $image; - } - if ($image->filename == 'image-zero-size.png') { - $zero = $image; - } - if ($image->filename == 'image-invalid.png') { - $invalid = $image; - } - } - // Create alt text for the image. $alt = $this->randomMachineName(); - // Create node with valid image. - $node = $this->uploadNodeImage($valid, $field_name, 'article', $alt); + // Create a node with a valid image. + $node = $this->uploadNodeImage($this->drupalGetTestImageFile('image-1.png'), $field_name, 'article', $alt); // Remove the image. $this->drupalPostForm('node/' . $node . '/edit', array(), t('Remove')); $this->drupalPostForm(NULL, array(), t('Save and keep published')); // Try uploading a zero-byte image. + $zero_size_image = $this->drupalGetTestImageFile('image-zero-size.png'); $edit = array( - 'files[' . $field_name . '_0]' => drupal_realpath($zero->uri), + 'files[' . $field_name . '_0]' => drupal_realpath($zero_size_image->uri), ); $this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload')); $this->assertFalse(file_exists('public://image-zero-size_0.png'), 'Zero-byte image file was not loaded.'); // Try uploading an invalid image. + $invalid_image = $this->drupalGetTestImageFile('image-invalid.png'); $edit = array( - 'files[' . $field_name . '_0]' => drupal_realpath($invalid->uri), + 'files[' . $field_name . '_0]' => drupal_realpath($invalid_image->uri), ); $this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload')); $this->assertFalse(file_exists('public://image-invalid_0.png'), 'Invalid image file was not loaded.'); @@ -73,24 +62,11 @@ function testResolution() { $this->createImageField($field_name, 'article', array(), $field_settings); // We want a test image that is too small, and a test image that is too - // big, so cycle through test image files until we have what we need. - $image_that_is_too_big = FALSE; - $image_that_is_too_small = FALSE; - $image_factory = $this->container->get('image.factory'); - foreach ($this->drupalGetTestFiles('image') as $image) { - $image_file = $image_factory->get($image->uri); - if ($image_file->getWidth() > $max_resolution) { - $image_that_is_too_big = $image; - } - if ($image_file->getWidth() < $min_resolution) { - $image_that_is_too_small = $image; - } - if ($image_that_is_too_small && $image_that_is_too_big) { - break; - } - } + // big. + $image_that_is_too_small = $this->drupalGetTestImageFile('image-test.jpg') $this->uploadNodeImage($image_that_is_too_small, $field_name, 'article'); $this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $image_that_is_too_small->filename)) . ' ' . t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => '50x50')), 'Node save failed when minimum image resolution was not met.'); + $image_that_is_too_big = $this->drupalGetTestImageFile('image-1.png'); $this->uploadNodeImage($image_that_is_too_big, $field_name, 'article'); $this->assertText(t('The image was resized to fit within the maximum allowed dimensions of 100x100 pixels.'), 'Image exceeding max resolution was properly resized.'); } diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index 64513b1..a85b54d 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -166,9 +166,9 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles = $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = Unicode::strtolower($this->randomMachineName()); $this->createImageField($field_name, 'article', array('uri_scheme' => $scheme)); - // Create a new node with an image attached. Make sure we use a large image + // Create a new node with an image attached. We use a large image // so the scale effects of the image styles always have an effect. - $test_image = current($this->drupalGetTestFiles('image', 39325)); + $test_image = $this->drupalGetTestImageFile('image-1.png'); // Create alt text for the image. $alt = $this->randomMachineName(); diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/src/Tests/UserPasswordResetTest.php index 3db2c00..08c63d5 100644 --- a/core/modules/user/src/Tests/UserPasswordResetTest.php +++ b/core/modules/user/src/Tests/UserPasswordResetTest.php @@ -111,7 +111,7 @@ function testUserPasswordReset() { // Make sure the ajax request from uploading a user picture does not // invalidate the reset token. - $image = current($this->drupalGetTestFiles('image')); + $image = $this->drupalGetTestImageFile(); $edit = array( 'files[user_picture_0]' => drupal_realpath($image->uri), );