function EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode()
  2. 8.9.x core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode()
  3. 10 core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode()

Tests that default language code is properly set for new nodes.

File

core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php, line 56

Class

EntityDefaultLanguageTest
Tests default language code is properly generated for entities.

Namespace

Drupal\Tests\language\Kernel

Code

public function testEntityTranslationDefaultLanguageViaCode() : void {
    // With language module activated, and a content type that is configured to
    // have no language by default, a new node of this content type will have
    // "und" language code when language is not specified.
    $node = $this->createNode('content_und');
    $this->assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED, $node->langcode->value);
    // With language module activated, and a content type that is configured to
    // have no language by default, a new node of this content type will have
    // "es" language code when language is specified as "es".
    $node = $this->createNode('content_und', 'es');
    $this->assertEquals('es', $node->langcode->value);
    // With language module activated, and a content type that is configured to
    // have language "es" by default, a new node of this content type will have
    // "es" language code when language is not specified.
    $node = $this->createNode('content_es');
    $this->assertEquals('es', $node->langcode->value);
    // With language module activated, and a content type that is configured to
    // have language "es" by default, a new node of this content type will have
    // "en" language code when language "en" is specified.
    $node = $this->createNode('content_es', 'en');
    $this->assertEquals('en', $node->langcode->value);
    // Disable language module.
    $this->disableModules([
        'language',
    ]);
    // With language module disabled, and a content type that is configured to
    // have no language specified by default, a new node of this content type
    // will have site's default language code when language is not specified.
    $node = $this->createNode('content_und');
    $this->assertEquals('en', $node->langcode->value);
    // With language module disabled, and a content type that is configured to
    // have no language specified by default, a new node of this type will have
    // "es" language code when language "es" is specified.
    $node = $this->createNode('content_und', 'es');
    $this->assertEquals('es', $node->langcode->value);
    // With language module disabled, and a content type that is configured to
    // have language "es" by default, a new node of this type will have site's
    // default language code when language is not specified.
    $node = $this->createNode('content_es');
    $this->assertEquals('en', $node->langcode->value);
    // With language module disabled, and a content type that is configured to
    // have language "es" by default, a new node of this type will have "en"
    // language code when language "en" is specified.
    $node = $this->createNode('content_es', 'en');
    $this->assertEquals('en', $node->langcode->value);
}

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