public function ContentTranslationLanguageChangeTest::testLanguageChange in Drupal 8
Same name and namespace in other branches
- 9 core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationLanguageChangeTest::testLanguageChange()
Test that the source language is properly set when changing.
File
- core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationLanguageChangeTest.php, line 88
Class
- ContentTranslationLanguageChangeTest
- Tests the content translation language that is set.
Namespace
Drupal\Tests\content_translation\FunctionalCode
public function testLanguageChange() {
// Create a node in English.
$this
->drupalGet('node/add/article');
$edit = [
'title[0][value]' => 'english_title',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
// Create a translation in French.
$this
->clickLink('Translate');
$this
->clickLink('Add');
$this
->drupalPostForm(NULL, [], t('Save (this translation)'));
$this
->clickLink('Translate');
// Edit English translation.
$this
->clickLink('Edit');
// 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
->drupalPostForm(NULL, $edit, t('Upload'));
$this
->drupalPostForm(NULL, [
'field_image_field[0][alt]' => 'alternative_text',
], t('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);
}