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';
33 protected function getExpectedNormalizedEntity() {
34 $default_normalization = parent::getExpectedNormalizedEntity();
36 $normalization = $this->applyHalFieldNormalization($default_normalization);
38 // Because \Drupal\comment\Entity\Comment::getOwner() generates an in-memory
39 // User entity without a UUID, we cannot use it.
40 $author = User::load($this->entity->getOwnerId());
41 $commented_entity = EntityTest::load(1);
42 return $normalization + [
45 'href' => $this->baseUrl . '/comment/1?_format=hal_json',
48 'href' => $this->baseUrl . '/rest/type/comment/comment',
50 $this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
52 'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
55 $this->baseUrl . '/rest/relation/comment/comment/uid' => [
57 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
63 $this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
67 'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
70 'href' => $this->baseUrl . '/rest/type/entity_test/bar',
74 ['value' => $commented_entity->uuid()]
78 $this->baseUrl . '/rest/relation/comment/comment/uid' => [
82 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
85 'href' => $this->baseUrl . '/rest/type/user/user',
89 ['value' => $author->uuid()]
101 protected function getNormalizedPostEntity() {
102 return parent::getNormalizedPostEntity() + [
105 'href' => $this->baseUrl . '/rest/type/comment/comment',