X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftaxonomy%2Ftests%2Fsrc%2FFunctional%2FHal%2FTermHalJsonAnonTest.php;fp=web%2Fcore%2Fmodules%2Ftaxonomy%2Ftests%2Fsrc%2FFunctional%2FHal%2FTermHalJsonAnonTest.php;h=ee3effc572a23fbb21e26f28c13cafa522eb5807;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/taxonomy/tests/src/Functional/Hal/TermHalJsonAnonTest.php b/web/core/modules/taxonomy/tests/src/Functional/Hal/TermHalJsonAnonTest.php new file mode 100644 index 000000000..ee3effc57 --- /dev/null +++ b/web/core/modules/taxonomy/tests/src/Functional/Hal/TermHalJsonAnonTest.php @@ -0,0 +1,178 @@ +applyHalFieldNormalization($default_normalization); + + // We test with multiple parent terms, and combinations thereof. + // @see ::createEntity() + // @see ::testGet() + // @see ::testGetTermWithParent() + // @see ::providerTestGetTermWithParent() + // @see ::testGetTermWithParent() + $parent_term_ids = []; + for ($i = 0; $i < $this->entity->get('parent')->count(); $i++) { + $parent_term_ids[$i] = (int) $this->entity->get('parent')[$i]->target_id; + } + + $expected_parent_normalization_links = FALSE; + $expected_parent_normalization_embedded = FALSE; + switch ($parent_term_ids) { + case [0]: + $expected_parent_normalization_links = [ + NULL, + ]; + $expected_parent_normalization_embedded = [ + NULL, + ]; + break; + case [2]: + $expected_parent_normalization_links = [ + [ + 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json', + ], + ]; + $expected_parent_normalization_embedded = [ + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids', + ], + ], + 'uuid' => [ + ['value' => Term::load(2)->uuid()], + ], + ], + ]; + break; + case [0, 2]: + $expected_parent_normalization_links = [ + NULL, + [ + 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json', + ], + ]; + $expected_parent_normalization_embedded = [ + NULL, + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids', + ], + ], + 'uuid' => [ + ['value' => Term::load(2)->uuid()], + ], + ], + ]; + break; + case [3, 2]: + $expected_parent_normalization_links = [ + [ + 'href' => $this->baseUrl . '/taxonomy/term/3?_format=hal_json', + ], + [ + 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json', + ], + ]; + $expected_parent_normalization_embedded = [ + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/taxonomy/term/3?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids', + ], + ], + 'uuid' => [ + ['value' => Term::load(3)->uuid()], + ], + ], + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids', + ], + ], + 'uuid' => [ + ['value' => Term::load(2)->uuid()], + ], + ], + ]; + break; + } + + return $normalization + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/llama?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids', + ], + $this->baseUrl . '/rest/relation/taxonomy_term/camelids/parent' => $expected_parent_normalization_links, + ], + '_embedded' => [ + $this->baseUrl . '/rest/relation/taxonomy_term/camelids/parent' => $expected_parent_normalization_embedded, + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return parent::getNormalizedPostEntity() + [ + '_links' => [ + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids', + ], + ], + ]; + } + +}