Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / hal / tests / src / Kernel / NormalizerTestBase.php
1 <?php
2
3 namespace Drupal\Tests\hal\Kernel;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\KernelTests\KernelTestBase;
8 use Drupal\field\Entity\FieldStorageConfig;
9
10 /**
11  * Test the HAL normalizer.
12  */
13 abstract class NormalizerTestBase extends KernelTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['entity_test', 'field', 'hal', 'language', 'serialization', 'system', 'text', 'user', 'filter'];
21
22   /**
23    * The mock serializer.
24    *
25    * @var \Symfony\Component\Serializer\Serializer
26    */
27   protected $serializer;
28
29   /**
30    * The format being tested.
31    *
32    * @var string
33    */
34   protected $format = 'hal_json';
35
36   /**
37    * The class name of the test class.
38    *
39    * @var string
40    */
41   protected $entityClass = 'Drupal\entity_test\Entity\EntityTest';
42
43   /**
44    * {@inheritdoc}
45    */
46   protected function setUp() {
47     parent::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);
56     while ($class) {
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);
63           }
64         }
65       }
66       $class = get_parent_class($class);
67     }
68     $this->installConfig(['field', 'language']);
69     \Drupal::service('router.builder')->rebuild();
70
71     // Add German as a language.
72     ConfigurableLanguage::create([
73       'id' => 'de',
74       'label' => 'Deutsch',
75       'weight' => -1,
76     ])->save();
77
78     // Create the test text field.
79     FieldStorageConfig::create([
80       'field_name' => 'field_test_text',
81       'entity_type' => 'entity_test',
82       'type' => 'text',
83     ])->save();
84     FieldConfig::create([
85       'entity_type' => 'entity_test',
86       'field_name' => 'field_test_text',
87       'bundle' => 'entity_test',
88       'translatable' => FALSE,
89     ])->save();
90
91     // Create the test translatable field.
92     FieldStorageConfig::create([
93       'field_name' => 'field_test_translatable_text',
94       'entity_type' => 'entity_test',
95       'type' => 'text',
96     ])->save();
97     FieldConfig::create([
98       'entity_type' => 'entity_test',
99       'field_name' => 'field_test_translatable_text',
100       'bundle' => 'entity_test',
101       'translatable' => TRUE,
102     ])->save();
103
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',
109       'settings' => [
110         'target_type' => 'entity_test',
111       ],
112     ])->save();
113     FieldConfig::create([
114       'entity_type' => 'entity_test',
115       'field_name' => 'field_test_entity_reference',
116       'bundle' => 'entity_test',
117       'translatable' => TRUE,
118     ])->save();
119
120     $this->serializer = $this->container->get('serializer');
121   }
122
123 }