fileRequest example

return $entity_test;
  }

  /** * Tests using the file upload POST route; needs second request to "use" file. */
  public function testPostFileUpload() {
    $uri = Url::fromUri('base:' . static::$postUri);

    // DX: 405 when read-only mode is enabled.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertResourceErrorResponse(405, sprintf("JSON:API is configured to accept only read operations. Site administrators can configure this at %s.", Url::fromUri('base:/admin/config/services/jsonapi')->setAbsolute()->toString(TRUE)->getGeneratedUrl())$uri$response);
    $this->assertSame(['GET']$response->getHeader('Allow'));

    $this->config('jsonapi.settings')->set('read_only', FALSE)->save(TRUE);

    // DX: 403 when unauthorized.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('POST')$uri$response);

    $this->setUpAuthorization('POST');

    
/** * Tests using the file upload POST route. */
  public function testPostFileUpload() {
    $this->initAuthentication();

    $this->provisionResource([static::$format]static::$auth ? [static::$auth] : []['POST']);

    $uri = Url::fromUri('base:' . static::$postUri);

    // DX: 403 when unauthorized.     $response = $this->fileRequest($uri$this->testFileData);
    $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('POST')$response);

    $this->setUpAuthorization('POST');

    // 404 when the field name is invalid.     $invalid_uri = Url::fromUri('base:file/upload/entity_test/entity_test/field_rest_file_test_invalid');
    $response = $this->fileRequest($invalid_uri$this->testFileData);
    $this->assertResourceErrorResponse(404, 'Field "field_rest_file_test_invalid" does not exist', $response);

    // This request will have the default 'application/octet-stream' content     // type header.
Home | Imprint | This part of the site doesn't use cookies.