public function ParagraphsAsymmetricTranslationTest::testParagraphsMultilingualFieldDeleteTranslation in Paragraphs asymmetric translation widgets 8
Test paragraph multilingual field deletes.
File
- tests/
src/ Functional/ ParagraphsAsymmetricTranslationTest.php, line 463
Class
- ParagraphsAsymmetricTranslationTest
- Tests asymmetric translation of paragraphs.
Namespace
Drupal\Tests\paragraphs_asymmetric_translation_widgets\FunctionalCode
public function testParagraphsMultilingualFieldDeleteTranslation() {
// 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. Delete the translation
// and check if the original is intact.
// 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');
// Now delete the french translation.
$this
->drupalGet('fr/node/' . $node
->id() . '/delete');
$this
->drupalPostForm(NULL, NULL, t('Delete French 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');
}