diff --git a/core/modules/comment/src/Tests/CommentPreviewTest.php b/core/modules/comment/src/Tests/CommentPreviewTest.php
index 8d4985a..891f97a 100644
--- a/core/modules/comment/src/Tests/CommentPreviewTest.php
+++ b/core/modules/comment/src/Tests/CommentPreviewTest.php
@@ -59,7 +59,7 @@ function testCommentPreview() {
     $this->assertRaw('<em>' . $this->webUser->id() . '</em>');
 
     // Add a user picture.
-    $image = current($this->drupalGetTestFiles('image'));
+    $image = $this->drupalGetTestImageFile();
     $user_edit['files[user_picture_0]'] = drupal_realpath($image->uri);
     $this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $user_edit, t('Save'));
 
diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php
index ea80e27..0acc878 100644
--- a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php
+++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php
@@ -40,7 +40,9 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
 
   protected function setUp() {
     parent::setUp();
-    $this->files = $this->drupalGetTestFiles('image');
+    foreach (['image-1.png', 'image-test.jpg', 'image-2.jpg', 'image-test.gif', 'image-test.png'] as $file) {
+      $this->files[] = $this->drupalGetTestImageFile($file);
+    }
   }
 
   /**
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 984773a..b06601e 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -391,7 +391,7 @@ function file_validate_is_image(FileInterface $file) {
   $image = $image_factory->get($file->getFileUri());
   if (!$image->isValid()) {
     $supported_extensions = $image_factory->getSupportedExtensions();
-    $errors[] = t('Image type not supported. Allowed types: %types', array('%types' => implode(' ', $supported_extensions)));
+    $errors[] = t('The image is invalid, or not supported. Allowed types: %types', array('%types' => implode(' ', $supported_extensions)));
   }
 
   return $errors;
diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php
index 7c3bd4c..7eda38b 100644
--- a/core/modules/file/src/Tests/SaveUploadTest.php
+++ b/core/modules/file/src/Tests/SaveUploadTest.php
@@ -51,8 +51,7 @@ protected function setUp() {
     $account = $this->drupalCreateUser(array('access site reports'));
     $this->drupalLogin($account);
 
-    $image_files = $this->drupalGetTestFiles('image');
-    $this->image = entity_create('file', (array) current($image_files));
+    $this->image = entity_create('file', (array) $this->drupalGetTestImageFile());
 
     list(, $this->imageExtension) = explode('.', $this->image->getFilename());
     $this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists.");
@@ -92,7 +91,7 @@ function testNormal() {
     file_test_reset();
 
     // Upload a second file.
-    $image2 = current($this->drupalGetTestFiles('image'));
+    $image2 = $this->drupalGetTestImageFile();
     $edit = array('files[file_test_upload]' => drupal_realpath($image2->uri));
     $this->drupalPostForm('file-test/upload', $edit, t('Submit'));
     $this->assertResponse(200, 'Received a 200 response for posted test file.');
@@ -113,7 +112,7 @@ function testNormal() {
     $this->assertTrue(isset($files[$file2->id()]), 'File was loaded successfully');
 
     // Upload a third file to a subdirectory.
-    $image3 = current($this->drupalGetTestFiles('image'));
+    $image3 = $this->drupalGetTestImageFile();
     $image3_realpath = drupal_realpath($image3->uri);
     $dir = $this->randomMachineName();
     $edit = array(
diff --git a/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php
index 9d96c5f..915e58e 100644
--- a/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php
+++ b/core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php
@@ -94,14 +94,14 @@ function testImageSource() {
     $title_text = t('This image has been removed. For security reasons, only images from the local domain are allowed.');
 
     // Put a test image in the files directory.
-    $test_images = $this->drupalGetTestFiles('image');
-    $test_image = $test_images[0]->filename;
+    $image_file = $this->drupalGetTestImageFile();
+    $test_image = $image_file->filename;
 
     // Put a test image in the files directory with special filename.
     $special_filename = 'tést fïle nàme.png';
     $special_image = rawurlencode($special_filename);
-    $special_uri = str_replace($test_images[0]->filename, $special_filename, $test_images[0]->uri);
-    file_unmanaged_copy($test_images[0]->uri, $special_uri);
+    $special_uri = str_replace($image_file->filename, $special_filename, $image_file->uri);
+    file_unmanaged_copy($image_file->uri, $special_uri);
 
     // Create a list of test image sources.
     // The keys become the value of the IMG 'src' attribute, the values are the
diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
index 10ebfb5..5b49cee 100644
--- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
+++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
@@ -117,6 +117,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
 
     $field_settings = $this->getFieldSettings();
 
+    // Add image validation.
+    $element['#upload_validators']['file_validate_is_image'] = array();
+
     // Add upload resolution validation.
     if ($field_settings['max_resolution'] || $field_settings['min_resolution']) {
       $element['#upload_validators']['file_validate_image_resolution'] = array($field_settings['max_resolution'], $field_settings['min_resolution']);
diff --git a/core/modules/image/src/Tests/FileMoveTest.php b/core/modules/image/src/Tests/FileMoveTest.php
index 34c54a7..8d457e8 100644
--- a/core/modules/image/src/Tests/FileMoveTest.php
+++ b/core/modules/image/src/Tests/FileMoveTest.php
@@ -29,7 +29,7 @@ class FileMoveTest extends WebTestBase {
    */
   function testNormal() {
     // Pick a file for testing.
-    $file = entity_create('file', (array) current($this->drupalGetTestFiles('image')));
+    $file = entity_create('file', (array) $this->drupalGetTestImageFile());
 
     // Create derivative image.
     $styles = ImageStyle::loadMultiple();
diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php
index cf5916c..c4f8780 100644
--- a/core/modules/image/src/Tests/ImageAdminStylesTest.php
+++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php
@@ -30,8 +30,7 @@ function createSampleImage(ImageStyleInterface $style) {
     // First, we need to make sure we have an image in our testing
     // file directory. Copy over an image on the first run.
     if (!isset($file_path)) {
-      $files = $this->drupalGetTestFiles('image');
-      $file = reset($files);
+      $file = $this->drupalGetTestImageFile();
       $file_path = file_unmanaged_copy($file->uri);
     }
 
@@ -313,7 +312,7 @@ function testStyleReplacement() {
       ->save();
 
     // Create a new node with an image attached.
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
     $node = Node::load($nid);
 
@@ -407,8 +406,8 @@ public function testFlushUserInterface() {
     $style->save();
 
     // Create an image to make sure it gets flushed.
-    $files = $this->drupalGetTestFiles('image');
-    $image_uri = $files[0]->uri;
+    $image_file = $this->drupalGetTestImageFile();
+    $image_uri = $image_file->uri;
     $derivative_uri = $style->buildUri($image_uri);
     $this->assertTrue($style->createDerivative($image_uri, $derivative_uri));
     $this->assertEqual($this->getImageCount($style), 1);
@@ -447,7 +446,7 @@ function testConfigImport() {
       ->save();
 
     // Create a new node with an image attached.
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
     $node = Node::load($nid);
 
diff --git a/core/modules/image/src/Tests/ImageDimensionsTest.php b/core/modules/image/src/Tests/ImageDimensionsTest.php
index f232d71..1d54bd7 100644
--- a/core/modules/image/src/Tests/ImageDimensionsTest.php
+++ b/core/modules/image/src/Tests/ImageDimensionsTest.php
@@ -32,8 +32,7 @@ class ImageDimensionsTest extends WebTestBase {
   function testImageDimensions() {
     $image_factory = $this->container->get('image.factory');
     // Create a working copy of the file.
-    $files = $this->drupalGetTestFiles('image');
-    $file = reset($files);
+    $file = $this->drupalGetTestImageFile('image-test.png');
     $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
 
     // Create a style.
@@ -264,7 +263,7 @@ function testImageDimensions() {
     $this->assertEqual($image_file->getWidth(), 100);
     $this->assertEqual($image_file->getHeight(), 100);
     // GIF original image. Should be resized to 50x50.
-    $file = $files[1];
+    $file = $this->drupalGetTestImageFile('image-test.gif');
     $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
     $generated_uri = 'public://styles/test_uri/public/'. \Drupal::service('file_system')->basename($original_uri);
     $url = file_url_transform_relative($style->buildUrl($original_uri));
diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
index 30a22fe..e817480 100644
--- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
+++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
@@ -30,19 +30,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.gif', 'image-test.png'];
     $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/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php
index 2ae0fa4..2b0a328 100644
--- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php
+++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php
@@ -77,7 +77,7 @@ function _testImageFieldFormatters($scheme) {
     user_role_change_permissions(reset($admin_user_roles), array('administer image styles' => TRUE));
 
     // Create a new node with an image attached.
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
 
     // Ensure that preview works.
     $this->previewNodeImage($test_image, $field_name, 'article');
@@ -213,7 +213,7 @@ function testImageFieldSettings() {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
     list(, $test_image_extension) = explode('.', $test_image->filename);
     $field_name = strtolower($this->randomMachineName());
     $field_settings = array(
@@ -344,12 +344,11 @@ function testImageFieldDefaultImage() {
     $this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
 
     // Add a default image to the public image field.
-    $images = $this->drupalGetTestFiles('image');
+    $image = $this->drupalGetTestImageFile('image-test.png');
     $alt = $this->randomString(512);
     $title = $this->randomString(1024);
     $edit = array(
-      // Get the path of the 'image-test.png' file.
-      'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri),
+      'files[settings_default_image_uuid]' => drupal_realpath($image->uri),
       'settings[default_image][alt]' => $alt,
       'settings[default_image][title]' => $title,
     );
@@ -381,8 +380,8 @@ function testImageFieldDefaultImage() {
     // Create alt text for the image.
     $alt = $this->randomMachineName();
 
-    // Upload the 'image-test.gif' file.
-    $nid = $this->uploadNodeImage($images[2], $field_name, 'article', $alt);
+    $image_file = $this->drupalGetTestImageFile('image-test.jpg');
+    $nid = $this->uploadNodeImage($image_file, $field_name, 'article', $alt);
     $node_storage->resetCache(array($nid));
     $node = $node_storage->load($nid);
     $file = $node->{$field_name}->entity;
@@ -417,8 +416,7 @@ function testImageFieldDefaultImage() {
     $this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private'));
     // Add a default image to the new field.
     $edit = array(
-      // Get the path of the 'image-test.gif' file.
-      'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri),
+      'files[settings_default_image_uuid]' => drupal_realpath($image_file->uri),
       'settings[default_image][alt]' => $alt,
       'settings[default_image][title]' => $title,
     );
diff --git a/core/modules/image/src/Tests/ImageFieldValidateTest.php b/core/modules/image/src/Tests/ImageFieldValidateTest.php
index c5ea831..8f40ce3 100644
--- a/core/modules/image/src/Tests/ImageFieldValidateTest.php
+++ b/core/modules/image/src/Tests/ImageFieldValidateTest.php
@@ -14,6 +14,56 @@
  */
 class ImageFieldValidateTest extends ImageFieldTestBase {
   /**
+   * Test image validity.
+   */
+  function testValid() {
+    $date_formatter = $this->container->get('date.formatter');
+    $file_system = $this->container->get('file_system');
+
+    $field_name = strtolower($this->randomMachineName());
+    $this->createImageField($field_name, 'article', array(), array());
+    $expected_path =
+      'public://' .
+      $date_formatter->format(REQUEST_TIME, 'custom', 'Y') . '-' .
+      $date_formatter->format(REQUEST_TIME, 'custom', 'm');
+
+    // Create alt text for the image.
+    $alt = $this->randomMachineName();
+
+    // Create a node with a valid image.
+    $node = $this->uploadNodeImage($this->drupalGetTestImageFile('image-1.png'), $field_name, 'article', $alt);
+    $this->assertTrue(file_exists($expected_path . '/image-1.png'));
+
+    // 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]' => $file_system->realpath($zero_size_image->uri),
+    );
+    $this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
+    $this->assertFalse(file_exists($expected_path . '/image-zero-size.png'));
+
+    // Try uploading an invalid image.
+    $invalid_image = $this->drupalGetTestImageFile('image-invalid.png');
+    $edit = array(
+      'files[' . $field_name . '_0]' => $file_system->realpath($invalid_image->uri),
+    );
+    $this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
+    $this->assertFalse(file_exists($expected_path . '/image-invalid.png'));
+
+    // Upload a valid image again.
+    $valid_image = $this->drupalGetTestImageFile('image-test.png');
+    $edit = array(
+      'files[' . $field_name . '_0]' => $file_system->realpath($valid_image->uri),
+    );
+    $this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
+    $this->assertTrue(file_exists($expected_path . '/image-test.png'));
+  }
+
+  /**
    * Test min/max resolution settings.
    */
   function testResolution() {
@@ -28,25 +78,12 @@ 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)));
     $this->assertRaw(t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => '50x50')));
+    $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.'));
   }
@@ -64,9 +101,8 @@ function testRequiredAttributes() {
       'required' => 1,
     );
     $instance = $this->createImageField($field_name, 'article', array(), $field_settings);
-    $images = $this->drupalGetTestFiles('image');
-    // Let's just use the first image.
-    $image = $images[0];
+    // Make sure we use a valid image.
+    $image = $this->drupalGetTestImageFile();
     $this->uploadNodeImage($image, $field_name, 'article');
 
     // Look for form-required for the alt text.
diff --git a/core/modules/image/src/Tests/ImageStyleFlushTest.php b/core/modules/image/src/Tests/ImageStyleFlushTest.php
index 0a6a5fa..e092f61 100644
--- a/core/modules/image/src/Tests/ImageStyleFlushTest.php
+++ b/core/modules/image/src/Tests/ImageStyleFlushTest.php
@@ -23,8 +23,7 @@ function createSampleImage($style, $wrapper) {
     static $file;
 
     if (!isset($file)) {
-      $files = $this->drupalGetTestFiles('image');
-      $file = reset($files);
+      $file = $this->drupalGetTestImageFile();
     }
 
     // Make sure we have an image in our wrapper testing file directory.
diff --git a/core/modules/image/src/Tests/ImageStylesPathAndUrlTest.php b/core/modules/image/src/Tests/ImageStylesPathAndUrlTest.php
index 28febab..cf51531 100644
--- a/core/modules/image/src/Tests/ImageStylesPathAndUrlTest.php
+++ b/core/modules/image/src/Tests/ImageStylesPathAndUrlTest.php
@@ -111,8 +111,7 @@ function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash =
     $this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.');
 
     // Create a working copy of the file.
-    $files = $this->drupalGetTestFiles('image');
-    $file = array_shift($files);
+    $file = $this->drupalGetTestImageFile('image-test.png');
     $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME);
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
@@ -178,7 +177,7 @@ function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash =
 
       // Repeat this with a different file that we do not have access to and
       // make sure that access is denied.
-      $file_noaccess = array_shift($files);
+      $file_noaccess = $this->drupalGetTestImageFile('image-test.jpg');
       $original_uri_noaccess = file_unmanaged_copy($file_noaccess->uri, $scheme . '://', FILE_EXISTS_RENAME);
       $generated_uri_noaccess = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/'. drupal_basename($original_uri_noaccess);
       $this->assertFalse(file_exists($generated_uri_noaccess), 'Generated file does not exist.');
@@ -212,8 +211,7 @@ function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash =
     $this->config('image.settings')->set('allow_insecure_derivatives', TRUE)->save();
 
     // Create another working copy of the file.
-    $files = $this->drupalGetTestFiles('image');
-    $file = array_shift($files);
+    $file = $this->drupalGetTestImageFile('image-test.png');
     $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME);
     // Let the image_module_test module know about this file, so it can claim
     // ownership in hook_file_download().
diff --git a/core/modules/image/src/Tests/ImageThemeFunctionTest.php b/core/modules/image/src/Tests/ImageThemeFunctionTest.php
index d64899b..be1588f 100644
--- a/core/modules/image/src/Tests/ImageThemeFunctionTest.php
+++ b/core/modules/image/src/Tests/ImageThemeFunctionTest.php
@@ -69,8 +69,7 @@ function testImageFormatterTheme() {
     $renderer = $this->container->get('renderer');
 
     // Create an image.
-    $files = $this->drupalGetTestFiles('image');
-    $file = reset($files);
+    $file = $this->drupalGetTestImageFile();
     $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
 
     // Create a style.
@@ -131,8 +130,7 @@ function testImageStyleTheme() {
     $renderer = $this->container->get('renderer');
 
     // Create an image.
-    $files = $this->drupalGetTestFiles('image');
-    $file = reset($files);
+    $file = $this->drupalGetTestImageFile();
     $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
 
     // Create a style.
diff --git a/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php
index 903636a..33101c8 100644
--- a/core/modules/node/src/Tests/PagePreviewTest.php
+++ b/core/modules/node/src/Tests/PagePreviewTest.php
@@ -144,7 +144,7 @@ function testPagePreview() {
     $edit[$term_key] = $this->term->getName();
 
     // Upload an image.
-    $test_image = current($this->drupalGetTestFiles('image', 39325));
+    $test_image = $this->drupalGetTestImageFile('image-1.png');
     $edit['files[field_image_0][]'] = drupal_realpath($test_image->uri);
     $this->drupalPostForm('node/add/page', $edit, t('Upload'));
 
diff --git a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
index 6e6fffb..2696a23 100644
--- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
+++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
@@ -547,7 +547,7 @@ public function testImageField() {
 
     // Add an image to the node.
     $this->drupalLogin($this->editorUser);
-    $image = $this->drupalGetTestFiles('image')[0];
+    $image = $this->drupalGetTestImageFile();
     $this->drupalPostForm('node/1/edit', [
       'files[field_image_0]' => $image->uri,
     ], t('Upload'));
diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
index a36a0a8..69d15c4 100644
--- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
+++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
@@ -65,7 +65,7 @@ protected function setUp() {
       ->save();
 
     // Get the test image that simpletest provides.
-    $image = current($this->drupalGetTestFiles('image'));
+    $image = $this->drupalGetTestImageFile();
 
     // Save a node with the image.
     $nid = $this->uploadNodeImage($image, $this->fieldName, 'article', $this->randomMachineName());
diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
index e8e7aae..eca2366 100644
--- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
+++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
@@ -175,9 +175,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();
@@ -378,7 +378,7 @@ public function testResponsiveImageFieldFormattersEmptyMediaQuery() {
     $field_name = Unicode::strtolower($this->randomMachineName());
     $this->createImageField($field_name, 'article', array('uri_scheme' => 'public'));
     // Create a new node with an image attached.
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
     $node_storage->resetCache(array($nid));
 
@@ -426,7 +426,7 @@ public function testResponsiveImageFieldFormattersOneSource() {
     $field_name = Unicode::strtolower($this->randomMachineName());
     $this->createImageField($field_name, 'article', array('uri_scheme' => 'public'));
     // Create a new node with an image attached.
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
     $nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
     $node_storage->resetCache(array($nid));
 
@@ -464,7 +464,7 @@ private function assertResponsiveImageFieldFormattersLink($link_type) {
     $field_settings = array('alt_field_required' => 0);
     $this->createImageField($field_name, 'article', array('uri_scheme' => 'public'), $field_settings);
     // Create a new node with an image attached.
-    $test_image = current($this->drupalGetTestFiles('image'));
+    $test_image = $this->drupalGetTestImageFile();
 
     // Test the image linked to file formatter.
     $display_options = array(
diff --git a/core/modules/simpletest/files/image-invalid.png b/core/modules/simpletest/files/image-invalid.png
new file mode 100644
index 0000000..8175b44
--- /dev/null
+++ b/core/modules/simpletest/files/image-invalid.png
@@ -0,0 +1 @@
+invalid image file
diff --git a/core/modules/simpletest/files/image-zero-size.png b/core/modules/simpletest/files/image-zero-size.png
new file mode 100644
index 0000000..e69de29
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index e4e9622..772a41f 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -410,6 +410,25 @@ protected function drupalGetTestFiles($type, $size = NULL) {
   }
 
   /**
+   * Gets an image file that can be used in tests.
+   *
+   * @param string|null $file_name
+   *   (Optional) The file name of the file to be returned. If not specified,
+   *   will return a valid image file from the image files.
+   *
+   * @return stdClass|null
+   *   A file object, or NULL if requested file is not existing.
+   */
+  protected function drupalGetTestImageFile($file_name = NULL) {
+    $image_files = array();
+    foreach ($this->drupalGetTestFiles('image') as $file) {
+      $image_files[$file->filename] = $file;
+    }
+    $file_name = $file_name ?: 'image-test.png';
+    return isset($image_files[$file_name]) ? $image_files[$file_name] : NULL;
+  }
+
+  /**
    * Compare two files based on size and file name.
    */
   protected function drupalCompareFiles($file1, $file2) {
diff --git a/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php b/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php
index bfdc64c..06c2148 100644
--- a/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php
+++ b/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php
@@ -36,8 +36,7 @@ class StateValuesCleanAdvancedTest extends WebTestBase {
   function testFormStateValuesCleanAdvanced() {
 
     // Get an image for uploading.
-    $image_files = $this->drupalGetTestFiles('image');
-    $this->image = current($image_files);
+    $this->image = $this->drupalGetTestImageFile();
 
     // Check if the physical file is there.
     $this->assertTrue(is_file($this->image->uri), "The image file we're going to upload exists.");
diff --git a/core/modules/system/src/Tests/Image/ToolkitTestBase.php b/core/modules/system/src/Tests/Image/ToolkitTestBase.php
index 21a514c..6bac25e 100644
--- a/core/modules/system/src/Tests/Image/ToolkitTestBase.php
+++ b/core/modules/system/src/Tests/Image/ToolkitTestBase.php
@@ -50,7 +50,7 @@ protected function setUp() {
     $this->imageFactory = $this->container->get('image.factory');
 
     // Pick a file for testing.
-    $file = current($this->drupalGetTestFiles('image'));
+    $file = $this->drupalGetTestImageFile();
     $this->file = $file->uri;
 
     // Setup a dummy image to work with.
diff --git a/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php
index c2f5a57..0ca3166 100644
--- a/core/modules/system/src/Tests/System/ThemeTest.php
+++ b/core/modules/system/src/Tests/System/ThemeTest.php
@@ -57,7 +57,7 @@ function testThemeSettings() {
     $this->assertResponse(404, 'The theme settings form URL for a hidden theme is unavailable.');
 
     // Specify a filesystem path to be used for the logo.
-    $file = current($this->drupalGetTestFiles('image'));
+    $file = $this->drupalGetTestImageFile();
     $file_relative = strtr($file->uri, array('public:/' => PublicStream::basePath()));
     $default_theme_path = 'core/themes/classy';
 
diff --git a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php
index b4c9d78..3f1cbbd 100644
--- a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php
+++ b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php
@@ -75,8 +75,7 @@ public function testTaxonomyImageAccess() {
     $this->drupalLogin($user);
 
     // Create a term and upload the image.
-    $files = $this->drupalGetTestFiles('image');
-    $image = array_pop($files);
+    $image = $this->drupalGetTestImageFile();
     $edit['name[0][value]'] = $this->randomMachineName();
     $edit['files[field_test_0]'] = drupal_realpath($image->uri);
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id()  . '/add', $edit, t('Save'));
diff --git a/core/modules/update/src/Tests/UpdateUploadTest.php b/core/modules/update/src/Tests/UpdateUploadTest.php
index b9635e1..f74c9d1 100644
--- a/core/modules/update/src/Tests/UpdateUploadTest.php
+++ b/core/modules/update/src/Tests/UpdateUploadTest.php
@@ -35,12 +35,8 @@ protected function setUp() {
    * Tests upload, extraction, and update of a module.
    */
   public function testUploadModule() {
-    // Images are not valid archives, so get one and try to install it. We
-    // need an extra variable to store the result of drupalGetTestFiles()
-    // since reset() takes an argument by reference and passing in a constant
-    // emits a notice in strict mode.
-    $imageTestFiles = $this->drupalGetTestFiles('image');
-    $invalidArchiveFile = reset($imageTestFiles);
+    // Images are not valid archives, so get one and try to install it.
+    $invalidArchiveFile = $this->drupalGetTestImageFile();
     $edit = array(
       'files[project_upload]' => $invalidArchiveFile->uri,
     );
diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/src/Tests/UserPasswordResetTest.php
index 420b97a..70b3f04 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),
     );
diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php
index 9fa28a3..51513a3 100644
--- a/core/modules/user/src/Tests/UserPictureTest.php
+++ b/core/modules/user/src/Tests/UserPictureTest.php
@@ -53,7 +53,7 @@ function testCreateDeletePicture() {
     $this->drupalLogin($this->webUser);
 
     // Save a new picture.
-    $image = current($this->drupalGetTestFiles('image'));
+    $image = $this->drupalGetTestImageFile();
     $file = $this->saveUserPicture($image);
 
     // Verify that the image is displayed on the user account page.
@@ -90,7 +90,7 @@ function testPictureOnNodeComment() {
     $this->drupalLogin($this->webUser);
 
     // Save a new picture.
-    $image = current($this->drupalGetTestFiles('image'));
+    $image = $this->drupalGetTestImageFile();
     $file = $this->saveUserPicture($image);
 
     $node = $this->drupalCreateNode(array('type' => 'article'));
