Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
43
web/core/modules/hal/tests/fixtures/update/drupal-8.hal-hal_update_8301.php
vendored
Normal file
43
web/core/modules/hal/tests/fixtures/update/drupal-8.hal-hal_update_8301.php
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
|
||||
* upgrade path of hal_update_8301().
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Set the schema version.
|
||||
$connection->insert('key_value')
|
||||
->fields([
|
||||
'collection' => 'system.schema',
|
||||
'name' => 'hal',
|
||||
'value' => 'i:8000;',
|
||||
])
|
||||
->fields([
|
||||
'collection' => 'system.schema',
|
||||
'name' => 'serialization',
|
||||
'value' => 'i:8000;',
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Update core.extension.
|
||||
$extensions = $connection->select('config')
|
||||
->fields('config', ['data'])
|
||||
->condition('collection', '')
|
||||
->condition('name', 'core.extension')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$extensions = unserialize($extensions);
|
||||
$extensions['module']['hal'] = 0;
|
||||
$extensions['module']['serialization'] = 0;
|
||||
$connection->update('config')
|
||||
->fields([
|
||||
'data' => serialize($extensions),
|
||||
])
|
||||
->condition('collection', '')
|
||||
->condition('name', 'core.extension')
|
||||
->execute();
|
BIN
web/core/modules/hal/tests/fixtures/update/drupal-8.rest-hal_update_8301.php
vendored
Normal file
BIN
web/core/modules/hal/tests/fixtures/update/drupal-8.rest-hal_update_8301.php
vendored
Normal file
Binary file not shown.
|
@ -0,0 +1,6 @@
|
|||
name: HAL test module
|
||||
type: module
|
||||
description: "Support module for HAL tests."
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
46
web/core/modules/hal/tests/modules/hal_test/hal_test.module
Normal file
46
web/core/modules/hal/tests/modules/hal_test/hal_test.module
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains hook implementations for testing HAL module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_hal_type_uri_alter().
|
||||
*/
|
||||
function hal_test_hal_type_uri_alter(&$uri, $context = []) {
|
||||
if (!empty($context['hal_test'])) {
|
||||
$uri = 'hal_test_type';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_hal_relation_uri_alter().
|
||||
*/
|
||||
function hal_test_hal_relation_uri_alter(&$uri, $context = []) {
|
||||
if (!empty($context['hal_test'])) {
|
||||
$uri = 'hal_test_relation';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rest_type_uri_alter().
|
||||
*
|
||||
* @deprecated Kept only for BC test coverage, see \Drupal\Tests\hal\Kernel\HalLinkManagerTest::testGetTypeUri().
|
||||
*/
|
||||
function hal_test_rest_type_uri_alter(&$uri, $context = []) {
|
||||
if (!empty($context['rest_test'])) {
|
||||
$uri = 'rest_test_type';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rest_relation_uri_alter().
|
||||
*
|
||||
* @deprecated Kept only for BC test coverage, see \Drupal\Tests\hal\Kernel\HalLinkManagerTest::testGetRelationUri().
|
||||
*/
|
||||
function hal_test_rest_relation_uri_alter(&$uri, $context = []) {
|
||||
if (!empty($context['rest_test'])) {
|
||||
$uri = 'rest_test_relation';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Action;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Action\ActionResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ActionHalJsonAnonTest extends ActionResourceTestBase {
|
||||
|
||||
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\Action;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Action\ActionResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ActionHalJsonBasicAuthTest extends ActionResourceTestBase {
|
||||
|
||||
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\Action;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Action\ActionResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ActionHalJsonCookieTest extends ActionResourceTestBase {
|
||||
|
||||
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';
|
||||
|
||||
}
|
|
@ -27,9 +27,4 @@ class BlockHalJsonAnonTest extends BlockResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Block;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Block\BlockResourceTestBase;
|
||||
|
||||
|
@ -28,19 +27,9 @@ class BlockHalJsonBasicAuthTest extends BlockResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,6 @@ class BlockHalJsonCookieTest extends BlockResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Comment;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
|
@ -22,9 +21,4 @@ class CommentHalJsonBasicAuthTest extends CommentHalJsonTestBase {
|
|||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Comment;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Comment\CommentResourceTestBase;
|
||||
|
@ -27,11 +26,6 @@ abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@ -42,9 +36,9 @@ abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
|
|||
* @todo fix in https://www.drupal.org/node/2824271
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'status',
|
||||
'created',
|
||||
'changed',
|
||||
'status',
|
||||
'thread',
|
||||
'entity_type',
|
||||
'field_name',
|
||||
|
@ -133,12 +127,4 @@ abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\CommentType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\CommentType\CommentTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentTypeHalJsonAnonTest extends CommentTypeResourceTestBase {
|
||||
|
||||
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\CommentType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\CommentType\CommentTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentTypeHalJsonBasicAuthTest extends CommentTypeResourceTestBase {
|
||||
|
||||
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\CommentType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\CommentType\CommentTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class CommentTypeHalJsonCookieTest extends CommentTypeResourceTestBase {
|
||||
|
||||
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';
|
||||
|
||||
}
|
|
@ -27,9 +27,4 @@ class ConfigTestHalJsonAnonTest extends ConfigTestResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ConfigTest;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ConfigTest\ConfigTestResourceTestBase;
|
||||
|
||||
|
@ -28,19 +27,9 @@ class ConfigTestHalJsonBasicAuthTest extends ConfigTestResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,6 @@ class ConfigTestHalJsonCookieTest extends ConfigTestResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ConfigurableLanguage;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage\ConfigurableLanguageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ConfigurableLanguageHalJsonAnonTest extends ConfigurableLanguageResourceTestBase {
|
||||
|
||||
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\ConfigurableLanguage;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage\ConfigurableLanguageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ConfigurableLanguageHalJsonBasicAuthTest extends ConfigurableLanguageResourceTestBase {
|
||||
|
||||
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\ConfigurableLanguage;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage\ConfigurableLanguageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ConfigurableLanguageHalJsonCookieTest extends ConfigurableLanguageResourceTestBase {
|
||||
|
||||
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';
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase;
|
||||
|
@ -31,11 +30,6 @@ class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -94,12 +88,4 @@ class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeTags(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
|
@ -22,9 +21,4 @@ class EntityTestHalJsonBasicAuthTest extends EntityTestHalJsonAnonTest {
|
|||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestLabel;
|
||||
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel\EntityTestLabelResourceTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityTestLabelHalJsonAnonTest extends EntityTestLabelResourceTestBase {
|
||||
|
||||
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);
|
||||
|
||||
$author = User::load(0);
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => '',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/user/0?_format=hal_json',
|
||||
'lang' => 'en',
|
||||
],
|
||||
],
|
||||
],
|
||||
'_embedded' => [
|
||||
$this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/user/0?_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/entity_test_label/entity_test_label',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return [
|
||||
'url.site',
|
||||
'user.permissions',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestLabel;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityTestLabelHalJsonBasicAuthTest extends EntityTestLabelHalJsonAnonTest {
|
||||
|
||||
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\EntityTestLabel;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class EntityTestLabelHalJsonCookieTest extends EntityTestLabelHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\FilterFormat;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\FilterFormat\FilterFormatResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FilterFormatHalJsonAnonTest extends FilterFormatResourceTestBase {
|
||||
|
||||
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\FilterFormat;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\FilterFormat\FilterFormatResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FilterFormatHalJsonBasicAuthTest extends FilterFormatResourceTestBase {
|
||||
|
||||
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\FilterFormat;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\FilterFormat\FilterFormatResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FilterFormatHalJsonCookieTest extends FilterFormatResourceTestBase {
|
||||
|
||||
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';
|
||||
|
||||
}
|
|
@ -92,7 +92,7 @@ trait HalEntityNormalizationTrait {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
|
||||
// \Drupal\serialization\Normalizer\EntityNormalizer::denormalize(): entity
|
||||
// \Drupal\hal\Normalizer\EntityNormalizer::denormalize(): entity
|
||||
// types with bundles MUST send their bundle field to be denormalizable.
|
||||
if ($this->entity->getEntityType()->hasKey('bundle')) {
|
||||
$normalization = $this->getNormalizedPostEntity();
|
||||
|
@ -103,11 +103,7 @@ trait HalEntityNormalizationTrait {
|
|||
|
||||
// DX: 400 when incorrect entity type bundle is specified.
|
||||
$response = $this->request($method, $url, $request_options);
|
||||
// @todo Uncomment, remove next 3 in https://www.drupal.org/node/2813853.
|
||||
// $this->assertResourceErrorResponse(400, 'No entity type(s) specified', $response);
|
||||
$this->assertSame(400, $response->getStatusCode());
|
||||
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
|
||||
$this->assertSame($this->serializer->encode(['error' => 'No entity type(s) specified'], static::$format), (string) $response->getBody());
|
||||
$this->assertResourceErrorResponse(400, 'No entity type(s) specified', $response);
|
||||
|
||||
|
||||
unset($normalization['_links']['type']);
|
||||
|
@ -116,11 +112,7 @@ trait HalEntityNormalizationTrait {
|
|||
|
||||
// DX: 400 when no entity type bundle is specified.
|
||||
$response = $this->request($method, $url, $request_options);
|
||||
// @todo Uncomment, remove next 3 in https://www.drupal.org/node/2813853.
|
||||
// $this->assertResourceErrorResponse(400, 'The type link relation must be specified.', $response);
|
||||
$this->assertSame(400, $response->getStatusCode());
|
||||
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
|
||||
$this->assertSame($this->serializer->encode(['error' => 'The type link relation must be specified.'], static::$format), (string) $response->getBody());
|
||||
$this->assertResourceErrorResponse(400, 'The type link relation must be specified.', $response);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\ImageStyle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ImageStyle\ImageStyleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ImageStyleHalJsonAnonTest extends ImageStyleResourceTestBase {
|
||||
|
||||
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\ImageStyle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ImageStyle\ImageStyleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ImageStyleHalJsonBasicAuthTest extends ImageStyleResourceTestBase {
|
||||
|
||||
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\ImageStyle;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\ImageStyle\ImageStyleResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class ImageStyleHalJsonCookieTest extends ImageStyleResourceTestBase {
|
||||
|
||||
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,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ItemHalJsonAnonTest extends ItemHalJsonTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ItemHalJsonBasicAuthTest extends ItemHalJsonTestBase {
|
||||
|
||||
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,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ItemHalJsonCookieTest extends ItemHalJsonTestBase {
|
||||
|
||||
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,100 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Item;
|
||||
|
||||
use Drupal\aggregator\Entity\Feed;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Item\ItemResourceTestBase;
|
||||
|
||||
/**
|
||||
* ResourceTestBase for Item entity.
|
||||
*/
|
||||
abstract class ItemHalJsonTestBase extends ItemResourceTestBase {
|
||||
|
||||
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);
|
||||
$feed = Feed::load($this->entity->getFeedId());
|
||||
|
||||
return $normalization + [
|
||||
'_embedded' => [
|
||||
$this->baseUrl . '/rest/relation/aggregator_item/aggregator_item/fid' => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/aggregator/sources/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/aggregator_feed/aggregator_feed',
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $feed->uuid(),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => '',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
|
||||
],
|
||||
$this->baseUrl . '/rest/relation/aggregator_item/aggregator_item/fid' => [
|
||||
[
|
||||
'href' => $this->baseUrl . '/aggregator/sources/' . $feed->id() . '?_format=hal_json',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return [
|
||||
'url.site',
|
||||
'user.permissions',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\MenuLinkContent;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\MenuLinkContent\MenuLinkContentResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MenuLinkContentHalJsonAnonTest extends MenuLinkContentResourceTestBase {
|
||||
|
||||
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 . '/admin/structure/menu/item/1/edit?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/menu_link_content/menu_link_content',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/menu_link_content/menu_link_content',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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\MenuLinkContent;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MenuLinkContentHalJsonBasicAuthTest extends MenuLinkContentHalJsonAnonTest {
|
||||
|
||||
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\MenuLinkContent;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class MenuLinkContentHalJsonCookieTest extends MenuLinkContentHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Node;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase;
|
||||
|
@ -31,11 +30,6 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -126,12 +120,4 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Node;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
|
@ -22,9 +21,4 @@ class NodeHalJsonBasicAuthTest extends NodeHalJsonAnonTest {
|
|||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\NodeType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\NodeType\NodeTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class NodeTypeHalJsonAnonTest extends NodeTypeResourceTestBase {
|
||||
|
||||
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\NodeType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\NodeType\NodeTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class NodeTypeHalJsonBasicAuthTest extends NodeTypeResourceTestBase {
|
||||
|
||||
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\NodeType;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\NodeType\NodeTypeResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class NodeTypeHalJsonCookieTest extends NodeTypeResourceTestBase {
|
||||
|
||||
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';
|
||||
|
||||
}
|
|
@ -27,9 +27,4 @@ class RoleHalJsonAnonTest extends RoleResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Role;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Role\RoleResourceTestBase;
|
||||
|
||||
|
@ -28,19 +27,9 @@ class RoleHalJsonBasicAuthTest extends RoleResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,6 @@ class RoleHalJsonCookieTest extends RoleResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\SearchPage;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\SearchPage\SearchPageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class SearchPageHalJsonAnonTest extends SearchPageResourceTestBase {
|
||||
|
||||
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\SearchPage;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\SearchPage\SearchPageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class SearchPageHalJsonBasicAuthTest extends SearchPageResourceTestBase {
|
||||
|
||||
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\SearchPage;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\SearchPage\SearchPageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class SearchPageHalJsonCookieTest extends SearchPageResourceTestBase {
|
||||
|
||||
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,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Shortcut;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Shortcut\ShortcutResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ShortcutHalJsonAnonTest extends ShortcutResourceTestBase {
|
||||
|
||||
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 . '/admin/config/user-interface/shortcut/link/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/shortcut/default',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/shortcut/default',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Shortcut;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ShortcutHalJsonBasicAuthTest extends ShortcutHalJsonAnonTest {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Shortcut;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class ShortcutHalJsonCookieTest extends ShortcutHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Term;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Term\TermResourceTestBase;
|
||||
|
@ -30,11 +29,6 @@ class TermHalJsonAnonTest extends TermResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -68,12 +62,4 @@ class TermHalJsonAnonTest extends TermResourceTestBase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Term;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
|
@ -22,9 +21,4 @@ class TermHalJsonBasicAuthTest extends TermHalJsonAnonTest {
|
|||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\User;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\User\UserResourceTestBase;
|
||||
|
@ -30,11 +29,6 @@ class UserHalJsonAnonTest extends UserResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -68,12 +62,4 @@ class UserHalJsonAnonTest extends UserResourceTestBase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\User;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
|
@ -22,9 +21,4 @@ class UserHalJsonBasicAuthTest extends UserHalJsonAnonTest {
|
|||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,6 @@ class VocabularyHalJsonAnonTest extends VocabularyResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* @todo Remove this override in https://www.drupal.org/node/2805281.
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Functional\EntityResource\Vocabulary;
|
||||
|
||||
use Drupal\Tests\hal\Functional\HalJsonBasicAuthWorkaroundFor2805281Trait;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\Vocabulary\VocabularyResourceTestBase;
|
||||
|
||||
|
@ -28,19 +27,9 @@ class VocabularyHalJsonBasicAuthTest extends VocabularyResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
// @todo Fix in https://www.drupal.org/node/2805281: remove this trait usage.
|
||||
use HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
HalJsonBasicAuthWorkaroundFor2805281Trait::assertResponseWhenMissingAuthentication insteadof BasicAuthResourceTestTrait;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,11 +27,6 @@ class VocabularyHalJsonCookieTest extends VocabularyResourceTestBase {
|
|||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $expectedErrorMimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that file entities can be denormalized in HAL.
|
||||
*
|
||||
* @group hal
|
||||
* @see \Drupal\hal\Normalizer\FileEntityNormalizer
|
||||
*/
|
||||
class FileDenormalizeTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['hal', 'file', 'node'];
|
||||
|
||||
/**
|
||||
* Tests file entity denormalization.
|
||||
*/
|
||||
public function testFileDenormalize() {
|
||||
$file_params = [
|
||||
'filename' => 'test_1.txt',
|
||||
'uri' => 'public://test_1.txt',
|
||||
'filemime' => 'text/plain',
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
];
|
||||
// Create a new file entity.
|
||||
$file = File::create($file_params);
|
||||
file_put_contents($file->getFileUri(), 'hello world');
|
||||
$file->save();
|
||||
|
||||
$serializer = \Drupal::service('serializer');
|
||||
$normalized_data = $serializer->normalize($file, 'hal_json');
|
||||
$denormalized = $serializer->denormalize($normalized_data, 'Drupal\file\Entity\File', 'hal_json');
|
||||
|
||||
$this->assertTrue($denormalized instanceof File, 'A File instance was created.');
|
||||
|
||||
$this->assertIdentical('temporary://' . $file->getFilename(), $denormalized->getFileUri(), 'The expected file URI was found.');
|
||||
$this->assertTrue(file_exists($denormalized->getFileUri()), 'The temporary file was found.');
|
||||
|
||||
$this->assertIdentical($file->uuid(), $denormalized->uuid(), 'The expected UUID was found');
|
||||
$this->assertIdentical($file->getMimeType(), $denormalized->getMimeType(), 'The expected MIME type was found.');
|
||||
$this->assertIdentical($file->getFilename(), $denormalized->getFilename(), 'The expected filename was found.');
|
||||
$this->assertTrue($denormalized->isPermanent(), 'The file has a permanent status.');
|
||||
|
||||
// Try to denormalize with the file uri only.
|
||||
$file_name = 'test_2.txt';
|
||||
$file_path = 'public://' . $file_name;
|
||||
|
||||
file_put_contents($file_path, 'hello world');
|
||||
$file_uri = file_create_url($file_path);
|
||||
|
||||
$data = [
|
||||
'uri' => [
|
||||
['value' => $file_uri],
|
||||
],
|
||||
];
|
||||
|
||||
$denormalized = $serializer->denormalize($data, 'Drupal\file\Entity\File', 'hal_json');
|
||||
|
||||
$this->assertIdentical('temporary://' . $file_name, $denormalized->getFileUri(), 'The expected file URI was found.');
|
||||
$this->assertTrue(file_exists($denormalized->getFileUri()), 'The temporary file was found.');
|
||||
|
||||
$this->assertIdentical('text/plain', $denormalized->getMimeType(), 'The expected MIME type was found.');
|
||||
$this->assertIdentical($file_name, $denormalized->getFilename(), 'The expected filename was found.');
|
||||
$this->assertFalse($denormalized->isPermanent(), 'The file has a permanent status.');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
trait HalJsonBasicAuthWorkaroundFor2805281Trait {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Note how the response claims it contains a application/hal+json body, but
|
||||
* in reality it contains a text/plain body! Also, the correct error MIME type
|
||||
* is application/json.
|
||||
*
|
||||
* @todo Fix in https://www.drupal.org/node/2805281: remove this trait.
|
||||
*/
|
||||
protected function assertResponseWhenMissingAuthentication(ResponseInterface $response) {
|
||||
$this->assertSame(401, $response->getStatusCode());
|
||||
// @todo this works fine locally, but on testbot it comes back with
|
||||
// 'text/plain; charset=UTF-8'. WTF.
|
||||
// $this->assertSame(['application/hal+json'], $response->getHeader('Content-Type'));
|
||||
$this->assertSame('No authentication credentials provided.', (string) $response->getBody());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests that 'hal.settings' is created, to store 'link_domain'.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2758897
|
||||
*
|
||||
* @group hal
|
||||
*/
|
||||
class CreateHalSettingsForLinkDomainUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.hal-hal_update_8301.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hal_update_8301().
|
||||
*/
|
||||
public function testHalSettingsCreated() {
|
||||
// Make sure we have the expected values before the update.
|
||||
$hal_settings = $this->config('hal.settings');
|
||||
$this->assertIdentical([], $hal_settings->getRawData());
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
// Make sure we have the expected values after the update.
|
||||
$hal_settings = \Drupal::configFactory()->get('hal.settings');
|
||||
$this->assertTrue(array_key_exists('link_domain', $hal_settings->getRawData()));
|
||||
$this->assertIdentical(NULL, $hal_settings->getRawData()['link_domain']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Functional\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* 'link_domain' is migrated from 'rest.settings' to 'hal.settings'.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2758897
|
||||
*
|
||||
* @group hal
|
||||
*/
|
||||
class MigrateLinkDomainSettingFromRestToHalUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.hal-hal_update_8301.php',
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.rest-hal_update_8301.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hal_update_8301().
|
||||
*/
|
||||
public function testLinkDomainMigratedFromRestSettingsToHalSettings() {
|
||||
// Make sure we have the expected values before the update.
|
||||
$hal_settings = $this->config('hal.settings');
|
||||
$this->assertIdentical([], $hal_settings->getRawData());
|
||||
$rest_settings = $this->config('rest.settings');
|
||||
$this->assertTrue(array_key_exists('link_domain', $rest_settings->getRawData()));
|
||||
$this->assertIdentical('http://example.com', $rest_settings->getRawData()['link_domain']);
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
// Make sure we have the expected values after the update.
|
||||
$hal_settings = \Drupal::configFactory()->get('hal.settings');
|
||||
$this->assertTrue(array_key_exists('link_domain', $hal_settings->getRawData()));
|
||||
$this->assertIdentical('http://example.com', $hal_settings->getRawData()['link_domain']);
|
||||
$rest_settings = $this->config('rest.settings');
|
||||
$this->assertFalse(array_key_exists('link_domain', $rest_settings->getRawData()));
|
||||
}
|
||||
|
||||
}
|
|
@ -18,40 +18,40 @@ class DenormalizeTest extends NormalizerTestBase {
|
|||
*/
|
||||
public function testTypeHandling() {
|
||||
// Valid type.
|
||||
$data_with_valid_type = array(
|
||||
'_links' => array(
|
||||
'type' => array(
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
$data_with_valid_type = [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
],
|
||||
];
|
||||
$denormalized = $this->serializer->denormalize($data_with_valid_type, $this->entityClass, $this->format);
|
||||
$this->assertEqual(get_class($denormalized), $this->entityClass, 'Request with valid type results in creation of correct bundle.');
|
||||
|
||||
// Multiple types.
|
||||
$data_with_multiple_types = array(
|
||||
'_links' => array(
|
||||
'type' => array(
|
||||
array(
|
||||
'href' => Url::fromUri('base:rest/types/foo', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
array(
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$data_with_multiple_types = [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
[
|
||||
'href' => Url::fromUri('base:rest/types/foo', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
[
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$denormalized = $this->serializer->denormalize($data_with_multiple_types, $this->entityClass, $this->format);
|
||||
$this->assertEqual(get_class($denormalized), $this->entityClass, 'Request with multiple types results in creation of correct bundle.');
|
||||
|
||||
// Invalid type.
|
||||
$data_with_invalid_type = array(
|
||||
'_links' => array(
|
||||
'type' => array(
|
||||
'href' => Url::fromUri('base:rest/types/foo', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
$data_with_invalid_type = [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => Url::fromUri('base:rest/types/foo', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
],
|
||||
];
|
||||
try {
|
||||
$this->serializer->denormalize($data_with_invalid_type, $this->entityClass, $this->format);
|
||||
$this->fail('Exception should be thrown when type is invalid.');
|
||||
|
@ -61,10 +61,10 @@ class DenormalizeTest extends NormalizerTestBase {
|
|||
}
|
||||
|
||||
// No type.
|
||||
$data_with_no_type = array(
|
||||
'_links' => array(
|
||||
),
|
||||
);
|
||||
$data_with_no_type = [
|
||||
'_links' => [
|
||||
],
|
||||
];
|
||||
try {
|
||||
$this->serializer->denormalize($data_with_no_type, $this->entityClass, $this->format);
|
||||
$this->fail('Exception should be thrown when no type is provided.');
|
||||
|
@ -78,13 +78,13 @@ class DenormalizeTest extends NormalizerTestBase {
|
|||
* Tests link relation handling with an invalid type.
|
||||
*/
|
||||
public function testTypeHandlingWithInvalidType() {
|
||||
$data_with_invalid_type = array(
|
||||
'_links' => array(
|
||||
'type' => array(
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test_invalid', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
$data_with_invalid_type = [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test_invalid', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setExpectedException(UnexpectedValueException::class);
|
||||
$this->serializer->denormalize($data_with_invalid_type, $this->entityClass, $this->format);
|
||||
|
@ -94,11 +94,11 @@ class DenormalizeTest extends NormalizerTestBase {
|
|||
* Tests link relation handling with no types.
|
||||
*/
|
||||
public function testTypeHandlingWithNoTypes() {
|
||||
$data_with_no_types = array(
|
||||
'_links' => array(
|
||||
'type' => array(),
|
||||
),
|
||||
);
|
||||
$data_with_no_types = [
|
||||
'_links' => [
|
||||
'type' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setExpectedException(UnexpectedValueException::class);
|
||||
$this->serializer->denormalize($data_with_no_types, $this->entityClass, $this->format);
|
||||
|
@ -110,32 +110,32 @@ class DenormalizeTest extends NormalizerTestBase {
|
|||
public function testMarkFieldForDeletion() {
|
||||
// Add a default value for a field.
|
||||
$field = FieldConfig::loadByName('entity_test', 'entity_test', 'field_test_text');
|
||||
$field->setDefaultValue(array(array('value' => 'Llama')));
|
||||
$field->setDefaultValue([['value' => 'Llama']]);
|
||||
$field->save();
|
||||
|
||||
// Denormalize data that contains no entry for the field, and check that
|
||||
// the default value is present in the resulting entity.
|
||||
$data = array(
|
||||
'_links' => array(
|
||||
'type' => array(
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
),
|
||||
);
|
||||
$data = [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
],
|
||||
];
|
||||
$entity = $this->serializer->denormalize($data, $this->entityClass, $this->format);
|
||||
$this->assertEqual($entity->field_test_text->count(), 1);
|
||||
$this->assertEqual($entity->field_test_text->value, 'Llama');
|
||||
|
||||
// Denormalize data that contains an empty entry for the field, and check
|
||||
// that the field is empty in the resulting entity.
|
||||
$data = array(
|
||||
'_links' => array(
|
||||
'type' => array(
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString(),
|
||||
),
|
||||
),
|
||||
'field_test_text' => array(),
|
||||
);
|
||||
$data = [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => Url::fromUri('base:rest/type/entity_test/entity_test', ['absolute' => TRUE])->toString(),
|
||||
],
|
||||
],
|
||||
'field_test_text' => [],
|
||||
];
|
||||
$entity = $this->serializer->denormalize($data, get_class($entity), $this->format, [ 'target_instance' => $entity ]);
|
||||
$this->assertEqual($entity->field_test_text->count(), 0);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\hal\Kernel;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
|
@ -18,14 +19,14 @@ class EntityTranslationNormalizeTest extends NormalizerTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'content_translation');
|
||||
public static $modules = ['node', 'content_translation'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', array('sequences'));
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installConfig(['node', 'content_translation']);
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,7 @@ class EntityTranslationNormalizeTest extends NormalizerTestBase {
|
|||
'title' => $this->randomMachineName(),
|
||||
'uid' => $user->id(),
|
||||
'type' => $node_type->id(),
|
||||
'status' => NODE_PUBLISHED,
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'langcode' => 'en',
|
||||
'promote' => 1,
|
||||
'sticky' => 0,
|
||||
|
|
|
@ -2,16 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Kernel;
|
||||
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\hal\Encoder\JsonEncoder;
|
||||
use Drupal\hal\Normalizer\FieldItemNormalizer;
|
||||
use Drupal\hal\Normalizer\FileEntityNormalizer;
|
||||
use Drupal\rest\LinkManager\LinkManager;
|
||||
use Drupal\rest\LinkManager\RelationLinkManager;
|
||||
use Drupal\rest\LinkManager\TypeLinkManager;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
|
||||
/**
|
||||
* Tests that file entities can be normalized in HAL.
|
||||
|
@ -25,7 +16,7 @@ class FileNormalizeTest extends NormalizerTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('file');
|
||||
public static $modules = ['file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -33,20 +24,6 @@ class FileNormalizeTest extends NormalizerTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('file');
|
||||
|
||||
$entity_manager = \Drupal::entityManager();
|
||||
$link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default'), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'), \Drupal::service('entity_type.bundle.info')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack')));
|
||||
|
||||
// Set up the mock serializer.
|
||||
$normalizers = array(
|
||||
new FieldItemNormalizer(),
|
||||
new FileEntityNormalizer($entity_manager, \Drupal::httpClient(), $link_manager, \Drupal::moduleHandler()),
|
||||
);
|
||||
|
||||
$encoders = array(
|
||||
new JsonEncoder(),
|
||||
);
|
||||
$this->serializer = new Serializer($normalizers, $encoders);
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,23 +31,23 @@ class FileNormalizeTest extends NormalizerTestBase {
|
|||
* Tests the normalize function.
|
||||
*/
|
||||
public function testNormalize() {
|
||||
$file_params = array(
|
||||
$file_params = [
|
||||
'filename' => 'test_1.txt',
|
||||
'uri' => 'public://test_1.txt',
|
||||
'filemime' => 'text/plain',
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
);
|
||||
];
|
||||
// Create a new file entity.
|
||||
$file = File::create($file_params);
|
||||
file_put_contents($file->getFileUri(), 'hello world');
|
||||
$file->save();
|
||||
|
||||
$expected_array = array(
|
||||
'uri' => array(
|
||||
array(
|
||||
'value' => file_create_url($file->getFileUri())),
|
||||
),
|
||||
);
|
||||
$expected_array = [
|
||||
'uri' => [
|
||||
[
|
||||
'value' => file_create_url($file->getFileUri())],
|
||||
],
|
||||
];
|
||||
|
||||
$normalized = $this->serializer->normalize($file, $this->format);
|
||||
$this->assertEqual($normalized['uri'], $expected_array['uri'], 'URI is normalized.');
|
||||
|
|
74
web/core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php
Normal file
74
web/core/modules/hal/tests/src/Kernel/HalLinkManagerTest.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Kernel;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\hal\LinkManager\LinkManager
|
||||
* @group hal
|
||||
*/
|
||||
class HalLinkManagerTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'hal_test', 'serialization', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTypeUri
|
||||
*/
|
||||
public function testGetTypeUri() {
|
||||
/* @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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getRelationUri
|
||||
*/
|
||||
public function testGetRelationUri() {
|
||||
/* @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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setLinkDomain
|
||||
*/
|
||||
public function testHalLinkManagersSetLinkDomain() {
|
||||
/* @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');
|
||||
$this->assertEqual($link, 'http://example.com/rest/type/node/page');
|
||||
$link = $link_manager->getRelationUri('node', 'page', 'field_ref');
|
||||
$this->assertEqual($link, 'http://example.com/rest/relation/node/page/field_ref');
|
||||
}
|
||||
|
||||
}
|
|
@ -26,135 +26,135 @@ class NormalizeTest extends NormalizerTestBase {
|
|||
* Tests the normalize function.
|
||||
*/
|
||||
public function testNormalize() {
|
||||
$target_entity_de = EntityTest::create((array('langcode' => 'de', 'field_test_entity_reference' => NULL)));
|
||||
$target_entity_de = EntityTest::create((['langcode' => 'de', 'field_test_entity_reference' => NULL]));
|
||||
$target_entity_de->save();
|
||||
$target_entity_en = EntityTest::create((array('langcode' => 'en', 'field_test_entity_reference' => NULL)));
|
||||
$target_entity_en = EntityTest::create((['langcode' => 'en', 'field_test_entity_reference' => NULL]));
|
||||
$target_entity_en->save();
|
||||
|
||||
// Create a German entity.
|
||||
$values = array(
|
||||
$values = [
|
||||
'langcode' => 'de',
|
||||
'name' => $this->randomMachineName(),
|
||||
'field_test_text' => array(
|
||||
'field_test_text' => [
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => 'full_html',
|
||||
),
|
||||
'field_test_entity_reference' => array(
|
||||
],
|
||||
'field_test_entity_reference' => [
|
||||
'target_id' => $target_entity_de->id(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
// Array of translated values.
|
||||
$translation_values = array(
|
||||
$translation_values = [
|
||||
'name' => $this->randomMachineName(),
|
||||
'field_test_entity_reference' => array(
|
||||
'field_test_entity_reference' => [
|
||||
'target_id' => $target_entity_en->id(),
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
$entity = EntityTest::create($values);
|
||||
$entity->save();
|
||||
// Add an English value for name and entity reference properties.
|
||||
$entity->addTranslation('en')->set('name', array(0 => array('value' => $translation_values['name'])));
|
||||
$entity->getTranslation('en')->set('field_test_entity_reference', array(0 => $translation_values['field_test_entity_reference']));
|
||||
$entity->addTranslation('en')->set('name', [0 => ['value' => $translation_values['name']]]);
|
||||
$entity->getTranslation('en')->set('field_test_entity_reference', [0 => $translation_values['field_test_entity_reference']]);
|
||||
$entity->save();
|
||||
|
||||
$type_uri = Url::fromUri('base:rest/type/entity_test/entity_test', array('absolute' => TRUE))->toString();
|
||||
$relation_uri = Url::fromUri('base:rest/relation/entity_test/entity_test/field_test_entity_reference', array('absolute' => TRUE))->toString();
|
||||
$type_uri = Url::fromUri('base:rest/type/entity_test/entity_test', ['absolute' => TRUE])->toString();
|
||||
$relation_uri = Url::fromUri('base:rest/relation/entity_test/entity_test/field_test_entity_reference', ['absolute' => TRUE])->toString();
|
||||
|
||||
$expected_array = array(
|
||||
'_links' => array(
|
||||
'curies' => array(
|
||||
array(
|
||||
$expected_array = [
|
||||
'_links' => [
|
||||
'curies' => [
|
||||
[
|
||||
'href' => '/relations',
|
||||
'name' => 'site',
|
||||
'templated' => TRUE,
|
||||
),
|
||||
),
|
||||
'self' => array(
|
||||
],
|
||||
],
|
||||
'self' => [
|
||||
'href' => $this->getEntityUri($entity),
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
'href' => $type_uri,
|
||||
),
|
||||
$relation_uri => array(
|
||||
array(
|
||||
],
|
||||
$relation_uri => [
|
||||
[
|
||||
'href' => $this->getEntityUri($target_entity_de),
|
||||
'lang' => 'de',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'href' => $this->getEntityUri($target_entity_en),
|
||||
'lang' => 'en',
|
||||
),
|
||||
),
|
||||
),
|
||||
'_embedded' => array(
|
||||
$relation_uri => array(
|
||||
array(
|
||||
'_links' => array(
|
||||
'self' => array(
|
||||
],
|
||||
],
|
||||
],
|
||||
'_embedded' => [
|
||||
$relation_uri => [
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->getEntityUri($target_entity_de),
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
'href' => $type_uri,
|
||||
),
|
||||
),
|
||||
'uuid' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $target_entity_de->uuid(),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
'lang' => 'de',
|
||||
),
|
||||
array(
|
||||
'_links' => array(
|
||||
'self' => array(
|
||||
],
|
||||
[
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->getEntityUri($target_entity_en),
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
'href' => $type_uri,
|
||||
),
|
||||
),
|
||||
'uuid' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $target_entity_en->uuid(),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
'lang' => 'en',
|
||||
),
|
||||
),
|
||||
),
|
||||
'id' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
'id' => [
|
||||
[
|
||||
'value' => $entity->id(),
|
||||
),
|
||||
),
|
||||
'uuid' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $entity->uuid(),
|
||||
),
|
||||
),
|
||||
'langcode' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'langcode' => [
|
||||
[
|
||||
'value' => 'de',
|
||||
),
|
||||
),
|
||||
'name' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'name' => [
|
||||
[
|
||||
'value' => $values['name'],
|
||||
'lang' => 'de',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'value' => $translation_values['name'],
|
||||
'lang' => 'en',
|
||||
),
|
||||
),
|
||||
'field_test_text' => array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
'field_test_text' => [
|
||||
[
|
||||
'value' => $values['field_test_text']['value'],
|
||||
'format' => $values['field_test_text']['format'],
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$normalized = $this->serializer->normalize($entity, $this->format);
|
||||
$this->assertEqual($normalized['_links']['self'], $expected_array['_links']['self'], 'self link placed correctly.');
|
||||
|
|
|
@ -2,22 +2,9 @@
|
|||
|
||||
namespace Drupal\Tests\hal\Kernel;
|
||||
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\hal\Encoder\JsonEncoder;
|
||||
use Drupal\hal\Normalizer\ContentEntityNormalizer;
|
||||
use Drupal\hal\Normalizer\EntityReferenceItemNormalizer;
|
||||
use Drupal\hal\Normalizer\FieldItemNormalizer;
|
||||
use Drupal\hal\Normalizer\FieldNormalizer;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\rest\LinkManager\LinkManager;
|
||||
use Drupal\rest\LinkManager\RelationLinkManager;
|
||||
use Drupal\rest\LinkManager\TypeLinkManager;
|
||||
use Drupal\serialization\EntityResolver\ChainEntityResolver;
|
||||
use Drupal\serialization\EntityResolver\TargetIdResolver;
|
||||
use Drupal\serialization\EntityResolver\UuidResolver;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
|
@ -30,7 +17,7 @@ abstract class NormalizerTestBase extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['entity_test', 'field', 'hal', 'language', 'rest', 'serialization', 'system', 'text', 'user', 'filter'];
|
||||
public static $modules = ['entity_test', 'field', 'hal', 'language', 'serialization', 'system', 'text', 'user', 'filter'];
|
||||
|
||||
/**
|
||||
* The mock serializer.
|
||||
|
@ -71,29 +58,29 @@ abstract class NormalizerTestBase extends KernelTestBase {
|
|||
// Only check the modules, if the $modules property was not inherited.
|
||||
$rp = new \ReflectionProperty($class, 'modules');
|
||||
if ($rp->class == $class) {
|
||||
foreach (array_intersect(array('node', 'comment'), $class::$modules) as $module) {
|
||||
foreach (array_intersect(['node', 'comment'], $class::$modules) as $module) {
|
||||
$this->installEntitySchema($module);
|
||||
}
|
||||
}
|
||||
}
|
||||
$class = get_parent_class($class);
|
||||
}
|
||||
$this->installConfig(array('field', 'language'));
|
||||
$this->installConfig(['field', 'language']);
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// Add German as a language.
|
||||
ConfigurableLanguage::create(array(
|
||||
ConfigurableLanguage::create([
|
||||
'id' => 'de',
|
||||
'label' => 'Deutsch',
|
||||
'weight' => -1,
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
// Create the test text field.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'field_test_text',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'text',
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_test_text',
|
||||
|
@ -102,11 +89,11 @@ abstract class NormalizerTestBase extends KernelTestBase {
|
|||
])->save();
|
||||
|
||||
// Create the test translatable field.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'field_test_translatable_text',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'text',
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_test_translatable_text',
|
||||
|
@ -115,14 +102,14 @@ abstract class NormalizerTestBase extends KernelTestBase {
|
|||
])->save();
|
||||
|
||||
// Create the test entity reference field.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'field_test_entity_reference',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'entity_reference',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'target_type' => 'entity_test',
|
||||
),
|
||||
))->save();
|
||||
],
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_test_entity_reference',
|
||||
|
@ -130,23 +117,7 @@ abstract class NormalizerTestBase extends KernelTestBase {
|
|||
'translatable' => TRUE,
|
||||
])->save();
|
||||
|
||||
$entity_manager = \Drupal::entityManager();
|
||||
$link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default'), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack'), \Drupal::service('entity_type.bundle.info')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack')));
|
||||
|
||||
$chain_resolver = new ChainEntityResolver(array(new UuidResolver($entity_manager), new TargetIdResolver()));
|
||||
|
||||
// Set up the mock serializer.
|
||||
$normalizers = array(
|
||||
new ContentEntityNormalizer($link_manager, $entity_manager, \Drupal::moduleHandler()),
|
||||
new EntityReferenceItemNormalizer($link_manager, $chain_resolver),
|
||||
new FieldItemNormalizer(),
|
||||
new FieldNormalizer(),
|
||||
);
|
||||
|
||||
$encoders = array(
|
||||
new JsonEncoder(),
|
||||
);
|
||||
$this->serializer = new Serializer($normalizers, $encoders);
|
||||
$this->serializer = $this->container->get('serializer');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\hal\Unit;
|
||||
|
||||
use Drupal\hal\Normalizer\FieldItemNormalizer;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\hal\Normalizer\FieldItemNormalizer
|
||||
|
@ -17,12 +18,12 @@ class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenorma
|
|||
* Context for FieldItemNormalizer::denormalize().
|
||||
*
|
||||
* @dataProvider providerNormalizerDenormalizeExceptions
|
||||
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testFieldItemNormalizerDenormalizeExceptions($context) {
|
||||
$field_item_normalizer = new FieldItemNormalizer();
|
||||
$data = array();
|
||||
$class = array();
|
||||
$data = [];
|
||||
$class = [];
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
$field_item_normalizer->denormalize($data, $class, NULL, $context);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\hal\Unit;
|
||||
|
||||
use Drupal\hal\Normalizer\FieldNormalizer;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\hal\Normalizer\FieldNormalizer
|
||||
|
@ -17,12 +18,12 @@ class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalize
|
|||
* Context for FieldNormalizer::denormalize().
|
||||
*
|
||||
* @dataProvider providerNormalizerDenormalizeExceptions
|
||||
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testFieldNormalizerDenormalizeExceptions($context) {
|
||||
$field_item_normalizer = new FieldNormalizer();
|
||||
$data = array();
|
||||
$class = array();
|
||||
$data = [];
|
||||
$class = [];
|
||||
$this->setExpectedException(InvalidArgumentException::class);
|
||||
$field_item_normalizer->denormalize($data, $class, NULL, $context);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@ abstract class NormalizerDenormalizeExceptionsUnitTestBase extends UnitTestCase
|
|||
* @return array Test data.
|
||||
*/
|
||||
public function providerNormalizerDenormalizeExceptions() {
|
||||
$mock = $this->getMock('\Drupal\Core\Field\Plugin\DataType\FieldItem', array('getParent'));
|
||||
$mock = $this->getMock('\Drupal\Core\Field\Plugin\DataType\FieldItem', ['getParent']);
|
||||
$mock->expects($this->any())
|
||||
->method('getParent')
|
||||
->will($this->returnValue(NULL));
|
||||
return array(
|
||||
array(array()),
|
||||
array(array('target_instance' => $mock)),
|
||||
);
|
||||
return [
|
||||
[[]],
|
||||
[['target_instance' => $mock]],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue