function FileUploadTest::testFileUploadNoConfiguration

Same name and namespace in other branches
  1. 11.x core/modules/jsonapi/tests/src/Functional/FileUploadTest.php \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadNoConfiguration()

Tests using the file upload POST route no configuration.

File

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

Class

FileUploadTest
Tests binary data file upload route.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testFileUploadNoConfiguration() : void {
  $this->setUpAuthorization('POST');
  $this->config('jsonapi.settings')
    ->set('read_only', FALSE)
    ->save(TRUE);
  $uri = Url::fromUri('base:' . static::$postUri);
  $this->field
    ->setSetting('file_extensions', '')
    ->save();
  \Drupal::service('router.builder')->rebuild();
  $response = $this->fileRequest($uri, $this->testFileData, [
    'Content-Disposition' => 'filename="example.txt"',
  ]);
  $expected = $this->getExpectedDocument(1, 'example.txt', TRUE);
  $this->assertResponseData($expected, $response);
  $this->assertFileExists('public://foobar/example.txt');
  $this->field
    ->setSetting('file_directory', '')
    ->save();
  $response = $this->fileRequest($uri, $this->testFileData, [
    'Content-Disposition' => 'filename="example.txt"',
  ]);
  $expected = $this->getExpectedDocument(2, 'example.txt', TRUE);
  $expected['data']['attributes']['uri']['value'] = 'public://example.txt';
  $expected['data']['attributes']['uri']['url'] = base_path() . $this->siteDirectory . '/files/example.txt';
  $this->assertResponseData($expected, $response);
  $this->assertFileExists('public://example.txt');
}

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