You are here

public function FileHalJsonAnonTest::testGetBcUriField in Drupal 8

@group legacy @expectedDeprecation Replacing the file uri with the URL is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the provided url property instead and disable hal.settings:bc_file_uri_as_url_normalizer. See https://www.drupal.org/node/2925783

See also

hal_update_8501()

File

core/modules/file/tests/src/Functional/Hal/FileHalJsonAnonTest.php, line 126

Class

FileHalJsonAnonTest
@group hal

Namespace

Drupal\Tests\file\Functional\Hal

Code

public function testGetBcUriField() {
  $this
    ->config('hal.settings')
    ->set('bc_file_uri_as_url_normalizer', TRUE)
    ->save(TRUE);
  $this
    ->initAuthentication();
  $url = $this
    ->getEntityResourceUrl();
  $url
    ->setOption('query', [
    '_format' => static::$format,
  ]);
  $request_options = $this
    ->getAuthenticationRequestOptions('GET');
  $this
    ->provisionEntityResource();
  $this
    ->setUpAuthorization('GET');
  $response = $this
    ->request('GET', $url, $request_options);
  $expected = $this
    ->getExpectedNormalizedEntity();
  static::recursiveKSort($expected);
  $actual = $this->serializer
    ->decode((string) $response
    ->getBody(), static::$format);
  static::recursiveKSort($actual);
  $this
    ->assertSame($expected, $actual);

  // Explicitly assert that $file->uri->value is an absolute file URL, unlike
  // the default normalization.
  $this
    ->assertSame($this->baseUrl . '/' . $this->siteDirectory . '/files/drupal.txt', $actual['uri'][0]['value']);
}