You are here

protected function TermResourceTestBase::getExpectedNormalizedEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::getExpectedNormalizedEntity()

Returns the expected normalization of the entity.

Return value

array

Overrides EntityResourceTestBase::getExpectedNormalizedEntity

See also

::createEntity()

2 calls to TermResourceTestBase::getExpectedNormalizedEntity()
TermHalJsonAnonTest::getExpectedNormalizedEntity in core/modules/taxonomy/tests/src/Functional/Hal/TermHalJsonAnonTest.php
Returns the expected normalization of the entity.
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).
1 method overrides TermResourceTestBase::getExpectedNormalizedEntity()
TermHalJsonAnonTest::getExpectedNormalizedEntity in core/modules/taxonomy/tests/src/Functional/Hal/TermHalJsonAnonTest.php
Returns the expected normalization of the entity.

File

core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php, line 91

Class

TermResourceTestBase

Namespace

Drupal\Tests\taxonomy\Functional\Rest

Code

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_log_message' => [],
    'revision_translation_affected' => [
      [
        'value' => TRUE,
      ],
    ],
  ];
}