X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fimage%2Ftests%2Fsrc%2FKernel%2FImageItemTest.php;fp=web%2Fcore%2Fmodules%2Fimage%2Ftests%2Fsrc%2FKernel%2FImageItemTest.php;h=951d1907f88f1b9ed4e3c0963b86d3d73e1caf08;hp=f7a130545085d8365fe3bf30643e2c195f1d4def;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/image/tests/src/Kernel/ImageItemTest.php b/web/core/modules/image/tests/src/Kernel/ImageItemTest.php index f7a130545..951d1907f 100644 --- a/web/core/modules/image/tests/src/Kernel/ImageItemTest.php +++ b/web/core/modules/image/tests/src/Kernel/ImageItemTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\image\Kernel; +use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -129,4 +130,26 @@ class ImageItemTest extends FieldKernelTestBase { $this->assertEqual($entity->image_test->entity->get('filemime')->value, 'image/jpeg'); } + /** + * Tests a malformed image. + */ + public function testImageItemMalformed() { + // Validate entity is an image and don't gather dimensions if it is not. + $entity = EntityTest::create(); + $entity->image_test = NULL; + $entity->image_test->target_id = 9999; + // PHPUnit re-throws E_USER_WARNING as an exception. + try { + $entity->save(); + $this->fail('Exception did not fail'); + } + catch (EntityStorageException $exception) { + $this->assertInstanceOf(\PHPUnit_Framework_Error_Warning::class, $exception->getPrevious()); + $this->assertEquals($exception->getMessage(), 'Missing file with ID 9999.'); + $this->assertEmpty($entity->image_test->width); + $this->assertEmpty($entity->image_test->height); + } + + } + }