function ContentTranslationLanguageChangeTest::testTitleDoesNotChangesOnChangingLanguageWidgetAndTriggeringAjaxCall

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

Tests that title does not change on ajax call with new language value.

File

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

Class

ContentTranslationLanguageChangeTest
Tests the content translation language that is set.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function testTitleDoesNotChangesOnChangingLanguageWidgetAndTriggeringAjaxCall() : void {
    // Create a node in English.
    $this->drupalGet('node/add/article', [
        'query' => [
            'test_field_only_en_fr' => 1,
        ],
    ]);
    $edit = [
        'title[0][value]' => 'english_title',
        'test_field_only_en_fr' => 'node created',
    ];
    $this->submitForm($edit, 'Save');
    $this->assertEquals('node created', \Drupal::state()->get('test_field_only_en_fr'));
    // Create a translation in French.
    $this->clickLink('Translate');
    $this->clickLink('Add');
    $this->submitForm([], 'Save (this translation)');
    $this->clickLink('Translate');
    // Edit English translation.
    $node = $this->getNodeByTitle('english_title');
    $this->drupalGet('node/' . $node->id() . '/edit');
    // Test the expected title when loading the form.
    $this->assertSession()
        ->titleEquals('Edit Article english_title | Drupal');
    // 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');
    // Test the expected title after triggering an ajax call with a new
    // language selected.
    $this->assertSession()
        ->titleEquals('Edit Article english_title | Drupal');
    $edit = [
        'langcode[0][value]' => 'en',
        'field_image_field[0][alt]' => 'alternative_text',
    ];
    $this->submitForm($edit, '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->assertArrayNotHasKey('de', $translation_languages);
}

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