Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / file / tests / src / Kernel / FileItemValidationTest.php
index c9a247bf40296c963369f5369ff694ad644104d7..ba763b665411e7217fa49415821f1ef0379c7027 100644 (file)
@@ -78,9 +78,9 @@ class FileItemValidationTest extends KernelTestBase {
         'default' => [
           'files' => [
             'test.txt' => str_repeat('a', 3000),
-          ]
-        ]
-      ]
+          ],
+        ],
+      ],
     ]);
 
     // Test for max filesize.
@@ -95,7 +95,7 @@ class FileItemValidationTest extends KernelTestBase {
       'uid' => $this->user->id(),
       'field_test_file' => [
         'target_id' => $file->id(),
-      ]
+      ],
     ]);
     $result = $entity_test->validate();
     $this->assertCount(2, $result);
@@ -104,6 +104,18 @@ class FileItemValidationTest extends KernelTestBase {
     $this->assertEquals('The file is <em class="placeholder">2.93 KB</em> exceeding the maximum file size of <em class="placeholder">2 KB</em>.', (string) $result->get(0)->getMessage());
     $this->assertEquals('field_test_file.0', $result->get(1)->getPropertyPath());
     $this->assertEquals('Only files with the following extensions are allowed: <em class="placeholder">jpg|png</em>.', (string) $result->get(1)->getMessage());
+
+    // Refer to a file that does not exist.
+    $entity_test = EntityTest::create([
+      'uid' => $this->user->id(),
+      'field_test_file' => [
+        'target_id' => 2,
+      ],
+    ]);
+    $result = $entity_test->validate();
+    $this->assertCount(1, $result);
+    $this->assertEquals('field_test_file.0.target_id', $result->get(0)->getPropertyPath());
+    $this->assertEquals('The referenced entity (<em class="placeholder">file</em>: <em class="placeholder">2</em>) does not exist.', (string) $result->get(0)->getMessage());
   }
 
   /**