class EntityTestJsonInternalPropertyNormalizerTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestJsonInternalPropertyNormalizerTest.php \Drupal\Tests\entity_test\Functional\Rest\EntityTestJsonInternalPropertyNormalizerTest
Test that internal properties are not exposed in the 'json' format.
@group rest
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\rest\Functional\ResourceTestBase implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase implements \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase implements \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase
- class \Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase uses \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait implements \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase
- class \Drupal\Tests\entity_test\Functional\Rest\EntityTestJsonInternalPropertyNormalizerTest uses \Drupal\Tests\rest\Functional\AnonResourceTestTrait implements \Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase
- class \Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase uses \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait implements \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase implements \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase implements \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\ResourceTestBase implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of EntityTestJsonInternalPropertyNormalizerTest
File
-
core/
modules/ system/ tests/ modules/ entity_test/ tests/ src/ Functional/ Rest/ EntityTestJsonInternalPropertyNormalizerTest.php, line 15
Namespace
Drupal\Tests\entity_test\Functional\RestView source
class EntityTestJsonInternalPropertyNormalizerTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$expected = parent::getExpectedNormalizedEntity();
// The 'internal_value' property in test field type is not exposed in the
// normalization because setInternal(FALSE) was not called for this
// property.
// @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
$expected['field_test_internal'] = [
[
'value' => 'This value shall not be internal!',
'non_internal_value' => 'Computed! This value shall not be internal!',
],
];
return $expected;
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'type' => 'internal_property_test',
'cardinality' => 1,
'translatable' => FALSE,
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'bundle' => 'entity_test',
'label' => 'Test field with internal and non-internal properties',
])->save();
}
$entity = parent::createEntity();
$entity->field_test_internal = [
'value' => 'This value shall not be internal!',
];
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'field_test_internal' => [
[
'value' => 'This value shall not be internal!',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), [
'request_format',
]);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), [
'you_are_it',
'no_tag_backs',
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.