You are here

protected function SortTranslationTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php \Drupal\Tests\views\Kernel\Handler\SortTranslationTest::setUp()

Parameters

bool $import_test_views: Should the views specified on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.

Overrides ViewsKernelTestBase::setUp

File

core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php, line 38

Class

SortTranslationTest
Tests sorting on translatable and not translatable fields.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function setUp($import_test_views = TRUE) : void {
  parent::setUp($import_test_views);
  ConfigurableLanguage::createFromLangcode('de')
    ->save();
  $this
    ->installSchema('node', 'node_access');
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('user');

  // $this->installConfig('node');
  $this->container
    ->get('kernel')
    ->rebuildContainer();
  $node_type = NodeType::create([
    'type' => 'article',
  ]);
  $node_type
    ->save();
  FieldStorageConfig::create([
    'field_name' => 'text',
    'entity_type' => 'node',
    'type' => 'string',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'text',
    'entity_type' => 'node',
    'bundle' => 'article',
    'label' => 'Translated text',
    'translatable' => TRUE,
  ])
    ->save();
  FieldStorageConfig::create([
    'field_name' => 'weight',
    'entity_type' => 'node',
    'type' => 'integer',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'weight',
    'entity_type' => 'node',
    'bundle' => 'article',
    'translatable' => FALSE,
  ])
    ->save();
  for ($i = 0; $i < 3; $i++) {
    $node = Node::create([
      'type' => 'article',
      'title' => 'Title en ' . $i,
      'weight' => [
        'value' => 3 - $i,
      ],
      'text' => [
        'value' => 'moo en ' . $i,
      ],
      'langcode' => 'en',
    ]);
    $node
      ->save();
    $translation = $node
      ->addTranslation('de');
    $translation->title->value = 'Title DE ' . $i;
    $translation->text->value = 'moo DE ' . $i;
    $translation
      ->save();
  }
}