function FileUploadTest::setUp

Same name in this branch
  1. 11.x core/modules/jsonapi/tests/src/Kernel/Controller/FileUploadTest.php \Drupal\Tests\jsonapi\Kernel\Controller\FileUploadTest::setUp()
Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::setUp()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::setUp()
  3. 10 core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::setUp()
  4. 10 core/modules/jsonapi/tests/src/Kernel/Controller/FileUploadTest.php \Drupal\Tests\jsonapi\Kernel\Controller\FileUploadTest::setUp()

Overrides ResourceTestBase::setUp

File

core/modules/jsonapi/tests/src/Functional/FileUploadTest.php, line 120

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function setUp() : void {
    if (in_array($this->name(), static::SKIP_METHODS, TRUE)) {
        $this->markTestSkipped('Irrelevant for this test');
    }
    parent::setUp();
    $this->fileStorage = $this->container
        ->get('entity_type.manager')
        ->getStorage('file');
    // Add a file field.
    $this->fieldStorage = FieldStorageConfig::create([
        'entity_type' => 'entity_test',
        'field_name' => 'field_rest_file_test',
        'type' => 'file',
        'settings' => [
            'uri_scheme' => 'public',
        ],
    ])->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this->fieldStorage
        ->save();
    $this->field = FieldConfig::create([
        'entity_type' => 'entity_test',
        'field_name' => 'field_rest_file_test',
        'bundle' => 'entity_test',
        'settings' => [
            'file_directory' => 'foobar',
            'file_extensions' => 'txt',
            'max_filesize' => '',
        ],
    ])->setLabel('Test file field')
        ->setTranslatable(FALSE);
    $this->field
        ->save();
    // Reload entity so that it has the new field.
    $this->entity = $this->entityStorage
        ->loadUnchanged($this->entity
        ->id());
}

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