3 namespace Drupal\Tests\hal\Kernel;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\KernelTests\KernelTestBase;
8 use Drupal\field\Entity\FieldStorageConfig;
11 * Test the HAL normalizer.
13 abstract class NormalizerTestBase extends KernelTestBase {
20 public static $modules = ['entity_test', 'field', 'hal', 'language', 'serialization', 'system', 'text', 'user', 'filter'];
23 * The mock serializer.
25 * @var \Symfony\Component\Serializer\Serializer
27 protected $serializer;
30 * The format being tested.
34 protected $format = 'hal_json';
37 * The class name of the test class.
41 protected $entityClass = 'Drupal\entity_test\Entity\EntityTest';
46 protected function setUp() {
48 $this->installEntitySchema('user');
49 $this->installEntitySchema('entity_test');
50 // If the concrete test sub-class installs the Node or Comment modules,
51 // ensure that the node and comment entity schema are created before the
52 // field configurations are installed. This is because the entity tables
53 // need to be created before the body field storage tables. This prevents
54 // trying to create the body field tables twice.
55 $class = get_class($this);
57 if (property_exists($class, 'modules')) {
58 // Only check the modules, if the $modules property was not inherited.
59 $rp = new \ReflectionProperty($class, 'modules');
60 if ($rp->class == $class) {
61 foreach (array_intersect(['node', 'comment'], $class::$modules) as $module) {
62 $this->installEntitySchema($module);
66 $class = get_parent_class($class);
68 $this->installConfig(['field', 'language']);
69 \Drupal::service('router.builder')->rebuild();
71 // Add German as a language.
72 ConfigurableLanguage::create([
78 // Create the test text field.
79 FieldStorageConfig::create([
80 'field_name' => 'field_test_text',
81 'entity_type' => 'entity_test',
85 'entity_type' => 'entity_test',
86 'field_name' => 'field_test_text',
87 'bundle' => 'entity_test',
88 'translatable' => FALSE,
91 // Create the test translatable field.
92 FieldStorageConfig::create([
93 'field_name' => 'field_test_translatable_text',
94 'entity_type' => 'entity_test',
98 'entity_type' => 'entity_test',
99 'field_name' => 'field_test_translatable_text',
100 'bundle' => 'entity_test',
101 'translatable' => TRUE,
104 // Create the test entity reference field.
105 FieldStorageConfig::create([
106 'field_name' => 'field_test_entity_reference',
107 'entity_type' => 'entity_test',
108 'type' => 'entity_reference',
110 'target_type' => 'entity_test',
113 FieldConfig::create([
114 'entity_type' => 'entity_test',
115 'field_name' => 'field_test_entity_reference',
116 'bundle' => 'entity_test',
117 'translatable' => TRUE,
120 $this->serializer = $this->container->get('serializer');