function FileTest::getExpectedDocument

Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/FileTest.php \Drupal\Tests\jsonapi\Functional\FileTest::getExpectedDocument()
  2. 10 core/modules/jsonapi/tests/src/Functional/FileTest.php \Drupal\Tests\jsonapi\Functional\FileTest::getExpectedDocument()
  3. 11.x core/modules/jsonapi/tests/src/Functional/FileTest.php \Drupal\Tests\jsonapi\Functional\FileTest::getExpectedDocument()

Overrides ResourceTestBase::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',
                        ],
                    ],
                ],
            ],
        ],
    ];
}

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