function FileItemTest::setUp

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

Overrides FieldKernelTestBase::setUp

1 call to FileItemTest::setUp()
WorkspacesFileItemTest::setUp in core/modules/workspaces/tests/src/Kernel/WorkspacesFileItemTest.php
1 method overrides FileItemTest::setUp()
WorkspacesFileItemTest::setUp in core/modules/workspaces/tests/src/Kernel/WorkspacesFileItemTest.php

File

core/modules/file/tests/src/Kernel/FileItemTest.php, line 46

Class

FileItemTest
Tests using entity fields of the file field type.

Namespace

Drupal\Tests\file\Kernel

Code

protected function setUp() : void {
    parent::setUp();
    $this->installEntitySchema('user');
    $this->installConfig([
        'user',
    ]);
    // Give anonymous users permission to access content, so they can view and
    // download public files.
    $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([
        'field_name' => 'file_test',
        'entity_type' => 'entity_test',
        'type' => 'file',
        'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    ])->save();
    $this->directory = $this->getRandomGenerator()
        ->name(8);
    FieldConfig::create([
        'entity_type' => 'entity_test',
        'field_name' => 'file_test',
        'bundle' => 'entity_test',
        'settings' => [
            'file_directory' => $this->directory,
        ],
    ])
        ->save();
    file_put_contents('public://example.txt', $this->randomMachineName());
    $this->file = File::create([
        'uri' => 'public://example.txt',
    ]);
    $this->file
        ->save();
}

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