You are here

protected function ImageFormatterTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/tests/src/Kernel/ImageFormatterTest.php \Drupal\Tests\image\Kernel\ImageFormatterTest::setUp()

Set the default field storage backend for fields created during tests.

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();
}