function ContentTranslationLanguageChangeTest::testLanguageChange

Same name and namespace in other branches
  1. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationLanguageChangeTest::testLanguageChange()
  2. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationLanguageChangeTest::testLanguageChange()
  3. 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationLanguageChangeTest::testLanguageChange()

Tests that the source language is properly set when changing.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php, line 89

Class

ContentTranslationLanguageChangeTest
Tests the content translation language that is set.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function testLanguageChange() {
    // Create a node in English.
    $this->drupalGet('node/add/article');
    $edit = [
        'title[0][value]' => 'english_title',
    ];
    $this->submitForm($edit, 'Save');
    // Create a translation in French.
    $this->clickLink('Translate');
    $this->clickLink('Add');
    $this->submitForm([], 'Save (this translation)');
    $this->clickLink('Translate');
    // Edit English translation.
    $this->clickLink('Edit', 1);
    // Upload and image after changing the node language.
    $images = $this->drupalGetTestFiles('image')[1];
    $edit = [
        'langcode[0][value]' => 'de',
        'files[field_image_field_0]' => $images->uri,
    ];
    $this->submitForm($edit, 'Upload');
    $this->submitForm([
        'field_image_field[0][alt]' => 'alternative_text',
    ], 'Save (this translation)');
    // Check that the translation languages are correct.
    $node = $this->getNodeByTitle('english_title');
    $translation_languages = $node->getTranslationLanguages();
    $this->assertArrayHasKey('fr', $translation_languages);
    $this->assertArrayHasKey('de', $translation_languages);
}

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