X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fhal%2Ftests%2Fsrc%2FKernel%2FNormalizerTestBase.php;fp=web%2Fcore%2Fmodules%2Fhal%2Ftests%2Fsrc%2FKernel%2FNormalizerTestBase.php;h=ef51a077c94f72977e95814c66e5293e75a67e53;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php b/web/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php new file mode 100644 index 000000000..ef51a077c --- /dev/null +++ b/web/core/modules/hal/tests/src/Kernel/NormalizerTestBase.php @@ -0,0 +1,123 @@ +installEntitySchema('user'); + $this->installEntitySchema('entity_test'); + // If the concrete test sub-class installs the Node or Comment modules, + // ensure that the node and comment entity schema are created before the + // field configurations are installed. This is because the entity tables + // need to be created before the body field storage tables. This prevents + // trying to create the body field tables twice. + $class = get_class($this); + while ($class) { + if (property_exists($class, 'modules')) { + // Only check the modules, if the $modules property was not inherited. + $rp = new \ReflectionProperty($class, 'modules'); + if ($rp->class == $class) { + foreach (array_intersect(['node', 'comment'], $class::$modules) as $module) { + $this->installEntitySchema($module); + } + } + } + $class = get_parent_class($class); + } + $this->installConfig(['field', 'language']); + \Drupal::service('router.builder')->rebuild(); + + // Add German as a language. + ConfigurableLanguage::create([ + 'id' => 'de', + 'label' => 'Deutsch', + 'weight' => -1, + ])->save(); + + // Create the test text field. + FieldStorageConfig::create([ + 'field_name' => 'field_test_text', + 'entity_type' => 'entity_test', + 'type' => 'text', + ])->save(); + FieldConfig::create([ + 'entity_type' => 'entity_test', + 'field_name' => 'field_test_text', + 'bundle' => 'entity_test', + 'translatable' => FALSE, + ])->save(); + + // Create the test translatable field. + FieldStorageConfig::create([ + 'field_name' => 'field_test_translatable_text', + 'entity_type' => 'entity_test', + 'type' => 'text', + ])->save(); + FieldConfig::create([ + 'entity_type' => 'entity_test', + 'field_name' => 'field_test_translatable_text', + 'bundle' => 'entity_test', + 'translatable' => TRUE, + ])->save(); + + // Create the test entity reference field. + FieldStorageConfig::create([ + 'field_name' => 'field_test_entity_reference', + 'entity_type' => 'entity_test', + 'type' => 'entity_reference', + 'settings' => [ + 'target_type' => 'entity_test', + ], + ])->save(); + FieldConfig::create([ + 'entity_type' => 'entity_test', + 'field_name' => 'field_test_entity_reference', + 'bundle' => 'entity_test', + 'translatable' => TRUE, + ])->save(); + + $this->serializer = $this->container->get('serializer'); + } + +}