You are here

protected function FileTest::getExpectedDocument in Drupal 8

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

Returns the expected JSON:API document for the entity.

Return value

array A JSON:API response document.

Overrides ResourceTestBase::getExpectedDocument

See also

::createEntity()

File

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

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(),
            'type' => 'user--user',
          ],
          'links' => [
            'related' => [
              'href' => $self_url . '/uid',
            ],
            'self' => [
              'href' => $self_url . '/relationships/uid',
            ],
          ],
        ],
      ],
    ],
  ];
}