You are here

public function MultilingualBehaviorTest::testMoveTranslatedNestedParagraphToLibrary in Paragraphs 8

Tests converting translated nested paragraph into library.

File

modules/paragraphs_library/tests/src/Functional/MultilingualBehaviorTest.php, line 140

Class

MultilingualBehaviorTest
Tests paragraphs library multilingual functionality.

Namespace

Drupal\Tests\paragraphs_library\Functional

Code

public function testMoveTranslatedNestedParagraphToLibrary() {
  $this
    ->enableConvertingParagraphsTypeToLibrary('nested_paragraph');

  // Add node with text paragraph.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'field_paragraphs_nested_paragraph_add_more');
  $this
    ->submitForm([], 'field_paragraphs_0_subform_field_err_field_test_content_add_more');
  $edit = [
    'title[0][value]' => 'En label Test node nested',
    'field_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');

  // Add translation for node.
  $node = $this
    ->drupalGetNodeByTitle('En label Test node nested');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/translations');
  $this
    ->clickLink('Add');
  $edit = [
    'title[0][value]' => 'Testknoten',
    'field_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 (this translation)');

  // Convert translated paragraph to library.
  $this
    ->drupalGet($node
    ->toUrl('edit-form'));
  $this
    ->submitForm([], 'field_paragraphs_0_promote_to_library');
  $this
    ->submitForm([], 'Save (this translation)');

  // Check translation.
  $this
    ->drupalGet($node
    ->toUrl());
  $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.');

  // Check library item after converting translated paragraph.
  $this
    ->drupalGet('de/admin/content/paragraphs/1');
  $this
    ->assertSession()
    ->pageTextContains('De label Beispieltext fur den Test in geschachteltem Absatz.');
}