3 namespace Drupal\Tests\taxonomy\Functional\Hal;
5 use Drupal\taxonomy\Entity\Term;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
8 use Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase;
13 class TermHalJsonAnonTest extends TermResourceTestBase {
15 use HalEntityNormalizationTrait;
16 use AnonResourceTestTrait;
21 public static $modules = ['hal'];
26 protected static $format = 'hal_json';
31 protected static $mimeType = 'application/hal+json';
36 protected function getExpectedNormalizedEntity() {
37 $default_normalization = parent::getExpectedNormalizedEntity();
39 $normalization = $this->applyHalFieldNormalization($default_normalization);
41 // We test with multiple parent terms, and combinations thereof.
42 // @see ::createEntity()
44 // @see ::testGetTermWithParent()
45 // @see ::providerTestGetTermWithParent()
46 // @see ::testGetTermWithParent()
47 $parent_term_ids = [];
48 for ($i = 0; $i < $this->entity->get('parent')->count(); $i++) {
49 $parent_term_ids[$i] = (int) $this->entity->get('parent')[$i]->target_id;
52 $expected_parent_normalization_links = FALSE;
53 $expected_parent_normalization_embedded = FALSE;
54 switch ($parent_term_ids) {
56 $expected_parent_normalization_links = [
59 $expected_parent_normalization_embedded = [
64 $expected_parent_normalization_links = [
66 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
69 $expected_parent_normalization_embedded = [
73 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
76 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
80 ['value' => Term::load(2)->uuid()],
86 $expected_parent_normalization_links = [
89 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
92 $expected_parent_normalization_embedded = [
97 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
100 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
104 ['value' => Term::load(2)->uuid()],
110 $expected_parent_normalization_links = [
112 'href' => $this->baseUrl . '/taxonomy/term/3?_format=hal_json',
115 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
118 $expected_parent_normalization_embedded = [
122 'href' => $this->baseUrl . '/taxonomy/term/3?_format=hal_json',
125 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
129 ['value' => Term::load(3)->uuid()],
135 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
138 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
142 ['value' => Term::load(2)->uuid()],
149 return $normalization + [
152 'href' => $this->baseUrl . '/llama?_format=hal_json',
155 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
157 $this->baseUrl . '/rest/relation/taxonomy_term/camelids/parent' => $expected_parent_normalization_links,
160 $this->baseUrl . '/rest/relation/taxonomy_term/camelids/parent' => $expected_parent_normalization_embedded,
168 protected function getNormalizedPostEntity() {
169 return parent::getNormalizedPostEntity() + [
172 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',