upgrades core to 8.4.2
This commit is contained in:
@@ -7,8 +7,8 @@ package: Web services
|
||||
dependencies:
|
||||
- serialization
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
@@ -17,6 +17,11 @@ services:
|
||||
tags:
|
||||
- { name: normalizer, priority: 20 }
|
||||
arguments: ['@entity.manager', '@http_client', '@hal.link_manager', '@module_handler']
|
||||
serializer.normalizer.timestamp_item.hal:
|
||||
class: Drupal\hal\Normalizer\TimestampItemNormalizer
|
||||
tags:
|
||||
# Priority must be higher than serializer.normalizer.field_item.hal.
|
||||
- { name: normalizer, priority: 20, bc: bc_timestamp_normalizer_unix, bc_config_name: 'serialization.settings' }
|
||||
serializer.normalizer.entity.hal:
|
||||
class: Drupal\hal\Normalizer\ContentEntityNormalizer
|
||||
arguments: ['@hal.link_manager', '@entity.manager', '@module_handler']
|
||||
|
||||
@@ -31,7 +31,7 @@ interface TypeLinkManagerInterface extends ConfigurableLinkManagerInterface {
|
||||
* @param array $context
|
||||
* Context from the normalizer/serializer operation.
|
||||
*
|
||||
* @return array | boolean
|
||||
* @return array|bool
|
||||
* If the URI matches a bundle, returns an array containing entity_type and
|
||||
* bundle. Otherwise, returns false.
|
||||
*/
|
||||
|
||||
@@ -74,15 +74,15 @@ class ContentEntityNormalizer extends NormalizerBase {
|
||||
|
||||
// If the fields to use were specified, only output those field values.
|
||||
if (isset($context['included_fields'])) {
|
||||
$fields = [];
|
||||
$field_items = [];
|
||||
foreach ($context['included_fields'] as $field_name) {
|
||||
$fields[] = $entity->get($field_name);
|
||||
$field_items[] = $entity->get($field_name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fields = $entity->getFields();
|
||||
$field_items = $entity->getFields();
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
foreach ($field_items as $field) {
|
||||
// Continue if the current user does not have access to view this field.
|
||||
if (!$field->access('view', $context['account'])) {
|
||||
continue;
|
||||
|
||||
@@ -21,25 +21,13 @@ class FieldItemNormalizer extends NormalizerBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field_item, $format = NULL, array $context = []) {
|
||||
$values = [];
|
||||
// We normalize each individual property, so each can do their own casting,
|
||||
// if needed.
|
||||
/** @var \Drupal\Core\TypedData\TypedDataInterface $property */
|
||||
foreach ($field_item as $property_name => $property) {
|
||||
$values[$property_name] = $this->serializer->normalize($property, $format, $context);
|
||||
}
|
||||
|
||||
if (isset($context['langcode'])) {
|
||||
$values['lang'] = $context['langcode'];
|
||||
}
|
||||
|
||||
// The values are wrapped in an array, and then wrapped in another array
|
||||
// keyed by field name so that field items can be merged by the
|
||||
// FieldNormalizer. This is necessary for the EntityReferenceItemNormalizer
|
||||
// to be able to place values in the '_links' array.
|
||||
$field = $field_item->getParent();
|
||||
return [
|
||||
$field->getName() => [$values],
|
||||
$field->getName() => [$this->normalizedFieldValues($field_item, $format, $context)],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -85,6 +73,35 @@ class FieldItemNormalizer extends NormalizerBase {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes field values for an item.
|
||||
*
|
||||
* @param \Drupal\Core\Field\FieldItemInterface $field_item
|
||||
* The field item instance.
|
||||
* @param string|null $format
|
||||
* The normalization format.
|
||||
* @param array $context
|
||||
* The context passed into the normalizer.
|
||||
*
|
||||
* @return array
|
||||
* An array of field item values, keyed by property name.
|
||||
*/
|
||||
protected function normalizedFieldValues(FieldItemInterface $field_item, $format, array $context) {
|
||||
$normalized = [];
|
||||
// We normalize each individual property, so each can do their own casting,
|
||||
// if needed.
|
||||
/** @var \Drupal\Core\TypedData\TypedDataInterface $property */
|
||||
foreach ($field_item as $property_name => $property) {
|
||||
$normalized[$property_name] = $this->serializer->normalize($property, $format, $context);
|
||||
}
|
||||
|
||||
if (isset($context['langcode'])) {
|
||||
$normalized['lang'] = $context['langcode'];
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a translated version of the field item instance.
|
||||
*
|
||||
@@ -93,7 +110,7 @@ class FieldItemNormalizer extends NormalizerBase {
|
||||
* entity. This is the reason for using target_instances, from which the
|
||||
* property path can be traversed up to the root.
|
||||
*
|
||||
* @param \Drupal\Core\Field\FieldItemInterface $field_item
|
||||
* @param \Drupal\Core\Field\FieldItemInterface $item
|
||||
* The untranslated field item instance.
|
||||
* @param $langcode
|
||||
* The langcode.
|
||||
|
||||
@@ -11,27 +11,25 @@ use Drupal\serialization\Normalizer\FieldNormalizer as SerializationFieldNormali
|
||||
class FieldNormalizer extends SerializationFieldNormalizer {
|
||||
|
||||
/**
|
||||
* The formats that the Normalizer can handle.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $format = ['hal_json'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field, $format = NULL, array $context = []) {
|
||||
public function normalize($field_items, $format = NULL, array $context = []) {
|
||||
$normalized_field_items = [];
|
||||
|
||||
// Get the field definition.
|
||||
$entity = $field->getEntity();
|
||||
$field_name = $field->getName();
|
||||
$field_definition = $field->getFieldDefinition();
|
||||
$entity = $field_items->getEntity();
|
||||
$field_name = $field_items->getName();
|
||||
$field_definition = $field_items->getFieldDefinition();
|
||||
|
||||
// If this field is not translatable, it can simply be normalized without
|
||||
// separating it into different translations.
|
||||
if (!$field_definition->isTranslatable()) {
|
||||
$normalized_field_items = $this->normalizeFieldItems($field, $format, $context);
|
||||
$normalized_field_items = $this->normalizeFieldItems($field_items, $format, $context);
|
||||
}
|
||||
// Otherwise, the languages have to be extracted from the entity and passed
|
||||
// in to the field item normalizer in the context. The langcode is appended
|
||||
@@ -40,22 +38,21 @@ class FieldNormalizer extends SerializationFieldNormalizer {
|
||||
foreach ($entity->getTranslationLanguages() as $language) {
|
||||
$context['langcode'] = $language->getId();
|
||||
$translation = $entity->getTranslation($language->getId());
|
||||
$translated_field = $translation->get($field_name);
|
||||
$normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context));
|
||||
$translated_field_items = $translation->get($field_name);
|
||||
$normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field_items, $format, $context));
|
||||
}
|
||||
}
|
||||
|
||||
// Merge deep so that links set in entity reference normalizers are merged
|
||||
// into the links property.
|
||||
$normalized = NestedArray::mergeDeepArray($normalized_field_items);
|
||||
return $normalized;
|
||||
return NestedArray::mergeDeepArray($normalized_field_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to normalize field items.
|
||||
*
|
||||
* @param \Drupal\Core\Field\FieldItemListInterface $field
|
||||
* The field object.
|
||||
* @param \Drupal\Core\Field\FieldItemListInterface $field_items
|
||||
* The field item list object.
|
||||
* @param string $format
|
||||
* The format.
|
||||
* @param array $context
|
||||
@@ -64,10 +61,10 @@ class FieldNormalizer extends SerializationFieldNormalizer {
|
||||
* @return array
|
||||
* The array of normalized field items.
|
||||
*/
|
||||
protected function normalizeFieldItems($field, $format, $context) {
|
||||
protected function normalizeFieldItems($field_items, $format, $context) {
|
||||
$normalized_field_items = [];
|
||||
if (!$field->isEmpty()) {
|
||||
foreach ($field as $field_item) {
|
||||
if (!$field_items->isEmpty()) {
|
||||
foreach ($field_items as $field_item) {
|
||||
$normalized_field_items[] = $this->serializer->normalize($field_item, $format, $context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,35 +11,21 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
abstract class NormalizerBase extends SerializationNormalizerBase implements DenormalizerInterface {
|
||||
|
||||
/**
|
||||
* The formats that the Normalizer can handle.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $formats = ['hal_json'];
|
||||
protected $format = ['hal_json'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = NULL) {
|
||||
return in_array($format, $this->formats) && parent::supportsNormalization($data, $format);
|
||||
}
|
||||
protected function checkFormat($format = NULL) {
|
||||
if (isset($this->formats)) {
|
||||
@trigger_error('::formats is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use ::$format instead. See https://www.drupal.org/node/2868275', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = NULL) {
|
||||
if (in_array($format, $this->formats) && (class_exists($this->supportedInterfaceOrClass) || interface_exists($this->supportedInterfaceOrClass))) {
|
||||
$target = new \ReflectionClass($type);
|
||||
$supported = new \ReflectionClass($this->supportedInterfaceOrClass);
|
||||
if ($supported->isInterface()) {
|
||||
return $target->implementsInterface($this->supportedInterfaceOrClass);
|
||||
}
|
||||
else {
|
||||
return ($target->getName() == $this->supportedInterfaceOrClass || $target->isSubclassOf($this->supportedInterfaceOrClass));
|
||||
}
|
||||
$this->format = $this->formats;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return parent::checkFormat($format);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\hal\Normalizer;
|
||||
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem;
|
||||
use Drupal\serialization\Normalizer\TimeStampItemNormalizerTrait;
|
||||
|
||||
/**
|
||||
* Converts values for TimestampItem to and from common formats for hal.
|
||||
*/
|
||||
class TimestampItemNormalizer extends FieldItemNormalizer {
|
||||
|
||||
use TimeStampItemNormalizerTrait;
|
||||
|
||||
/**
|
||||
* The interface or class that this Normalizer supports.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $supportedInterfaceOrClass = TimestampItem::class;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function normalizedFieldValues(FieldItemInterface $field_item, $format, array $context) {
|
||||
$normalized = parent::normalizedFieldValues($field_item, $format, $context);
|
||||
return $this->processNormalizedValues($normalized);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-08-16
|
||||
version: '8.3.7'
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1502903957
|
||||
datestamp: 1509719929
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ContactForm;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ContactForm\ContactFormResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ContactFormHalJsonAnonTest extends ContactFormResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ContactForm;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ContactForm\ContactFormResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ContactFormHalJsonBasicAuthTest extends ContactFormResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ContactForm;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ContactForm\ContactFormResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ContactFormHalJsonCookieTest extends ContactFormResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\DateFormat;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\DateFormat\DateFormatResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class DateFormatHalJsonAnonTest extends DateFormatResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\DateFormat;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\DateFormat\DateFormatResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class DateFormatHalJsonBasicAuthTest extends DateFormatResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\DateFormat;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\DateFormat\DateFormatResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class DateFormatHalJsonCookieTest extends DateFormatResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityFormMode;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityFormMode\EntityFormModeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityFormModeHalJsonAnonTest extends EntityFormModeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityFormMode;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityFormMode\EntityFormModeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityFormModeHalJsonBasicAuthTest extends EntityFormModeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityFormMode;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityFormMode\EntityFormModeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityFormModeHalJsonCookieTest extends EntityFormModeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestBundle;
|
||||
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle\EntityTestBundleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityTestBundleHalJsonAnonTest extends EntityTestBundleResourceTestBase {
|
||||
|
||||
use HalEntityNormalizationTrait;
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestBundle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle\EntityTestBundleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityTestBundleHalJsonBasicAuthTest extends EntityTestBundleResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestBundle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTestBundle\EntityTestBundleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityTestBundleHalJsonCookieTest extends EntityTestBundleResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityViewMode;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityViewMode\EntityViewModeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityViewModeHalJsonAnonTest extends EntityViewModeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityViewMode;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityViewMode\EntityViewModeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityViewModeHalJsonBasicAuthTest extends EntityViewModeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityViewMode;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityViewMode\EntityViewModeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityViewModeHalJsonCookieTest extends EntityViewModeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+4
-4
@@ -101,18 +101,18 @@ trait HalEntityNormalizationTrait {
|
||||
$normalization['_links']['type'] = Url::fromUri('base:rest/type/' . static::$entityTypeId . '/bad_bundle_name');
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format);
|
||||
|
||||
// DX: 400 when incorrect entity type bundle is specified.
|
||||
// DX: 422 when incorrect entity type bundle is specified.
|
||||
$response = $this->request($method, $url, $request_options);
|
||||
$this->assertResourceErrorResponse(400, 'No entity type(s) specified', $response);
|
||||
$this->assertResourceErrorResponse(422, 'No entity type(s) specified', $response);
|
||||
|
||||
|
||||
unset($normalization['_links']['type']);
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format);
|
||||
|
||||
|
||||
// DX: 400 when no entity type bundle is specified.
|
||||
// DX: 422 when no entity type bundle is specified.
|
||||
$response = $this->request($method, $url, $request_options);
|
||||
$this->assertResourceErrorResponse(400, 'The type link relation must be specified.', $response);
|
||||
$this->assertResourceErrorResponse(422, 'The type link relation must be specified.', $response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Media;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Media\MediaResourceTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MediaHalJsonAnonTest extends MediaResourceTestBase {
|
||||
|
||||
use HalEntityNormalizationTrait;
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
$default_normalization = parent::getExpectedNormalizedEntity();
|
||||
|
||||
$normalization = $this->applyHalFieldNormalization($default_normalization);
|
||||
|
||||
$file = File::load(1);
|
||||
$thumbnail = File::load(2);
|
||||
$author = User::load($this->entity->getOwnerId());
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/media/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/media/camelids',
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
|
||||
[
|
||||
'href' => $file->url(),
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/revision_user' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [
|
||||
[
|
||||
'href' => $thumbnail->url(),
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/uid' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
],
|
||||
'_embedded' => [
|
||||
$this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $file->url(),
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/file/file',
|
||||
],
|
||||
],
|
||||
'lang' => 'en',
|
||||
'uri' => [
|
||||
[
|
||||
'value' => $file->url(),
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $file->uuid(),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/revision_user' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/user/user',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $author->uuid(),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $thumbnail->url(),
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/file/file',
|
||||
],
|
||||
],
|
||||
'lang' => 'en',
|
||||
'uri' => [
|
||||
[
|
||||
'value' => $thumbnail->url(),
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $thumbnail->uuid(),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/media/camelids/uid' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/user/user',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $author->uuid(),
|
||||
],
|
||||
],
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/media/camelids',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Media;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MediaHalJsonBasicAuthTest extends MediaHalJsonAnonTest {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Media;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MediaHalJsonCookieTest extends MediaHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\MediaType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\MediaType\MediaTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MediaTypeHalJsonAnonTest extends MediaTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\MediaType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\MediaType\MediaTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MediaTypeHalJsonBasicAuthTest extends MediaTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\MediaType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\MediaType\MediaTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MediaTypeHalJsonCookieTest extends MediaTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Menu;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Menu\MenuResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MenuHalJsonAnonTest extends MenuResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Menu;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Menu\MenuResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MenuHalJsonBasicAuthTest extends MenuResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Menu;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Menu\MenuResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MenuHalJsonCookieTest extends MenuResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -34,11 +34,12 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'revision_timestamp',
|
||||
'created',
|
||||
'changed',
|
||||
'promote',
|
||||
'sticky',
|
||||
'revision_timestamp',
|
||||
'path',
|
||||
'revision_uid',
|
||||
];
|
||||
|
||||
@@ -54,24 +55,39 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/node/1?_format=hal_json',
|
||||
'href' => $this->baseUrl . '/llama?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/node/camelids',
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/node/camelids/uid' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
],
|
||||
],
|
||||
'_embedded' => [
|
||||
$this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/user/user',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
['value' => $author->uuid()]
|
||||
],
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/node/camelids/uid' => [
|
||||
[
|
||||
'_links' => [
|
||||
@@ -88,21 +104,6 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/user/user',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
['value' => $author->uuid()]
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ResponsiveImageStyle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ResponsiveImageStyle\ResponsiveImageStyleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ResponsiveImageStyleHalJsonAnonTest extends ResponsiveImageStyleResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ResponsiveImageStyle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ResponsiveImageStyle\ResponsiveImageStyleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ResponsiveImageStyleHalJsonBasicAuthTest extends ResponsiveImageStyleResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ResponsiveImageStyle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ResponsiveImageStyle\ResponsiveImageStyleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ResponsiveImageStyleHalJsonCookieTest extends ResponsiveImageStyleResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class TermHalJsonAnonTest extends TermResourceTestBase {
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/taxonomy/term/1?_format=hal_json',
|
||||
'href' => $this->baseUrl . '/llama?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Tour;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Tour\TourResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class TourHalJsonAnonTest extends TourResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Tour;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Tour\TourResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class TourHalJsonBasicAuthTest extends TourResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Tour;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Tour\TourResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class TourHalJsonCookieTest extends TourResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\View;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\View\ViewResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ViewHalJsonAnonTest extends ViewResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\View;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\View\ViewResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ViewHalJsonBasicAuthTest extends ViewResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\View;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\View\ViewResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ViewHalJsonCookieTest extends ViewResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests that 'hal.settings' is created, to store 'link_domain'.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* 'link_domain' is migrated from 'rest.settings' to 'hal.settings'.
|
||||
|
||||
@@ -62,8 +62,7 @@ class DenormalizeTest extends NormalizerTestBase {
|
||||
|
||||
// No type.
|
||||
$data_with_no_type = [
|
||||
'_links' => [
|
||||
],
|
||||
'_links' => [],
|
||||
];
|
||||
try {
|
||||
$this->serializer->denormalize($data_with_no_type, $this->entityClass, $this->format);
|
||||
@@ -136,7 +135,7 @@ class DenormalizeTest extends NormalizerTestBase {
|
||||
],
|
||||
'field_test_text' => [],
|
||||
];
|
||||
$entity = $this->serializer->denormalize($data, get_class($entity), $this->format, [ 'target_instance' => $entity ]);
|
||||
$entity = $this->serializer->denormalize($data, get_class($entity), $this->format, ['target_instance' => $entity]);
|
||||
$this->assertEqual($entity->field_test_text->count(), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class EntityTranslationNormalizeTest extends NormalizerTestBase {
|
||||
|
||||
$node = Node::create([
|
||||
'title' => $this->randomMachineName(),
|
||||
'uid' => $user->id(),
|
||||
'uid' => (int) $user->id(),
|
||||
'type' => $node_type->id(),
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'langcode' => 'en',
|
||||
|
||||
@@ -44,8 +44,7 @@ class FileNormalizeTest extends NormalizerTestBase {
|
||||
|
||||
$expected_array = [
|
||||
'uri' => [
|
||||
[
|
||||
'value' => file_create_url($file->getFileUri())],
|
||||
['value' => file_create_url($file->getFileUri())],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class HalLinkManagerTest extends KernelTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [ 'hal', 'hal_test', 'serialization', 'system', 'node', 'user', 'field'];
|
||||
public static $modules = ['hal', 'hal_test', 'serialization', 'system', 'node', 'user', 'field'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -46,36 +46,123 @@ class HalLinkManagerTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* @covers ::getTypeUri
|
||||
* @dataProvider providerTestGetTypeUri
|
||||
*/
|
||||
public function testGetTypeUri() {
|
||||
public function testGetTypeUri($link_domain, $entity_type, $bundle, array $context, $expected_return, array $expected_context) {
|
||||
$hal_settings = \Drupal::configFactory()->getEditable('hal.settings');
|
||||
|
||||
if ($link_domain === NULL) {
|
||||
$hal_settings->clear('link_domain');
|
||||
}
|
||||
else {
|
||||
$hal_settings->set('link_domain', $link_domain)->save(TRUE);
|
||||
}
|
||||
|
||||
/* @var \Drupal\rest\LinkManager\TypeLinkManagerInterface $type_manager */
|
||||
$type_manager = \Drupal::service('hal.link_manager.type');
|
||||
$base = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
|
||||
$link = $type_manager->getTypeUri('node', 'page');
|
||||
$this->assertSame($link, $base . 'rest/type/node/page');
|
||||
// Now with optional context.
|
||||
$link = $type_manager->getTypeUri('node', 'page', ['hal_test' => TRUE]);
|
||||
$this->assertSame($link, 'hal_test_type');
|
||||
// Test BC: hook_rest_type_uri_alter().
|
||||
$link = $type_manager->getTypeUri('node', 'page', ['rest_test' => TRUE]);
|
||||
$this->assertSame($link, 'rest_test_type');
|
||||
|
||||
$link = $type_manager->getTypeUri($entity_type, $bundle, $context);
|
||||
$this->assertSame($link, str_replace('BASE_URL/', Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), $expected_return));
|
||||
$this->assertEquals($context, $expected_context);
|
||||
}
|
||||
|
||||
public function providerTestGetTypeUri() {
|
||||
$base_test_case = [
|
||||
'link_domain' => NULL,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
];
|
||||
|
||||
return [
|
||||
'site URL' => $base_test_case + [
|
||||
'context' => [],
|
||||
'link_domain' => NULL,
|
||||
'expected return' => 'BASE_URL/rest/type/node/page',
|
||||
'expected context' => [],
|
||||
],
|
||||
// Test hook_hal_type_uri_alter().
|
||||
'site URL, with optional context, to test hook_hal_type_uri_alter()' => $base_test_case + [
|
||||
'context' => ['hal_test' => TRUE],
|
||||
'expected return' => 'hal_test_type',
|
||||
'expected context' => ['hal_test' => TRUE],
|
||||
],
|
||||
// Test hook_rest_type_uri_alter() — for backwards compatibility.
|
||||
'site URL, with optional context, to test hook_rest_type_uri_alter()' => $base_test_case + [
|
||||
'context' => ['rest_test' => TRUE],
|
||||
'expected return' => 'rest_test_type',
|
||||
'expected context' => ['rest_test' => TRUE],
|
||||
],
|
||||
'configured URL' => [
|
||||
'link_domain' => 'http://llamas-rock.com/for-real/',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'context' => [],
|
||||
'expected return' => 'http://llamas-rock.com/for-real/rest/type/node/page',
|
||||
'expected context' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getRelationUri
|
||||
* @dataProvider providerTestGetRelationUri
|
||||
*/
|
||||
public function testGetRelationUri() {
|
||||
public function testGetRelationUri($link_domain, $entity_type, $bundle, $field_name, array $context, $expected_return, array $expected_context) {
|
||||
$hal_settings = \Drupal::configFactory()->getEditable('hal.settings');
|
||||
|
||||
if ($link_domain === NULL) {
|
||||
$hal_settings->clear('link_domain');
|
||||
}
|
||||
else {
|
||||
$hal_settings->set('link_domain', $link_domain)->save(TRUE);
|
||||
}
|
||||
|
||||
/* @var \Drupal\rest\LinkManager\RelationLinkManagerInterface $relation_manager */
|
||||
$relation_manager = \Drupal::service('hal.link_manager.relation');
|
||||
$base = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
|
||||
$link = $relation_manager->getRelationUri('node', 'page', 'field_ref');
|
||||
$this->assertSame($link, $base . 'rest/relation/node/page/field_ref');
|
||||
// Now with optional context.
|
||||
$link = $relation_manager->getRelationUri('node', 'page', 'foobar', ['hal_test' => TRUE]);
|
||||
$this->assertSame($link, 'hal_test_relation');
|
||||
// Test BC: hook_rest_relation_uri_alter().
|
||||
$link = $relation_manager->getRelationUri('node', 'page', 'foobar', ['rest_test' => TRUE]);
|
||||
$this->assertSame($link, 'rest_test_relation');
|
||||
|
||||
$link = $relation_manager->getRelationUri($entity_type, $bundle, $field_name, $context);
|
||||
$this->assertSame($link, str_replace('BASE_URL/', Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), $expected_return));
|
||||
$this->assertEquals($context, $expected_context);
|
||||
}
|
||||
|
||||
public function providerTestGetRelationUri() {
|
||||
$field_name = $this->randomMachineName();
|
||||
$base_test_case = [
|
||||
'link_domain' => NULL,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'field_name' => $field_name,
|
||||
];
|
||||
|
||||
return [
|
||||
'site URL' => $base_test_case + [
|
||||
'context' => [],
|
||||
'link_domain' => NULL,
|
||||
'expected return' => 'BASE_URL/rest/relation/node/page/' . $field_name,
|
||||
'expected context' => [],
|
||||
],
|
||||
// Test hook_hal_relation_uri_alter().
|
||||
'site URL, with optional context, to test hook_hal_relation_uri_alter()' => $base_test_case + [
|
||||
'context' => ['hal_test' => TRUE],
|
||||
'expected return' => 'hal_test_relation',
|
||||
'expected context' => ['hal_test' => TRUE],
|
||||
],
|
||||
// Test hook_rest_relation_uri_alter() — for backwards compatibility.
|
||||
'site URL, with optional context, to test hook_rest_relation_uri_alter()' => $base_test_case + [
|
||||
'context' => ['rest_test' => TRUE],
|
||||
'expected return' => 'rest_test_relation',
|
||||
'expected context' => ['rest_test' => TRUE],
|
||||
],
|
||||
'configured URL' => [
|
||||
'link_domain' => 'http://llamas-rock.com/for-real/',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'field_name' => $field_name,
|
||||
'context' => [],
|
||||
'expected return' => 'http://llamas-rock.com/for-real/rest/relation/node/page/' . $field_name,
|
||||
'expected context' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user