You are here

protected function FileTest::getExpectedDocument in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/FileTest.php \Drupal\Tests\jsonapi\Functional\FileTest::getExpectedDocument()
  2. 9 core/modules/jsonapi/tests/src/Functional/FileTest.php \Drupal\Tests\jsonapi\Functional\FileTest::getExpectedDocument()

File

core/modules/jsonapi/tests/src/Functional/FileTest.php, line 131

Class

FileTest
JSON:API integration test for the "File" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() {
  $self_url = Url::fromUri('base:/jsonapi/file/file/' . $this->entity
    ->uuid())
    ->setAbsolute()
    ->toString(TRUE)
    ->getGeneratedUrl();
  return [
    'jsonapi' => [
      'meta' => [
        'links' => [
          'self' => [
            'href' => 'http://jsonapi.org/format/1.0/',
          ],
        ],
      ],
      'version' => '1.0',
    ],
    'links' => [
      'self' => [
        'href' => $self_url,
      ],
    ],
    'data' => [
      'id' => $this->entity
        ->uuid(),
      'type' => 'file--file',
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'attributes' => [
        'created' => (new \DateTime())
          ->setTimestamp($this->entity
          ->getCreatedTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'changed' => (new \DateTime())
          ->setTimestamp($this->entity
          ->getChangedTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'filemime' => 'text/plain',
        'filename' => 'drupal.txt',
        'filesize' => (int) $this->entity
          ->getSize(),
        'langcode' => 'en',
        'status' => TRUE,
        'uri' => [
          'url' => base_path() . $this->siteDirectory . '/files/drupal.txt',
          'value' => 'public://drupal.txt',
        ],
        'drupal_internal__fid' => 1,
      ],
      'relationships' => [
        'uid' => [
          'data' => [
            'id' => $this->author
              ->uuid(),
            'meta' => [
              'drupal_internal__target_id' => (int) $this->author
                ->id(),
            ],
            'type' => 'user--user',
          ],
          'links' => [
            'related' => [
              'href' => $self_url . '/uid',
            ],
            'self' => [
              'href' => $self_url . '/relationships/uid',
            ],
          ],
        ],
      ],
    ],
  ];
}