function TermResourceTestBase::getExpectedNormalizedEntity
Same name in other branches
- 9 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::getExpectedNormalizedEntity()
- 8.9.x core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::getExpectedNormalizedEntity()
- 11.x core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::getExpectedNormalizedEntity()
Overrides EntityResourceTestBase::getExpectedNormalizedEntity
1 call to TermResourceTestBase::getExpectedNormalizedEntity()
- TermResourceTestBase::testGetTermWithParent in core/
modules/ taxonomy/ tests/ src/ Functional/ Rest/ TermResourceTestBase.php - Tests GETting a term with a parent term other than the default <root> (0).
File
-
core/
modules/ taxonomy/ tests/ src/ Functional/ Rest/ TermResourceTestBase.php, line 104
Class
Namespace
Drupal\Tests\taxonomy\Functional\RestCode
protected function getExpectedNormalizedEntity() {
// We test with multiple parent terms, and combinations thereof.
// @see ::createEntity()
// @see ::testGet()
// @see ::testGetTermWithParent()
// @see ::providerTestGetTermWithParent()
$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 = FALSE;
switch ($parent_term_ids) {
case [
0,
]:
$expected_parent_normalization = [
[
'target_id' => NULL,
],
];
break;
case [
2,
]:
$expected_parent_normalization = [
[
'target_id' => 2,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(2)->uuid(),
'url' => base_path() . 'taxonomy/term/2',
],
];
break;
case [
0,
2,
]:
$expected_parent_normalization = [
[
'target_id' => NULL,
],
[
'target_id' => 2,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(2)->uuid(),
'url' => base_path() . 'taxonomy/term/2',
],
];
break;
case [
3,
2,
]:
$expected_parent_normalization = [
[
'target_id' => 3,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(3)->uuid(),
'url' => base_path() . 'taxonomy/term/3',
],
[
'target_id' => 2,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(2)->uuid(),
'url' => base_path() . 'taxonomy/term/2',
],
];
break;
}
return [
'tid' => [
[
'value' => 1,
],
],
'revision_id' => [
[
'value' => 1,
],
],
'uuid' => [
[
'value' => $this->entity
->uuid(),
],
],
'vid' => [
[
'target_id' => 'camelids',
'target_type' => 'taxonomy_vocabulary',
'target_uuid' => Vocabulary::load('camelids')->uuid(),
],
],
'name' => [
[
'value' => 'Llama',
],
],
'description' => [
[
'value' => 'It is a little known fact that llamas cannot count higher than seven.',
'format' => NULL,
'processed' => "<p>It is a little known fact that llamas cannot count higher than seven.</p>\n",
],
],
'parent' => $expected_parent_normalization,
'weight' => [
[
'value' => 0,
],
],
'langcode' => [
[
'value' => 'en',
],
],
'changed' => [
[
'value' => (new \DateTime())->setTimestamp($this->entity
->getChangedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'format' => \DateTime::RFC3339,
],
],
'default_langcode' => [
[
'value' => TRUE,
],
],
'path' => [
[
'alias' => '/llama',
'pid' => 1,
'langcode' => 'en',
],
],
'status' => [
[
'value' => TRUE,
],
],
'revision_created' => [
[
'value' => (new \DateTime())->setTimestamp((int) $this->entity
->getRevisionCreationTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'format' => \DateTime::RFC3339,
],
],
'revision_user' => [],
'revision_translation_affected' => [
[
'value' => TRUE,
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.