protected function ProductVariationResourceTest::getExpectedDocument in Commerce Core 8.2
Returns the expected JSON:API document for the entity.
Return value
array A JSON:API response document.
Overrides ResourceTestBase::getExpectedDocument
See also
::createEntity()
File
- modules/
product/ tests/ src/ Functional/ Jsonapi/ ProductVariationResourceTest.php, line 125
Class
- ProductVariationResourceTest
- JSON:API resource test for variations.
Namespace
Drupal\Tests\commerce_product\Functional\JsonapiCode
protected function getExpectedDocument() {
$base_url = Url::fromUri('base:/jsonapi/commerce_product_variation/default/' . $this->entity
->uuid())
->setAbsolute();
$self_url = clone $base_url;
return [
'jsonapi' => [
'meta' => [
'links' => [
'self' => [
'href' => 'http://jsonapi.org/format/1.0/',
],
],
],
'version' => '1.0',
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'commerce_product_variation--default',
'links' => [
'self' => [
'href' => $self_url
->toString(),
],
],
'attributes' => [
'changed' => (new \DateTime())
->setTimestamp($this->entity
->getChangedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'created' => (new \DateTime())
->setTimestamp($this->entity
->getCreatedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'default_langcode' => TRUE,
'drupal_internal__variation_id' => (int) $this->entity
->id(),
'langcode' => 'en',
'list_price' => NULL,
'price' => [
'currency_code' => 'USD',
'formatted' => '$4.00',
'number' => '4.00',
],
'sku' => '456DEF',
'status' => TRUE,
'title' => $this->entity
->label(),
],
'relationships' => [
'commerce_product_variation_type' => [
'data' => [
'id' => ProductVariationType::load('default')
->uuid(),
'type' => 'commerce_product_variation_type--commerce_product_variation_type',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/commerce_product_variation_type',
],
'self' => [
'href' => $base_url
->toString() . '/relationships/commerce_product_variation_type',
],
],
],
'product_id' => [
'data' => [
'id' => $this->product
->uuid(),
'type' => 'commerce_product--default',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/product_id',
],
'self' => [
'href' => $base_url
->toString() . '/relationships/product_id',
],
],
],
'uid' => [
'data' => [
'id' => $this->entity
->getOwner()
->uuid(),
'type' => 'user--user',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/uid',
],
'self' => [
'href' => $base_url
->toString() . '/relationships/uid',
],
],
],
],
],
'links' => [
'self' => [
'href' => $self_url
->toString(),
],
],
];
}