function NodeFieldMultilingualTest::setUp

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php \Drupal\Tests\node\Functional\NodeFieldMultilingualTest::setUp()
  2. 10 core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php \Drupal\Tests\node\Functional\NodeFieldMultilingualTest::setUp()
  3. 11.x core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php \Drupal\Tests\node\Functional\NodeFieldMultilingualTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/node/tests/src/Functional/NodeFieldMultilingualTest.php, line 30

Class

NodeFieldMultilingualTest
Tests multilingual support for fields.

Namespace

Drupal\Tests\node\Functional

Code

protected function setUp() {
    parent::setUp();
    // Create Basic page node type.
    $this->drupalCreateContentType([
        'type' => 'page',
        'name' => 'Basic page',
    ]);
    // Setup users.
    $admin_user = $this->drupalCreateUser([
        'administer languages',
        'administer content types',
        'access administration pages',
        'create page content',
        'edit own page content',
    ]);
    $this->drupalLogin($admin_user);
    // Add a new language.
    ConfigurableLanguage::createFromLangcode('it')->save();
    // Enable URL language detection and selection.
    $edit = [
        'language_interface[enabled][language-url]' => '1',
    ];
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
    // Set "Basic page" content type to use multilingual support.
    $edit = [
        'language_configuration[language_alterable]' => TRUE,
    ];
    $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
    $this->assertRaw(t('The content type %type has been updated.', [
        '%type' => 'Basic page',
    ]), 'Basic page content type has been updated.');
    // Make node body translatable.
    $field_storage = FieldStorageConfig::loadByName('node', 'body');
    $field_storage->setTranslatable(TRUE);
    $field_storage->save();
}

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