From 0a96230db79fe1be33e815026c044dda935f3d48 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Mon, 30 Dec 2013 07:47:41 -0800
Subject: [PATCH] Issue #2001308 by marthinal, helmo, David_Rothstein,
 micahw156: Tests for: Node preview removes file values from node edit form
 for non-displayed items.

---
 .../Drupal/file/Tests/FileFieldDisplayTest.php    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php
index f6c399d3e6ff..219c083f5e62 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\file\Tests;
 
+use Drupal\Core\Field\FieldDefinitionInterface;
+
 /**
  * Tests that formatters are working properly.
  */
@@ -29,6 +31,7 @@ function testNodeDisplay() {
     $field_settings = array(
       'display_field' => '1',
       'display_default' => '1',
+      'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
     );
     $instance_settings = array(
       'description_field' => '1',
@@ -80,5 +83,17 @@ function testNodeDisplay() {
     );
     $this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
     $this->assertText($description);
+
+    // Test that fields appear as expected after during the preview.
+    // Add a second file.
+    $name = 'files[' . $field_name . '_1][]';
+    $edit[$name] = drupal_realpath($test_file->getFileUri());
+
+    // Uncheck the display checkboxes and go to the preview.
+    $edit[$field_name . '[0][display]'] = FALSE;
+    $edit[$field_name . '[1][display]'] = FALSE;
+    $this->drupalPostForm("node/$nid/edit", $edit, t('Preview'));
+    $this->assertRaw($field_name . '[0][display]', 'First file appears as expected.');
+    $this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.');
   }
 }
-- 
GitLab