X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FKernel%2FFileItemValidationTest.php;h=ba763b665411e7217fa49415821f1ef0379c7027;hp=c9a247bf40296c963369f5369ff694ad644104d7;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/file/tests/src/Kernel/FileItemValidationTest.php b/web/core/modules/file/tests/src/Kernel/FileItemValidationTest.php index c9a247bf4..ba763b665 100644 --- a/web/core/modules/file/tests/src/Kernel/FileItemValidationTest.php +++ b/web/core/modules/file/tests/src/Kernel/FileItemValidationTest.php @@ -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 2.93 KB exceeding the maximum file size of 2 KB.', (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: jpg|png.', (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 (file: 2) does not exist.', (string) $result->get(0)->getMessage()); } /**