function TermTranslationFieldViewTest::setUpNode

Same name in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Functional/TermTranslationFieldViewTest.php \Drupal\Tests\taxonomy\Functional\TermTranslationFieldViewTest::setUpNode()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermTranslationFieldViewTest.php \Drupal\Tests\taxonomy\Functional\TermTranslationFieldViewTest::setUpNode()
  3. 11.x core/modules/taxonomy/tests/src/Functional/TermTranslationFieldViewTest.php \Drupal\Tests\taxonomy\Functional\TermTranslationFieldViewTest::setUpNode()

Creates a test subject node, with translation.

1 call to TermTranslationFieldViewTest::setUpNode()
TermTranslationFieldViewTest::setUp in core/modules/taxonomy/tests/src/Functional/TermTranslationFieldViewTest.php

File

core/modules/taxonomy/tests/src/Functional/TermTranslationFieldViewTest.php, line 80

Class

TermTranslationFieldViewTest
Tests the translation of taxonomy terms field on nodes.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUpNode() {
    
    /** @var \Drupal\node\Entity\Node $node */
    $node = Node::create([
        'title' => $this->randomMachineName(),
        'type' => 'article',
        'description' => [
            [
                'value' => $this->randomMachineName(),
                'format' => 'basic_html',
            ],
        ],
        $this->termFieldName => [
            [
                'target_id' => $this->term
                    ->id(),
            ],
        ],
        'langcode' => $this->baseLangcode,
    ]);
    $node->save();
    $node->addTranslation($this->translateToLangcode, $node->toArray());
    $node->save();
    $this->node = $node;
}

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