3 namespace Drupal\Tests\hal\Functional\EntityResource\Comment;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\Comment\CommentResourceTestBase;
8 use Drupal\user\Entity\User;
10 abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
12 use HalEntityNormalizationTrait;
17 public static $modules = ['hal'];
22 protected static $format = 'hal_json';
27 protected static $mimeType = 'application/hal+json';
32 * The HAL+JSON format causes different PATCH-protected fields. For some
33 * reason, the 'pid' and 'homepage' fields are NOT PATCH-protected, even
34 * though they are for non-HAL+JSON serializations.
36 * @todo fix in https://www.drupal.org/node/2824271
38 protected static $patchProtectedFieldNames = [
52 protected function getExpectedNormalizedEntity() {
53 $default_normalization = parent::getExpectedNormalizedEntity();
55 $normalization = $this->applyHalFieldNormalization($default_normalization);
57 // Because \Drupal\comment\Entity\Comment::getOwner() generates an in-memory
58 // User entity without a UUID, we cannot use it.
59 $author = User::load($this->entity->getOwnerId());
60 $commented_entity = EntityTest::load(1);
61 return $normalization + [
64 'href' => $this->baseUrl . '/comment/1?_format=hal_json',
67 'href' => $this->baseUrl . '/rest/type/comment/comment',
69 $this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
71 'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
74 $this->baseUrl . '/rest/relation/comment/comment/uid' => [
76 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
82 $this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
86 'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
89 'href' => $this->baseUrl . '/rest/type/entity_test/bar',
93 ['value' => $commented_entity->uuid()]
97 $this->baseUrl . '/rest/relation/comment/comment/uid' => [
101 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
104 'href' => $this->baseUrl . '/rest/type/user/user',
108 ['value' => $author->uuid()]
120 protected function getNormalizedPostEntity() {
121 return parent::getNormalizedPostEntity() + [
124 'href' => $this->baseUrl . '/rest/type/comment/comment',