function ImageFieldDefaultImagesTest::testInvalidDefaultImage

Same name in other branches
  1. 9 core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php \Drupal\Tests\image\Functional\ImageFieldDefaultImagesTest::testInvalidDefaultImage()
  2. 8.9.x core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php \Drupal\Tests\image\Functional\ImageFieldDefaultImagesTest::testInvalidDefaultImage()
  3. 11.x core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php \Drupal\Tests\image\Functional\ImageFieldDefaultImagesTest::testInvalidDefaultImage()

Tests image field and field storage having an invalid default image.

File

core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php, line 261

Class

ImageFieldDefaultImagesTest
Tests setting up default images both to the field and field storage.

Namespace

Drupal\Tests\image\Functional

Code

public function testInvalidDefaultImage() : void {
    $field_storage = FieldStorageConfig::create([
        'field_name' => $this->randomMachineName(),
        'entity_type' => 'node',
        'type' => 'image',
        'settings' => [
            'default_image' => [
                'uuid' => 100000,
            ],
        ],
    ]);
    $field_storage->save();
    $settings = $field_storage->getSettings();
    // The non-existent default image should not be saved.
    $this->assertNull($settings['default_image']['uuid']);
    $field = FieldConfig::create([
        'field_storage' => $field_storage,
        'bundle' => 'page',
        'label' => $this->randomMachineName(),
        'settings' => [
            'default_image' => [
                'uuid' => 100000,
            ],
        ],
    ]);
    $field->save();
    $settings = $field->getSettings();
    // The non-existent default image should not be saved.
    $this->assertNull($settings['default_image']['uuid']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.