You are here

public function ContentTranslationLanguageChangeTest::testTitleDoesNotChangesOnChangingLanguageWidgetAndTriggeringAjaxCall in Drupal 8

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

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

File

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

Class

ContentTranslationLanguageChangeTest
Tests the content translation language that is set.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function testTitleDoesNotChangesOnChangingLanguageWidgetAndTriggeringAjaxCall() {

  // 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
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertEqual('node created', \Drupal::state()
    ->get('test_field_only_en_fr'));

  // Create a translation in French.
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('Add');
  $this
    ->drupalPostForm(NULL, [], t('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
    ->assertRaw('<title>Edit Article english_title | Drupal</title>');

  // 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'));

  // Test the expected title after triggering an ajax call with a new
  // language selected.
  $this
    ->assertRaw('<title>Edit Article english_title | Drupal</title>');
  $edit = [
    'langcode[0][value]' => 'en',
    'field_image_field[0][alt]' => 'alternative_text',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 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
    ->assertArrayNotHasKey('de', $translation_languages);
}