public function MultilingualBehaviorTest::testReuseTranslationForNestedParagraphFromLibrary

Tests reusing translated nested paragraph from library.

File

paragraphs/modules/paragraphs_library/tests/src/Functional/MultilingualBehaviorTest.php, line 81

Class

MultilingualBehaviorTest
Tests paragraphs library multilingual functionality.

Namespace

Drupal\Tests\paragraphs_library\Functional

Code

public function testReuseTranslationForNestedParagraphFromLibrary() {

  // Add nested paragraph directly in library.
  $this
    ->drupalGet('admin/content/paragraphs/add/default');
  $this
    ->submitForm([], 'paragraphs_nested_paragraph_add_more');
  $this
    ->submitForm([], 'paragraphs_0_subform_field_err_field_test_content_add_more');
  $edit = [
    'label[0][value]' => 'En label Test nested paragraph',
    'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'En label Example text for test in nested paragraph.',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Paragraph En label Test nested paragraph has been created.');

  // Translate nested paragraphs library item.
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('Add');
  $edit = [
    'label[0][value]' => 'De label Test geschachtelten Absatz',
    'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'De label Beispieltext fur den Test in geschachteltem Absatz.',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Create test content.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'field_paragraphs_from_library_add_more');
  $edit = [
    'title[0][value]' => 'En label Test node nested',
    'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 'En label Test nested paragraph',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Add translation for test node.
  $node = $this
    ->drupalGetNodeByTitle('En label Test node nested');
  $edit = [
    'title[0][value]' => 'De label Test geschachtelten Absatz',
  ];
  $this
    ->drupalGet('de/node/' . $node
    ->id() . '/translations/add/en/de');
  $this
    ->submitForm($edit, 'Save (this translation)');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('En label Example text for test in nested paragraph.');
  $this
    ->drupalGet('de/node/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.');

  // Update translation of library item.
  $edit = [
    'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'De label Beispieltext fur den Test geander.',
  ];
  $this
    ->drupalGet('de/admin/content/paragraphs/1/edit');
  $this
    ->submitForm($edit, 'Save');

  // Check updated content.
  $this
    ->drupalGet('de/node/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('De label Beispieltext fur den Test geander.');
}