protected function TermResourceTestBase::getExpectedNormalizedEntity in Drupal 8
Same name and namespace in other branches
- 9 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 94
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' => [
$this
->formatExpectedTimestampItemValues($this->entity
->getChangedTime()),
],
'default_langcode' => [
[
'value' => TRUE,
],
],
'path' => [
[
'alias' => '/llama',
'pid' => 1,
'langcode' => 'en',
],
],
'status' => [
[
'value' => TRUE,
],
],
'revision_created' => [
$this
->formatExpectedTimestampItemValues((int) $this->entity
->getRevisionCreationTime()),
],
'revision_user' => [],
'revision_log_message' => [],
'revision_translation_affected' => [
[
'value' => TRUE,
],
],
];
}