updated core
This commit is contained in:
@@ -7,8 +7,8 @@ package: Web services
|
||||
dependencies:
|
||||
- serialization
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\hal\EventSubscriber;
|
||||
|
||||
use Drupal\Core\EventSubscriber\ExceptionJsonSubscriber;
|
||||
|
||||
/**
|
||||
* Handle HAL JSON exceptions the same as JSON exceptions.
|
||||
*/
|
||||
class ExceptionHalJsonSubscriber extends ExceptionJsonSubscriber {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getHandledFormats() {
|
||||
return ['hal_json'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\hal\Tests;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests that file entities can be denormalized in HAL.
|
||||
*
|
||||
* @group hal
|
||||
* @see \Drupal\hal\Normalizer\FileEntityNormalizer
|
||||
*/
|
||||
class FileDenormalizeTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('hal', 'file', 'node');
|
||||
|
||||
/**
|
||||
* Tests file entity denormalization.
|
||||
*/
|
||||
public function testFileDenormalize() {
|
||||
$file_params = array(
|
||||
'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 = array(
|
||||
'uri' => array(
|
||||
array('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.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
|
||||
// User entity without a UUID, we cannot use it.
|
||||
$author = User::load($this->entity->getOwnerId());
|
||||
$commented_entity = EntityTest::load(1);
|
||||
return $normalization + [
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/comment/1?_format=hal_json',
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
|
||||
$normalization = $this->applyHalFieldNormalization($default_normalization);
|
||||
|
||||
$author = User::load(0);
|
||||
return $normalization + [
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
|
||||
|
||||
@@ -97,7 +97,6 @@ trait HalEntityNormalizationTrait {
|
||||
if ($this->entity->getEntityType()->hasKey('bundle')) {
|
||||
$normalization = $this->getNormalizedPostEntity();
|
||||
|
||||
|
||||
$normalization['_links']['type'] = Url::fromUri('base:rest/type/' . static::$entityTypeId . '/bad_bundle_name');
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format);
|
||||
|
||||
@@ -105,11 +104,9 @@ trait HalEntityNormalizationTrait {
|
||||
$response = $this->request($method, $url, $request_options);
|
||||
$this->assertResourceErrorResponse(422, 'No entity type(s) specified', $response);
|
||||
|
||||
|
||||
unset($normalization['_links']['type']);
|
||||
$request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format);
|
||||
|
||||
|
||||
// DX: 422 when no entity type bundle is specified.
|
||||
$response = $this->request($method, $url, $request_options);
|
||||
$this->assertResourceErrorResponse(422, 'The type link relation must be specified.', $response);
|
||||
|
||||
@@ -52,7 +52,7 @@ class NodeHalJsonAnonTest extends NodeResourceTestBase {
|
||||
$normalization = $this->applyHalFieldNormalization($default_normalization);
|
||||
|
||||
$author = User::load($this->entity->getOwnerId());
|
||||
return $normalization + [
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/llama?_format=hal_json',
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\hal\Kernel;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
|
||||
/**
|
||||
* Tests that nodes and terms are correctly normalized and denormalized.
|
||||
*
|
||||
* @group hal
|
||||
*/
|
||||
class EntityNormalizeTest extends NormalizerTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'taxonomy', 'comment');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
$this->installSchema('system', array('sequences'));
|
||||
$this->installSchema('comment', array('comment_entity_statistics'));
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['node', 'comment']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the normalization of nodes.
|
||||
*/
|
||||
public function testNode() {
|
||||
$node_type = NodeType::create(['type' => 'example_type']);
|
||||
$node_type->save();
|
||||
|
||||
$user = User::create(['name' => $this->randomMachineName()]);
|
||||
$user->save();
|
||||
|
||||
// Add comment type.
|
||||
$this->container->get('entity.manager')->getStorage('comment_type')->create(array(
|
||||
'id' => 'comment',
|
||||
'label' => 'comment',
|
||||
'target_entity_type_id' => 'node',
|
||||
))->save();
|
||||
|
||||
$this->addDefaultCommentField('node', 'example_type');
|
||||
|
||||
$node = Node::create([
|
||||
'title' => $this->randomMachineName(),
|
||||
'uid' => $user->id(),
|
||||
'type' => $node_type->id(),
|
||||
'status' => NODE_PUBLISHED,
|
||||
'promote' => 1,
|
||||
'sticky' => 0,
|
||||
'body' => [
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => $this->randomMachineName()
|
||||
],
|
||||
'revision_log' => $this->randomString(),
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
$original_values = $node->toArray();
|
||||
|
||||
$normalized = $this->serializer->normalize($node, $this->format);
|
||||
|
||||
/** @var \Drupal\node\NodeInterface $denormalized_node */
|
||||
$denormalized_node = $this->serializer->denormalize($normalized, 'Drupal\node\Entity\Node', $this->format);
|
||||
|
||||
$this->assertEqual($original_values, $denormalized_node->toArray(), 'Node values are restored after normalizing and denormalizing.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the normalization of terms.
|
||||
*/
|
||||
public function testTerm() {
|
||||
$vocabulary = Vocabulary::create(['vid' => 'example_vocabulary']);
|
||||
$vocabulary->save();
|
||||
|
||||
$account = User::create(['name' => $this->randomMachineName()]);
|
||||
$account->save();
|
||||
|
||||
// @todo Until https://www.drupal.org/node/2327935 is fixed, if no parent is
|
||||
// set, the test fails because target_id => 0 is reserialized to NULL.
|
||||
$term_parent = Term::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => $vocabulary->id(),
|
||||
]);
|
||||
$term_parent->save();
|
||||
$term = Term::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => $vocabulary->id(),
|
||||
'description' => array(
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => $this->randomMachineName(),
|
||||
),
|
||||
'parent' => $term_parent->id(),
|
||||
]);
|
||||
$term->save();
|
||||
|
||||
$original_values = $term->toArray();
|
||||
|
||||
$normalized = $this->serializer->normalize($term, $this->format, ['account' => $account]);
|
||||
|
||||
/** @var \Drupal\taxonomy\TermInterface $denormalized_term */
|
||||
$denormalized_term = $this->serializer->denormalize($normalized, 'Drupal\taxonomy\Entity\Term', $this->format, ['account' => $account]);
|
||||
|
||||
$this->assertEqual($original_values, $denormalized_term->toArray(), 'Term values are restored after normalizing and denormalizing.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the normalization of comments.
|
||||
*/
|
||||
public function testComment() {
|
||||
$node_type = NodeType::create(['type' => 'example_type']);
|
||||
$node_type->save();
|
||||
|
||||
$account = User::create(['name' => $this->randomMachineName()]);
|
||||
$account->save();
|
||||
|
||||
// Add comment type.
|
||||
$this->container->get('entity.manager')->getStorage('comment_type')->create(array(
|
||||
'id' => 'comment',
|
||||
'label' => 'comment',
|
||||
'target_entity_type_id' => 'node',
|
||||
))->save();
|
||||
|
||||
$this->addDefaultCommentField('node', 'example_type');
|
||||
|
||||
$node = Node::create([
|
||||
'title' => $this->randomMachineName(),
|
||||
'uid' => $account->id(),
|
||||
'type' => $node_type->id(),
|
||||
'status' => NODE_PUBLISHED,
|
||||
'promote' => 1,
|
||||
'sticky' => 0,
|
||||
'body' => [[
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => $this->randomMachineName()
|
||||
]],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
$parent_comment = Comment::create(array(
|
||||
'uid' => $account->id(),
|
||||
'subject' => $this->randomMachineName(),
|
||||
'comment_body' => [
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => NULL,
|
||||
],
|
||||
'entity_id' => $node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
));
|
||||
$parent_comment->save();
|
||||
|
||||
$comment = Comment::create(array(
|
||||
'uid' => $account->id(),
|
||||
'subject' => $this->randomMachineName(),
|
||||
'comment_body' => [
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => NULL,
|
||||
],
|
||||
'entity_id' => $node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'pid' => $parent_comment->id(),
|
||||
'mail' => 'dries@drupal.org',
|
||||
'homepage' => 'http://buytaert.net',
|
||||
));
|
||||
$comment->save();
|
||||
|
||||
$original_values = $comment->toArray();
|
||||
// Hostname will always be denied view access.
|
||||
// No value will exist for name as this is only for anonymous users.
|
||||
unset($original_values['hostname'], $original_values['name']);
|
||||
|
||||
$normalized = $this->serializer->normalize($comment, $this->format, ['account' => $account]);
|
||||
|
||||
// Assert that the hostname field does not appear at all in the normalized
|
||||
// data.
|
||||
$this->assertFalse(array_key_exists('hostname', $normalized), 'Hostname was not found in normalized comment data.');
|
||||
|
||||
/** @var \Drupal\comment\CommentInterface $denormalized_comment */
|
||||
$denormalized_comment = $this->serializer->denormalize($normalized, 'Drupal\comment\Entity\Comment', $this->format, ['account' => $account]);
|
||||
|
||||
// Before comparing, unset values that are expected to differ.
|
||||
$denormalized_comment_values = $denormalized_comment->toArray();
|
||||
unset($denormalized_comment_values['hostname'], $denormalized_comment_values['name']);
|
||||
$this->assertEqual($original_values, $denormalized_comment_values, 'The expected comment values are restored after normalizing and denormalizing.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user