public function ParagraphsAsymmetricTranslationTest::testParagraphsMultilingualFieldTranslationNested in Paragraphs asymmetric translation widgets 8
Test paragraphs with nested multilingual fields.
File
- tests/
src/ Functional/ ParagraphsAsymmetricTranslationTest.php, line 366
Class
- ParagraphsAsymmetricTranslationTest
- Tests asymmetric translation of paragraphs.
Namespace
Drupal\Tests\paragraphs_asymmetric_translation_widgets\FunctionalCode
public function testParagraphsMultilingualFieldTranslationNested() {
// Set widget to assymetric one.
$this
->drupalGet('/admin/structure/types/manage/paragraphed_content_demo/form-display');
$this
->drupalPostForm(NULL, array(
'fields[field_paragraphs_demo][type]' => 'paragraphs_classic_asymmetric',
), t('Save'));
// 1. Translate node and create different paragraphs.
// Add an English node.
$this
->drupalGet('node/add/paragraphed_content_demo');
$this
->drupalPostForm(NULL, NULL, t('Add Nested Paragraph'), []);
$this
->drupalPostForm(NULL, NULL, 'field_paragraphs_demo_0_subform_field_paragraphs_demo_text_add_more');
$edit = [
'title[0][value]' => 'Title in english',
'field_paragraphs_demo[0][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'Text in english',
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
// Translate the node to French.
$node = $this
->drupalGetNodeByTitle('Title in english');
$this
->drupalGet('node/' . $node
->id() . '/translations/add/en/fr');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_edit');
$edit = [
'title[0][value]' => 'Title in french',
'field_paragraphs_demo[0][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'Text in french',
];
$this
->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// Check the english translation.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Title in english');
$this
->assertSession()
->pageTextContains('Text in english');
$this
->assertSession()
->responseNotContains('Title in french');
$this
->assertSession()
->responseNotContains('Text in french');
// Check the french translation.
$this
->drupalGet('fr/node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Title in french');
$this
->assertSession()
->pageTextContains('Text in french');
$this
->assertSession()
->responseNotContains('Title in english');
$this
->assertSession()
->responseNotContains('Text in english');
// 2. Update the paragraphs.
// Try to edit the paragraphs, to see if the correct translation gets
// updated. Start with the english.
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_edit');
$edit = [
'field_paragraphs_demo[0][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'The updated english text',
];
$this
->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// Check if only the english node had its paragraph text updated, and that
// there has been no mixing-up of the paragraph entities.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('The updated english text');
$this
->assertSession()
->responseNotContains('Text in english');
$this
->assertSession()
->responseNotContains('Text in french');
$this
->drupalGet('fr/node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Text in french');
$this
->assertSession()
->responseNotContains('Text in english');
$this
->assertSession()
->responseNotContains('The updated english text');
// 3. Add different number of paragraphs on one translation.
// Add one more paragraph on the english node.
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_edit');
$this
->drupalPostForm(NULL, NULL, 'field_paragraphs_demo_0_subform_field_paragraphs_demo_text_add_more');
$edit = [
'field_paragraphs_demo[0][subform][field_paragraphs_demo][1][subform][field_text_demo][0][value]' => 'New english text',
];
$this
->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// Confirm that the english node has the new paragraphs, and the french
// node is intact.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('The updated english text');
$this
->assertSession()
->pageTextContains('New english text');
$this
->assertSession()
->responseNotContains('Text in french');
$this
->drupalGet('fr/node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Text in french');
$this
->assertSession()
->responseNotContains('The updated english text');
$this
->assertSession()
->responseNotContains('New english text');
}