function SortTranslationTest::setUp

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php \Drupal\Tests\views\Kernel\Handler\SortTranslationTest::setUp()
  2. 10 core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php \Drupal\Tests\views\Kernel\Handler\SortTranslationTest::setUp()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php \Drupal\Tests\views\Kernel\Handler\SortTranslationTest::setUp()

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();
    }
}

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