You are here

public function EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode in Drupal 9

Same name and namespace in other branches
  1. 8 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 53

Class

EntityDefaultLanguageTest
Tests default language code is properly generated for entities.

Namespace

Drupal\Tests\language\Kernel

Code

public function testEntityTranslationDefaultLanguageViaCode() {

  // 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('ctund');
  $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('ctund', '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('ctes');
  $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('ctes', '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('ctund');
  $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('ctund', '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('ctes');
  $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('ctes', 'en');
  $this
    ->assertEquals('en', $node->langcode->value);
}