Newer
Older
Lee Rowlands
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Test that internal properties are not exposed in the 'hal_json' format.
*
* @group hal
*/
class EntityTestHalJsonInternalPropertyNormalizerTest extends EntityTestHalJsonAnonTest {
use AnonResourceTestTrait, HalEntityNormalizationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
// The 'internal_value' property in test field type will not be returned in
// normalization because setInternal(FALSE) was not called for this
// property.
// @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
$normalization['field_test_internal'] = [
[
'value' => 'This value shall not be internal!',
'non_internal_value' => 'Computed! This value shall not be internal!',
],
];
return $normalization;
}
/**
* {@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!',
],
],
];
}
}