You are here

protected function NormalizerTestBase::setUp in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/hal/src/Tests/NormalizerTestBase.php \Drupal\hal\Tests\NormalizerTestBase::setUp()
  2. 8 core/modules/serialization/src/Tests/NormalizerTestBase.php \Drupal\serialization\Tests\NormalizerTestBase::setUp()
Same name and namespace in other branches
  1. 8.0 core/modules/hal/src/Tests/NormalizerTestBase.php \Drupal\hal\Tests\NormalizerTestBase::setUp()

Performs setup tasks before each individual test method is run.

Overrides KernelTestBase::setUp

3 calls to NormalizerTestBase::setUp()
EntityTest::setUp in core/modules/hal/src/Tests/EntityTest.php
Performs setup tasks before each individual test method is run.
FileNormalizeTest::setUp in core/modules/hal/src/Tests/FileNormalizeTest.php
Performs setup tasks before each individual test method is run.
NormalizeTest::setUp in core/modules/hal/src/Tests/NormalizeTest.php
Performs setup tasks before each individual test method is run.
3 methods override NormalizerTestBase::setUp()
EntityTest::setUp in core/modules/hal/src/Tests/EntityTest.php
Performs setup tasks before each individual test method is run.
FileNormalizeTest::setUp in core/modules/hal/src/Tests/FileNormalizeTest.php
Performs setup tasks before each individual test method is run.
NormalizeTest::setUp in core/modules/hal/src/Tests/NormalizeTest.php
Performs setup tasks before each individual test method is run.

File

core/modules/hal/src/Tests/NormalizerTestBase.php, line 62
Contains \Drupal\hal\Tests\NormalizerTestBase.

Class

NormalizerTestBase
Test the HAL normalizer.

Namespace

Drupal\hal\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installSchema('system', array(
    'url_alias',
    'router',
  ));
  $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 = 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(array(
          'node',
          'comment',
        ), $class::$modules) as $module) {
          $this
            ->installEntitySchema($module);
        }
      }
    }
    $class = get_parent_class($class);
  }
  $this
    ->installConfig(array(
    'field',
    'language',
  ));
  \Drupal::service('router.builder')
    ->rebuild();

  // Add German as a language.
  ConfigurableLanguage::create(array(
    'id' => 'de',
    'label' => 'Deutsch',
    'weight' => -1,
  ))
    ->save();

  // Create the test text field.
  entity_create('field_storage_config', array(
    'field_name' => 'field_test_text',
    'entity_type' => 'entity_test',
    'type' => 'text',
  ))
    ->save();
  entity_create('field_config', array(
    'entity_type' => 'entity_test',
    'field_name' => 'field_test_text',
    'bundle' => 'entity_test',
    'translatable' => FALSE,
  ))
    ->save();

  // Create the test translatable field.
  entity_create('field_storage_config', array(
    'field_name' => 'field_test_translatable_text',
    'entity_type' => 'entity_test',
    'type' => 'text',
  ))
    ->save();
  entity_create('field_config', array(
    'entity_type' => 'entity_test',
    'field_name' => 'field_test_translatable_text',
    'bundle' => 'entity_test',
    'translatable' => TRUE,
  ))
    ->save();

  // Create the test entity reference field.
  entity_create('field_storage_config', array(
    'field_name' => 'field_test_entity_reference',
    'entity_type' => 'entity_test',
    'type' => 'entity_reference',
    'settings' => array(
      'target_type' => 'entity_test',
    ),
  ))
    ->save();
  entity_create('field_config', array(
    'entity_type' => 'entity_test',
    'field_name' => 'field_test_entity_reference',
    'bundle' => 'entity_test',
    'translatable' => TRUE,
  ))
    ->save();
  $entity_manager = \Drupal::entityManager();
  $link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default'), \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager, \Drupal::moduleHandler(), \Drupal::service('config.factory'), \Drupal::service('request_stack')));
  $chain_resolver = new ChainEntityResolver(array(
    new UuidResolver($entity_manager),
    new TargetIdResolver(),
  ));

  // Set up the mock serializer.
  $normalizers = array(
    new ContentEntityNormalizer($link_manager, $entity_manager, \Drupal::moduleHandler()),
    new EntityReferenceItemNormalizer($link_manager, $chain_resolver),
    new FieldItemNormalizer(),
    new FieldNormalizer(),
  );
  $encoders = array(
    new JsonEncoder(),
  );
  $this->serializer = new Serializer($normalizers, $encoders);
}