function NormalizerTestBase::setUp

Same name in this branch
  1. 9 core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase::setUp()
Same name in other branches
  1. 8.9.x core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase::setUp()
  2. 8.9.x core/modules/hal/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\hal\Kernel\NormalizerTestBase::setUp()
  3. 10 core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase::setUp()
  4. 11.x core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase::setUp()

Overrides KernelTestBase::setUp

3 calls to NormalizerTestBase::setUp()
EntityTranslationNormalizeTest::setUp in core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php
FileNormalizeTest::setUp in core/modules/hal/tests/src/Kernel/FileNormalizeTest.php
NormalizeTest::setUp in core/modules/hal/tests/src/Kernel/NormalizeTest.php
3 methods override NormalizerTestBase::setUp()
EntityTranslationNormalizeTest::setUp in core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php
FileNormalizeTest::setUp in core/modules/hal/tests/src/Kernel/FileNormalizeTest.php
NormalizeTest::setUp in core/modules/hal/tests/src/Kernel/NormalizeTest.php

File

core/modules/hal/tests/src/Kernel/NormalizerTestBase.php, line 56

Class

NormalizerTestBase
Test the HAL normalizer.

Namespace

Drupal\Tests\hal\Kernel

Code

protected function setUp() {
    parent::setUp();
    $this->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 = static::class;
    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',
    ]);
    // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.