function ImageFormatterTest::setUp

Same name and namespace in other branches
  1. 8.9.x core/modules/image/tests/src/Kernel/ImageFormatterTest.php \Drupal\Tests\image\Kernel\ImageFormatterTest::setUp()
  2. 10 core/modules/image/tests/src/Kernel/ImageFormatterTest.php \Drupal\Tests\image\Kernel\ImageFormatterTest::setUp()
  3. 11.x core/modules/image/tests/src/Kernel/ImageFormatterTest.php \Drupal\Tests\image\Kernel\ImageFormatterTest::setUp()

Overrides FieldKernelTestBase::setUp

File

core/modules/image/tests/src/Kernel/ImageFormatterTest.php, line 51

Class

ImageFormatterTest
Tests the image field rendering using entity fields of the image field type.

Namespace

Drupal\Tests\image\Kernel

Code

protected function setUp() : void {
    parent::setUp();
    $this->installConfig([
        'field',
    ]);
    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('file');
    $this->installSchema('file', [
        'file_usage',
    ]);
    $this->entityType = 'entity_test';
    $this->bundle = $this->entityType;
    $this->fieldName = mb_strtolower($this->randomMachineName());
    FieldStorageConfig::create([
        'entity_type' => $this->entityType,
        'field_name' => $this->fieldName,
        'type' => 'image',
        'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    ])
        ->save();
    FieldConfig::create([
        'entity_type' => $this->entityType,
        'field_name' => $this->fieldName,
        'bundle' => $this->bundle,
        'settings' => [
            'file_extensions' => 'jpg',
        ],
    ])
        ->save();
    $this->display = \Drupal::service('entity_display.repository')->getViewDisplay($this->entityType, $this->bundle)
        ->setComponent($this->fieldName, [
        'type' => 'image',
        'label' => 'hidden',
    ]);
    $this->display
        ->save();
}

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