function ImageItemTest::setUp

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

Overrides FieldKernelTestBase::setUp

File

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

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();
    FieldStorageConfig::create([
        'entity_type' => 'entity_test',
        'field_name' => 'image_test_generation',
        '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();
    FieldConfig::create([
        'entity_type' => 'entity_test',
        'field_name' => 'image_test_generation',
        'bundle' => 'entity_test',
        'settings' => [
            'min_resolution' => '800x800',
        ],
    ])->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');
}

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