You are here

public function MultilingualBehaviorTest::testDetachBeforeTranslation in Paragraphs 8

Tests detach paragraph before adding a translation for the node.

File

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

Class

MultilingualBehaviorTest
Tests paragraphs library multilingual functionality.

Namespace

Drupal\Tests\paragraphs_library\Functional

Code

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

  // Add 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.',
  ];
  $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, 'field_paragraphs_0_unlink_from_library');
  $edit = [
    'title[0][value]' => 'En label Test node nested',
  ];
  $this
    ->submitForm($edit, 'Save');

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