updated core from 8.4 to 8.5 : bug with login_destination

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-13 14:01:21 +01:00
parent 0d78da249b
commit e668535a4e
3486 changed files with 89604 additions and 33283 deletions
@@ -5,8 +5,8 @@ package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -0,0 +1,74 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\BlockContent;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\BlockContent\BlockContentResourceTestBase;
/**
* @group hal
*/
class BlockContentHalJsonAnonTest extends BlockContentResourceTestBase {
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);
return $normalization + [
'_links' => [
'self' => [
'href' => $this->baseUrl . '/block/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/block_content/basic',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/block_content/basic',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
// The 'url.site' cache context is added for '_links' in the response.
return Cache::mergeTags(parent::getExpectedCacheContexts(), ['url.site']);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\BlockContent;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class BlockContentHalJsonBasicAuthTest extends BlockContentHalJsonAnonTest {
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\BlockContent;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class BlockContentHalJsonCookieTest extends BlockContentHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -25,11 +25,11 @@ class CommentHalJsonAnonTest extends CommentHalJsonTestBase {
* @see ::setUpAuthorization
*/
protected static $patchProtectedFieldNames = [
'entity_id',
'changed',
'thread',
'entity_type',
'field_name',
'entity_id',
];
}
@@ -26,25 +26,6 @@ abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*
* The HAL+JSON format causes different PATCH-protected fields. For some
* reason, the 'pid' and 'homepage' fields are NOT PATCH-protected, even
* though they are for non-HAL+JSON serializations.
*
* @todo fix in https://www.drupal.org/node/2824271
*/
protected static $patchProtectedFieldNames = [
'status',
'created',
'changed',
'thread',
'entity_type',
'field_name',
'entity_id',
'uid',
];
/**
* {@inheritdoc}
@@ -2,7 +2,7 @@
namespace Drupal\Tests\hal\Functional\EntityResource\ConfigurableLanguage;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage\ConfigurableLanguageResourceTestBase;
/**
@@ -10,7 +10,7 @@ use Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage\Configurabl
*/
class ConfigurableLanguageHalJsonBasicAuthTest extends ConfigurableLanguageResourceTestBase {
use BasicAuthResourceTestTrait;
use BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* {@inheritdoc}
@@ -2,7 +2,7 @@
namespace Drupal\Tests\hal\Functional\EntityResource\ContentLanguageSettings;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\BasicAuthResourceWithInterfaceTranslationTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\ContentLanguageSettings\ContentLanguageSettingsResourceTestBase;
/**
@@ -10,7 +10,7 @@ use Drupal\Tests\rest\Functional\EntityResource\ContentLanguageSettings\ContentL
*/
class ContentLanguageSettingsHalJsonBasicAuthTest extends ContentLanguageSettingsResourceTestBase {
use BasicAuthResourceTestTrait;
use BasicAuthResourceWithInterfaceTranslationTestTrait;
/**
* {@inheritdoc}
@@ -0,0 +1,30 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\EntityFormDisplay;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityFormDisplay\EntityFormDisplayResourceTestBase;
/**
* @group hal
*/
class EntityFormDisplayHalJsonAnonTest extends EntityFormDisplayResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\EntityFormDisplay;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityFormDisplay\EntityFormDisplayResourceTestBase;
/**
* @group hal
*/
class EntityFormDisplayHalJsonBasicAuthTest extends EntityFormDisplayResourceTestBase {
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\EntityFormDisplay;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityFormDisplay\EntityFormDisplayResourceTestBase;
/**
* @group hal
*/
class EntityFormDisplayHalJsonCookieTest extends EntityFormDisplayResourceTestBase {
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';
}
@@ -5,6 +5,7 @@ namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
use Drupal\user\Entity\User;
/**
@@ -14,6 +15,7 @@ class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
/**
* {@inheritdoc}
@@ -0,0 +1,100 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
use Drupal\Core\Cache\Cache;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Test that internal properties are not exposed in the 'hal_json' format.
*
* @group hal
*/
class EntityTestHalJsonInternalPropertyNormalizerTest extends EntityTestHalJsonAnonTest {
use AnonResourceTestTrait, HalEntityNormalizationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
// The 'internal_value' property in test field type will not be returned in
// normalization because setInternal(FALSE) was not called for this
// property.
// @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
$normalization['field_test_internal'] = [
[
'value' => 'This value shall not be internal!',
'non_internal_value' => 'Computed! This value shall not be internal!',
],
];
return $normalization;
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'type' => 'internal_property_test',
'cardinality' => 1,
'translatable' => FALSE,
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'bundle' => 'entity_test',
'label' => 'Test field with internal and non-internal properties',
])->save();
}
$entity = parent::createEntity();
$entity->field_test_internal = [
'value' => 'This value shall not be internal!',
];
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'field_test_internal' => [
[
'value' => 'This value shall not be internal!',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['request_format']);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), ['you_are_it', 'no_tag_backs']);
}
}
@@ -0,0 +1,30 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\EntityViewDisplay;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityViewDisplay\EntityViewDisplayResourceTestBase;
/**
* @group hal
*/
class EntityViewDisplayHalJsonAnonTest extends EntityViewDisplayResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\EntityViewDisplay;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class EntityViewDisplayHalJsonBasicAuthTest extends EntityViewDisplayHalJsonAnonTest {
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\EntityViewDisplay;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class EntityViewDisplayHalJsonCookieTest extends EntityViewDisplayHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,147 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\File;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\File\FileResourceTestBase;
/**
* @group hal
*/
class FileHalJsonAnonTest extends FileResourceTestBase {
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);
$url = file_create_url($this->entity->getFileUri());
// @see \Drupal\Tests\hal\Functional\EntityResource\File\FileHalJsonAnonTest::testGetBcUriField()
if ($this->config('hal.settings')->get('bc_file_uri_as_url_normalizer')) {
$normalization['uri'][0]['value'] = $url;
}
$uid = $this->author->id();
return $normalization + [
'_embedded' => [
$this->baseUrl . '/rest/relation/file/file/uid' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . "/user/$uid?_format=hal_json",
],
'type' => [
'href' => $this->baseUrl . '/rest/type/user/user',
],
],
'uuid' => [
[
'value' => $this->author->uuid(),
],
],
],
],
],
'_links' => [
'self' => [
'href' => $url,
],
'type' => [
'href' => $this->baseUrl . '/rest/type/file/file',
],
$this->baseUrl . '/rest/relation/file/file/uid' => [
[
'href' => $this->baseUrl . "/user/$uid?_format=hal_json",
],
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/file/file',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:hal.settings']);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return [
'url.site',
'user.permissions',
];
}
/**
* @see hal_update_8501()
*/
public function testGetBcUriField() {
$this->config('hal.settings')->set('bc_file_uri_as_url_normalizer', TRUE)->save(TRUE);
$this->initAuthentication();
$url = $this->getEntityResourceUrl();
$url->setOption('query', ['_format' => static::$format]);
$request_options = $this->getAuthenticationRequestOptions('GET');
$this->provisionEntityResource();
$this->setUpAuthorization('GET');
$response = $this->request('GET', $url, $request_options);
$expected = $this->getExpectedNormalizedEntity();
static::recursiveKSort($expected);
$actual = $this->serializer->decode((string) $response->getBody(), static::$format);
static::recursiveKSort($actual);
$this->assertSame($expected, $actual);
// Explicitly assert that $file->uri->value is an absolute file URL, unlike
// the default normalization.
$this->assertSame($this->baseUrl . '/' . $this->siteDirectory . '/files/drupal.txt', $actual['uri'][0]['value']);
}
/**
* {@inheritdoc}
*/
public function testPatch() {
// @todo https://www.drupal.org/node/1927648
$this->markTestSkipped();
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\File;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class FileHalJsonBasicAuthTest extends FileHalJsonAnonTest {
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\File;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class FileHalJsonCookieTest extends FileHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -70,24 +70,6 @@ trait HalEntityNormalizationTrait {
return $normalization;
}
/**
* {@inheritdoc}
*/
protected function removeFieldsFromNormalization(array $normalization, $field_names) {
$normalization = parent::removeFieldsFromNormalization($normalization, $field_names);
foreach ($field_names as $field_name) {
$relation_url = Url::fromUri('base:rest/relation/' . static::$entityTypeId . '/' . $this->entity->bundle() . '/' . $field_name)
->setAbsolute(TRUE)
->toString();
$normalization['_links'] = array_diff_key($normalization['_links'], [$relation_url => TRUE]);
if (isset($normalization['_embedded'])) {
$normalization['_embedded'] = array_diff_key($normalization['_embedded'], [$relation_url => TRUE]);
}
}
return array_diff_key($normalization, array_flip($field_names));
}
/**
* {@inheritdoc}
*/
@@ -2,6 +2,7 @@
namespace Drupal\Tests\hal\Functional\EntityResource\Media;
use Drupal\Core\Cache\Cache;
use Drupal\file\Entity\File;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
@@ -50,7 +51,7 @@ class MediaHalJsonAnonTest extends MediaResourceTestBase {
'type' => [
'href' => $this->baseUrl . '/rest/type/media/camelids',
],
$this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
$this->baseUrl . '/rest/relation/media/camelids/field_media_file' => [
[
'href' => $file->url(),
'lang' => 'en',
@@ -75,7 +76,7 @@ class MediaHalJsonAnonTest extends MediaResourceTestBase {
],
],
'_embedded' => [
$this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
$this->baseUrl . '/rest/relation/media/camelids/field_media_file' => [
[
'_links' => [
'self' => [
@@ -86,11 +87,6 @@ class MediaHalJsonAnonTest extends MediaResourceTestBase {
],
],
'lang' => 'en',
'uri' => [
[
'value' => $file->url(),
],
],
'uuid' => [
[
'value' => $file->uuid(),
@@ -126,11 +122,6 @@ class MediaHalJsonAnonTest extends MediaResourceTestBase {
],
],
'lang' => 'en',
'uri' => [
[
'value' => $thumbnail->url(),
],
],
'uuid' => [
[
'value' => $thumbnail->uuid(),
@@ -173,4 +164,11 @@ class MediaHalJsonAnonTest extends MediaResourceTestBase {
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:hal.settings']);
}
}
@@ -0,0 +1,45 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Message;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\Message\MessageResourceTestBase;
/**
* @group hal
*/
class MessageHalJsonAnonTest extends MessageResourceTestBase {
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 getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/contact_message/camelids',
],
],
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\Message;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class MessageHalJsonBasicAuthTest extends MessageHalJsonAnonTest {
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\Message;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class MessageHalJsonCookieTest extends MessageHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -30,19 +30,6 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [
'revision_timestamp',
'created',
'changed',
'promote',
'sticky',
'path',
'revision_uid',
];
/**
* {@inheritdoc}
*/
@@ -20,6 +20,20 @@ class FileDenormalizeTest extends BrowserTestBase {
*/
public static $modules = ['hal', 'file', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// @todo Remove this work-around in https://www.drupal.org/node/1927648.
// @see hal_update_8501()
\Drupal::configFactory()
->getEditable('hal.settings')
->set('bc_file_uri_as_url_normalizer', TRUE)
->save(TRUE);
}
/**
* Tests file entity denormalization.
*/
@@ -83,6 +83,8 @@ class EntityTranslationNormalizeTest extends NormalizerTestBase {
$this->assertSame($node->getTitle(), $denormalized_node->getTitle());
$this->assertSame($translation->getTitle(), $denormalized_node->getTranslation('de')->getTitle());
$original_values['revision_default'] = [];
$original_translation_values['revision_default'] = [];
$this->assertEquals($original_values, $denormalized_node->toArray(), 'Node values are restored after normalizing and denormalizing.');
$this->assertEquals($original_translation_values, $denormalized_node->getTranslation('en')->toArray(), 'Node values are restored after normalizing and denormalizing.');
}
@@ -44,7 +44,10 @@ class FileNormalizeTest extends NormalizerTestBase {
$expected_array = [
'uri' => [
['value' => file_create_url($file->getFileUri())],
[
'value' => $file->getFileUri(),
'url' => file_url_transform_relative(file_create_url($file->getFileUri())),
],
],
];
@@ -2,11 +2,13 @@
namespace Drupal\Tests\hal\Kernel;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\serialization\Normalizer\CacheableNormalizerInterface;
/**
* @coversDefaultClass \Drupal\hal\LinkManager\LinkManager
@@ -67,6 +69,13 @@ class HalLinkManagerTest extends KernelTestBase {
}
public function providerTestGetTypeUri() {
$serialization_context_collecting_cacheability = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata()
];
$expected_serialization_context_cacheability_url_site = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheContexts(['url.site'])
];
$base_test_case = [
'link_domain' => NULL,
'entity_type' => 'node',
@@ -80,18 +89,35 @@ class HalLinkManagerTest extends KernelTestBase {
'expected return' => 'BASE_URL/rest/type/node/page',
'expected context' => [],
],
'site URL, with optional context to collect cacheability metadata' => $base_test_case + [
'context' => $serialization_context_collecting_cacheability,
'expected return' => 'BASE_URL/rest/type/node/page',
'expected context' => $expected_serialization_context_cacheability_url_site,
],
// 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],
],
'site URL, with optional context, to test hook_hal_type_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
'context' => ['hal_test' => TRUE] + $serialization_context_collecting_cacheability,
'expected return' => 'hal_test_type',
// No cacheability metadata bubbled.
'expected context' => ['hal_test' => TRUE] + $serialization_context_collecting_cacheability,
],
// 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],
],
'site URL, with optional context, to test hook_rest_type_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
'context' => ['rest_test' => TRUE] + $serialization_context_collecting_cacheability,
'expected return' => 'rest_test_type',
// No cacheability metadata bubbled.
'expected context' => ['rest_test' => TRUE] + $serialization_context_collecting_cacheability,
],
'configured URL' => [
'link_domain' => 'http://llamas-rock.com/for-real/',
'entity_type' => 'node',
@@ -100,6 +126,16 @@ class HalLinkManagerTest extends KernelTestBase {
'expected return' => 'http://llamas-rock.com/for-real/rest/type/node/page',
'expected context' => [],
],
'configured URL, with optional context to collect cacheability metadata' => [
'link_domain' => 'http://llamas-rock.com/for-real/',
'entity_type' => 'node',
'bundle' => 'page',
'context' => $serialization_context_collecting_cacheability,
'expected return' => 'http://llamas-rock.com/for-real/rest/type/node/page',
'expected context' => [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheTags(['config:hal.settings']),
],
],
];
}
@@ -126,6 +162,13 @@ class HalLinkManagerTest extends KernelTestBase {
}
public function providerTestGetRelationUri() {
$serialization_context_collecting_cacheability = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata()
];
$expected_serialization_context_cacheability_url_site = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheContexts(['url.site'])
];
$field_name = $this->randomMachineName();
$base_test_case = [
'link_domain' => NULL,
@@ -141,18 +184,35 @@ class HalLinkManagerTest extends KernelTestBase {
'expected return' => 'BASE_URL/rest/relation/node/page/' . $field_name,
'expected context' => [],
],
'site URL, with optional context to collect cacheability metadata' => $base_test_case + [
'context' => $serialization_context_collecting_cacheability,
'expected return' => 'BASE_URL/rest/relation/node/page/' . $field_name,
'expected context' => $expected_serialization_context_cacheability_url_site,
],
// 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],
],
'site URL, with optional context, to test hook_hal_relation_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
'context' => ['hal_test' => TRUE] + $serialization_context_collecting_cacheability,
'expected return' => 'hal_test_relation',
// No cacheability metadata bubbled.
'expected context' => ['hal_test' => TRUE] + $serialization_context_collecting_cacheability,
],
// 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],
],
'site URL, with optional context, to test hook_rest_relation_uri_alter(), and collecting cacheability metadata' => $base_test_case + [
'context' => ['rest_test' => TRUE] + $serialization_context_collecting_cacheability,
'expected return' => 'rest_test_relation',
// No cacheability metadata bubbled.
'expected context' => ['rest_test' => TRUE] + $serialization_context_collecting_cacheability,
],
'configured URL' => [
'link_domain' => 'http://llamas-rock.com/for-real/',
'entity_type' => 'node',
@@ -162,6 +222,17 @@ class HalLinkManagerTest extends KernelTestBase {
'expected return' => 'http://llamas-rock.com/for-real/rest/relation/node/page/' . $field_name,
'expected context' => [],
],
'configured URL, with optional context to collect cacheability metadata' => [
'link_domain' => 'http://llamas-rock.com/for-real/',
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => $field_name,
'context' => $serialization_context_collecting_cacheability,
'expected return' => 'http://llamas-rock.com/for-real/rest/relation/node/page/' . $field_name,
'expected context' => [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => (new CacheableMetadata())->setCacheTags(['config:hal.settings']),
],
],
];
}
@@ -186,13 +257,19 @@ class HalLinkManagerTest extends KernelTestBase {
* @covers ::setLinkDomain
*/
public function testHalLinkManagersSetLinkDomain() {
$serialization_context = [
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY => new CacheableMetadata()
];
/* @var \Drupal\rest\LinkManager\LinkManager $link_manager */
$link_manager = \Drupal::service('hal.link_manager');
$link_manager->setLinkDomain('http://example.com/');
$link = $link_manager->getTypeUri('node', 'page');
$link = $link_manager->getTypeUri('node', 'page', $serialization_context);
$this->assertEqual($link, 'http://example.com/rest/type/node/page');
$link = $link_manager->getRelationUri('node', 'page', 'field_ref');
$this->assertEqual(new CacheableMetadata(), $serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]);
$link = $link_manager->getRelationUri('node', 'page', 'field_ref', $serialization_context);
$this->assertEqual($link, 'http://example.com/rest/relation/node/page/field_ref');
$this->assertEqual(new CacheableMetadata(), $serialization_context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]);
}
}
@@ -5,6 +5,7 @@ namespace Drupal\Tests\hal\Kernel;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\filter\Entity\FilterFormat;
/**
* Tests HAL normalization edge cases for EntityResource.
@@ -19,6 +20,27 @@ class NormalizeTest extends NormalizerTestBase {
protected function setUp() {
parent::setUp();
FilterFormat::create([
'format' => 'my_text_format',
'name' => 'My Text Format',
'filters' => [
'filter_html' => [
'module' => 'filter',
'status' => TRUE,
'weight' => 10,
'settings' => [
'allowed_html' => '<p>',
],
],
'filter_autop' => [
'module' => 'filter',
'status' => TRUE,
'weight' => 10,
'settings' => [],
],
],
])->save();
\Drupal::service('router.builder')->rebuild();
}
@@ -37,7 +59,7 @@ class NormalizeTest extends NormalizerTestBase {
'name' => $this->randomMachineName(),
'field_test_text' => [
'value' => $this->randomMachineName(),
'format' => 'full_html',
'format' => 'my_text_format',
],
'field_test_entity_reference' => [
'target_id' => $target_entity_de->id(),
@@ -152,6 +174,7 @@ class NormalizeTest extends NormalizerTestBase {
[
'value' => $values['field_test_text']['value'],
'format' => $values['field_test_text']['format'],
'processed' => "<p>{$values['field_test_text']['value']}</p>",
],
],
];