You are here

protected function ImageItemTest::setUp in Drupal 9

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

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

Overrides FieldKernelTestBase::setUp

File

core/modules/image/tests/src/Kernel/ImageItemTest.php, line 43

Class

ImageItemTest
Tests using entity fields of the image field type.

Namespace

Drupal\Tests\image\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('user');
  $this
    ->installConfig([
    'user',
  ]);

  // Give anonymous users permission to access content, so that we can view
  // and download public file.
  $anonymous_role = Role::load(Role::ANONYMOUS_ID);
  $anonymous_role
    ->grantPermission('access content');
  $anonymous_role
    ->save();
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  FieldStorageConfig::create([
    'entity_type' => 'entity_test',
    'field_name' => 'image_test',
    'type' => 'image',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => 'entity_test',
    'field_name' => 'image_test',
    'bundle' => 'entity_test',
    'settings' => [
      'file_extensions' => 'jpg',
    ],
  ])
    ->save();
  \Drupal::service('file_system')
    ->copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
  $this->image = File::create([
    'uri' => 'public://example.jpg',
  ]);
  $this->image
    ->save();
  $this->imageFactory = $this->container
    ->get('image.factory');
}