function ImageItemTest::testImageItemMalformed
Same name in other branches
- 8.9.x 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()
- 11.x 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 149
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('Missing file with ID 9999.', $exception->getMessage());
$this->assertEmpty($entity->image_test->width);
$this->assertEmpty($entity->image_test->height);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.