public function ParagraphsTranslationTest::testParagraphTranslationMultilingual in Paragraphs 8
Same name in this branch
- 8 tests/src/Functional/WidgetLegacy/ParagraphsTranslationTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsTranslationTest::testParagraphTranslationMultilingual()
- 8 tests/src/Functional/WidgetStable/ParagraphsTranslationTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTranslationTest::testParagraphTranslationMultilingual()
Tests the paragraph buttons presence in translation multilingual workflow.
This test covers the following test cases: 1) original node langcode in EN, translate in FR, change to DE. 2) original node langcode in DE, change site langcode to DE, change node langcode to EN.
File
- tests/
src/ Functional/ WidgetLegacy/ ParagraphsTranslationTest.php, line 437
Class
- ParagraphsTranslationTest
- Tests the configuration of paragraphs.
Namespace
Drupal\Tests\paragraphs\Functional\WidgetLegacyCode
public function testParagraphTranslationMultilingual() {
// Case 1: original node langcode in EN, translate in FR, change to DE.
// Add 'Images' paragraph and check the paragraphs buttons are displayed.
$this
->drupalGet('node/add/paragraphed_content_demo');
$this
->submitForm([], 'Add images');
$this
->assertParagraphsButtons(1);
// Upload an image and check the paragraphs buttons are still displayed.
$images = $this
->getTestFiles('image')[0];
$edit = [
'title[0][value]' => 'Title in english',
'files[field_paragraphs_demo_0_subform_field_images_demo_0][]' => $images->uri,
];
$this
->submitForm($edit, 'Upload');
$this
->assertParagraphsButtons(1);
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains('Title in english');
$node = $this
->drupalGetNodeByTitle('Title in english');
// Check the paragraph langcode is 'en'.
$this
->assertParagraphsLangcode($node
->id());
// Add french translation.
$this
->clickLink('Translate');
$this
->clickLink('Add', 1);
// Make sure the host entity and its paragraphs have valid source language
// and check that the paragraphs buttons are hidden.
$this
->assertNoParagraphsButtons(1);
$edit = [
'title[0][value]' => 'Title in french',
];
$this
->submitForm($edit, 'Save (this translation)');
$this
->assertParagraphsLangcode($node
->id(), 'en', 'fr');
$this
->assertSession()
->pageTextContains('paragraphed_content_demo Title in french has been updated.');
$this
->assertSession()
->pageTextContains('Title in french');
$this
->assertSession()
->pageTextNotContains('Title in english');
// Check the original node and the paragraph langcode is still 'en'.
$this
->assertParagraphsLangcode($node
->id());
// Edit the french translation and upload a new image.
$this
->clickLink('Edit');
$images = $this
->getTestFiles('image')[1];
$this
->submitForm([
'files[field_paragraphs_demo_0_subform_field_images_demo_1][]' => $images->uri,
], 'Upload');
// Check editing a translation does not affect the source langcode and
// check that the paragraphs buttons are still hidden.
$this
->assertParagraphsLangcode($node
->id(), 'en', 'fr');
$this
->assertNoParagraphsButtons(1);
$this
->submitForm([], 'Save (this translation)');
$this
->assertSession()
->pageTextContains('Title in french');
$this
->assertSession()
->pageTextNotContains('Title in english');
// Back to the original node.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Title in english');
$this
->assertSession()
->pageTextNotContains('Title in french');
// Check the original node and the paragraph langcode are still 'en' and
// check that the paragraphs buttons are still displayed.
$this
->clickLink('Edit');
$this
->assertParagraphsLangcode($node
->id());
$this
->assertParagraphsButtons(1);
// Change the node langcode to 'german', add a 'Nested Paragraph', check
// the paragraphs langcode are still 'en' and their buttons are displayed.
$edit = [
'title[0][value]' => 'Title in english (de)',
'langcode[0][value]' => 'de',
];
$this
->submitForm($edit, 'Add nested_paragraph');
$this
->assertParagraphsLangcode($node
->id());
$this
->assertParagraphsButtons(2);
// Add an 'Images' paragraph inside the nested one, check the paragraphs
// langcode are still 'en' and the paragraphs buttons are still displayed.
$this
->submitForm([], 'field_paragraphs_demo_1_subform_field_paragraphs_demo_images_add_more');
$this
->assertParagraphsLangcode($node
->id());
$this
->assertParagraphsButtons(2);
// Upload a new image, check the paragraphs langcode are still 'en' and the
// paragraphs buttons are displayed.
$images = $this
->getTestFiles('image')[2];
$this
->submitForm([
'files[field_paragraphs_demo_1_subform_field_paragraphs_demo_0_subform_field_images_demo_0][]' => $images->uri,
], 'Upload');
$this
->assertParagraphsLangcode($node
->id());
$this
->assertParagraphsButtons(2);
$this
->submitForm([], 'Save (this translation)');
$this
->assertSession()
->pageTextContains('Title in english (de)');
$this
->assertSession()
->pageTextNotContains('Title in french');
// Check the original node and the paragraphs langcode are now 'de'.
$this
->assertParagraphsLangcode($node
->id(), 'de');
// Check the french translation.
$this
->drupalGet('fr/node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Title in french');
$this
->assertSession()
->pageTextNotContains('Title in english (de)');
// Check editing a translation does not affect the source langcode and
// check that the paragraphs buttons are still hidden.
$this
->clickLink('Edit');
$this
->assertParagraphsLangcode($node
->id(), 'de', 'fr');
$this
->assertNoParagraphsButtons(2);
// Case 2: original node langcode in DE, change site langcode to DE, change
// node langcode to EN.
// Change the site langcode to french.
$this
->drupalGet('admin/config/regional/language');
$this
->submitForm([
'site_default_language' => 'fr',
], 'Save configuration');
// Check the original node and its paragraphs langcode are still 'de'
// and the paragraphs buttons are still displayed.
$this
->drupalGet('de/node/' . $node
->id() . '/edit');
$this
->assertParagraphsLangcode($node
->id(), 'de');
$this
->assertParagraphsButtons(2);
// Go to the french translation.
$this
->drupalGet('node/' . $node
->id() . '/translations');
$this
->clickLink('Edit', 1);
// Check editing a translation does not affect the source langcode and
// check that the paragraphs buttons are still hidden.
$this
->assertParagraphsLangcode($node
->id(), 'de', 'fr');
$this
->assertNoParagraphsButtons(2);
// Upload another image.
$images = $this
->getTestFiles('image')[3];
$this
->submitForm([
'files[field_paragraphs_demo_1_subform_field_paragraphs_demo_0_subform_field_images_demo_1][]' => $images->uri,
], 'Upload');
// Check editing a translation does not affect the source langcode and
// check that the paragraphs buttons are still hidden.
$this
->assertParagraphsLangcode($node
->id(), 'de', 'fr');
$this
->assertNoParagraphsButtons(2);
$this
->submitForm([], 'Save (this translation)');
// Check the paragraphs langcode are still 'de' after saving the translation.
$this
->assertParagraphsLangcode($node
->id(), 'de', 'fr');
$this
->assertSession()
->pageTextContains('Title in french');
$this
->assertSession()
->pageTextNotContains('Title in english (de)');
// Back to the original node.
$this
->drupalGet('de/node/' . $node
->id());
$this
->assertSession()
->pageTextContains('Title in english (de)');
$this
->assertSession()
->pageTextNotContains('Title in french');
// Check the original node and the paragraphs langcode are still 'de' and
// check that the paragraphs buttons are still displayed.
$this
->clickLink('Edit');
$this
->assertParagraphsLangcode($node
->id(), 'de');
$this
->assertParagraphsButtons(2);
// Change the node langcode back to 'english', add an 'Images' paragraph,
// check the paragraphs langcode are still 'de' and their buttons are shown.
$edit = [
'title[0][value]' => 'Title in english',
'langcode[0][value]' => 'en',
];
$this
->submitForm($edit, 'field_paragraphs_demo_images_add_more');
$this
->assertParagraphsLangcode($node
->id(), 'de');
$this
->assertParagraphsButtons(3);
// Upload a new image, check the paragraphs langcode are still 'de' and the
// paragraphs buttons are displayed.
$images = $this
->getTestFiles('image')[4];
$this
->submitForm([
'files[field_paragraphs_demo_2_subform_field_images_demo_0][]' => $images->uri,
], 'Upload');
$this
->assertParagraphsLangcode($node
->id(), 'de');
$this
->assertParagraphsButtons(3);
$this
->submitForm([], 'Save (this translation)');
$this
->assertSession()
->pageTextContains('paragraphed_content_demo Title in english has been updated.');
// Check the original node and the paragraphs langcode are now 'en'.
$this
->assertParagraphsLangcode($node
->id());
}