public function ImageItemTest::testImageItemMalformed in Drupal 8
Same name and namespace in other branches
- 9 core/modules/image/tests/src/Kernel/ImageItemTest.php \Drupal\Tests\image\Kernel\ImageItemTest::testImageItemMalformed()
- 10 core/modules/image/tests/src/Kernel/ImageItemTest.php \Drupal\Tests\image\Kernel\ImageItemTest::testImageItemMalformed()
Tests a malformed image.
File
- core/
modules/ image/ tests/ src/ Kernel/ ImageItemTest.php, line 146
Class
- ImageItemTest
- Tests using entity fields of the image field type.
Namespace
Drupal\Tests\image\KernelCode
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(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);
}
}