X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FClassic%2FParagraphsTranslationTest.php;fp=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FClassic%2FParagraphsTranslationTest.php;h=efb2cc6b645be66af21adfacf9c15cc16509451e;hp=68e957078acbd249b5a7a74da56081869c6dcb1b;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTranslationTest.php b/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTranslationTest.php index 68e957078..efb2cc6b6 100644 --- a/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTranslationTest.php +++ b/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsTranslationTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Language\LanguageInterface; use Drupal\paragraphs\Entity\Paragraph; use Drupal\node\Entity\Node; +use Drupal\user\Entity\Role; /** * Tests the configuration of paragraphs. @@ -54,12 +55,31 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'settings[paragraph][images][fields][field_images_demo]' => TRUE, ]; $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); + + // Set the form display to classic. + EntityFormDisplay::load('node.paragraphed_content_demo.default') + ->setComponent('field_paragraphs_demo', ['type' => 'entity_reference_paragraphs']) + ->save(); + EntityFormDisplay::load('paragraph.nested_paragraph.default') + ->setComponent('field_paragraphs_demo', ['type' => 'entity_reference_paragraphs']) + ->save(); + + if (version_compare(\Drupal::VERSION, '8.4', '>=')) { + // @todo Workaround for file usage/unable to save the node with no usages. + // Remove when https://www.drupal.org/node/2801777 is fixed. + \Drupal::configFactory()->getEditable('file.settings') + ->set('make_unused_managed_files_temporary', TRUE) + ->save(); + } } /** * Tests the paragraph translation. */ public function testParagraphTranslation() { + // We need to add a permission to administer roles to deal with revisions. + $roles = $this->loggedInUser->getRoles(); + $this->grantPermissions(Role::load(array_shift($roles)), ['administer nodes']); $this->drupalGet('admin/config/regional/content-language'); // Check the settings are saved correctly. @@ -69,11 +89,6 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { $this->assertFieldChecked('edit-settings-paragraph-images-columns-field-images-demo-alt'); $this->assertFieldChecked('edit-settings-paragraph-images-columns-field-images-demo-title'); - // Set the form display to classic. - $form_display = EntityFormDisplay::load('node.paragraphed_content_demo.default') - ->setComponent('field_paragraphs_demo', ['type' => 'entity_reference_paragraphs']); - $form_display->save(); - // Check if the publish/unpublish option works. $this->drupalGet('admin/structure/paragraphs_type/text_image/form-display'); $edit = array( @@ -89,7 +104,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'title[0][value]' => 'example_publish_unpublish', 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'Example published and unpublished', ]; - $this->drupalPostForm(NULL, $edit, t('Save and publish')); + $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertText(t('Example published and unpublished')); $this->clickLink(t('Edit')); @@ -99,7 +114,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'field_paragraphs_demo[0][subform][status][value]' => FALSE, 'field_paragraphs_demo[1][subform][field_paragraphs_demo][0][subform][field_text_demo][0][value]' => 'Dummy text' ]; - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit + ['status[value]' => FALSE], t('Save')); $this->assertNoText(t('Example published and unpublished')); // Check the parent fields are set properly. Get the node. @@ -130,7 +145,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ); // The button to remove a paragraph is present. $this->assertRaw(t('Remove')); - $this->drupalPostForm(NULL, $edit, t('Save and publish')); + $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle('Title in english'); // The text is present when editing again. $this->clickLink(t('Edit')); @@ -152,7 +167,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'revision' => TRUE, 'revision_log[0][value]' => 'french 1', ); - $this->drupalPostForm(NULL, $edit, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $this->assertText('Paragraphed article Title in french has been updated.'); // Check the english translation. @@ -177,7 +192,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'revision' => TRUE, 'revision_log[0][value]' => 'french 2', ); - $this->drupalPostForm(NULL, $edit, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $this->assertText('Title Change in french'); $this->assertText('New text in french'); @@ -187,7 +202,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { $this->assertText('Title in english'); $this->assertText('Text in english'); // Save the original content on second request. - $this->drupalPostForm(NULL, NULL, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); $this->assertText('Paragraphed article Title in english has been updated.'); // Test if reverting to old paragraphs revisions works, make sure that @@ -198,7 +213,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { $this->clickLink(t('Edit')); $this->assertRaw('Title in french'); $this->assertText('Text in french'); - $this->drupalPostForm(NULL, [], t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, [], t('Save (this translation)')); $this->assertNoRaw('The content has either been modified by another user, or you have already submitted modifications'); $this->assertText('Text in french'); @@ -232,7 +247,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'field_paragraphs_demo[0][subform][field_images_demo][0][width]' => 100, 'field_paragraphs_demo[0][subform][field_images_demo][0][height]' => 100, ]; - $this->drupalPostForm(NULL, $edit, t('Save and publish')); + $this->drupalPostForm(NULL, $edit, t('Save')); // Translate the node with the image paragraph. $this->clickLink('Translate'); @@ -242,7 +257,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'field_paragraphs_demo[0][subform][field_images_demo][0][alt]' => 'Image alt FR', 'field_paragraphs_demo[0][subform][field_images_demo][0][title]' => 'Image title FR', ]; - $this->drupalPostForm(NULL, $edit, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $this->assertRaw('Title FR'); $this->drupalGet('node/add/paragraphed_content_demo'); @@ -252,7 +267,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'title[0][value]' => 'titulo', 'langcode[0][value]' => 'de', ]; - $this->drupalPostForm(NULL, $edit, t('Save and publish')); + $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle('titulo'); $this->assertParagraphsLangcode($node->id(), 'de'); @@ -285,7 +300,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'field_paragraphs_demo' => [$paragraph_1, $translated_paragraph], ]); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->drupalPostForm(NULL, [], t('Save and keep published')); + $this->drupalPostForm(NULL, [], t('Save')); $this->assertText('Paragraphed article ' . $node->label() . ' has been updated.'); // Check that first paragraph langcode has been updated. $paragraph = Paragraph::load($paragraph_1->id()); @@ -302,7 +317,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'field_paragraphs_demo[0][subform][field_text_demo][0][value]' => 'english_translation_1', 'field_paragraphs_demo[1][subform][field_text_demo][0][value]' => 'english_translation_2', ]; - $this->drupalPostForm('node/' . $node->id() . '/translations/add/de/en', $edit, t('Save and keep published (this translation)')); + $this->drupalPostForm('node/' . $node->id() . '/translations/add/de/en', $edit, t('Save (this translation)')); // Attempt to create a french translation. $this->drupalGet('node/' . $node->id() . '/translations/add/de/fr'); // Check that the german translation of the paragraphs is displayed. @@ -316,7 +331,8 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { // Create a node with empty Paragraphs. $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, [], t('Add Nested Paragraph')); - $this->drupalPostForm(NULL, ['title[0][value]' => 'empty_node'], t('Save and publish')); + $edit = ['title[0][value]' => 'empty_node']; + $this->drupalPostForm(NULL, $edit, t('Save')); // Attempt to translate it. $this->clickLink(t('Translate')); $this->clickLink(t('Add')); @@ -386,11 +402,6 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { public function testParagraphTranslationMultilingual() { // Case 1: original node langcode in EN, translate in FR, change to DE. - // Set the form display to classic. - $form_display = EntityFormDisplay::load('node.paragraphed_content_demo.default') - ->setComponent('field_paragraphs_demo', ['type' => 'entity_reference_paragraphs']); - $form_display->save(); - // Add 'Images' paragraph and check the paragraphs buttons are displayed. $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add Images')); @@ -403,7 +414,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ]; $this->drupalPostForm(NULL, $edit, t('Upload')); $this->assertParagraphsButtons(1); - $this->drupalPostForm(NULL, NULL, t('Save and publish')); + $this->drupalPostForm(NULL, NULL, t('Save')); $this->assertText('Title in english'); $node = $this->drupalGetNodeByTitle('Title in english'); // Check the paragraph langcode is 'en'. @@ -418,7 +429,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { $edit = [ 'title[0][value]' => 'Title in french', ]; - $this->drupalPostForm(NULL, $edit, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $this->assertParagraphsLangcode($node->id(), 'en', 'fr'); $this->assertText('Paragraphed article Title in french has been updated.'); $this->assertText('Title in french'); @@ -436,7 +447,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { // check that the paragraphs buttons are still hidden. $this->assertParagraphsLangcode($node->id(), 'en', 'fr'); $this->assertNoParagraphsButtons(1); - $this->drupalPostForm(NULL, NULL, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); $this->assertText('Title in french'); $this->assertNoText('Title in english'); @@ -471,7 +482,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ], t('Upload')); $this->assertParagraphsLangcode($node->id()); $this->assertParagraphsButtons(2); - $this->drupalPostForm(NULL, NULL, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); $this->assertText('Title in english (de)'); $this->assertNoText('Title in french'); // Check the original node and the paragraphs langcode are now 'de'. @@ -517,7 +528,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { // check that the paragraphs buttons are still hidden. $this->assertParagraphsLangcode($node->id(), 'de', 'fr'); $this->assertNoParagraphsButtons(2); - $this->drupalPostForm(NULL, NULL, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); // Check the paragraphs langcode are still 'de' after saving the translation. $this->assertParagraphsLangcode($node->id(), 'de', 'fr'); $this->assertText('Title in french'); @@ -549,7 +560,8 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ], t('Upload')); $this->assertParagraphsLangcode($node->id(), 'de'); $this->assertParagraphsButtons(3); - $this->drupalPostForm(NULL, NULL, t('Save and keep published (this translation)')); + $this->drupalPostForm(NULL, NULL, t('Save (this translation)')); + $this->assertText('Paragraphed article Title in english has been updated.'); // Check the original node and the paragraphs langcode are now 'en'. $this->assertParagraphsLangcode($node->id()); } @@ -567,11 +579,6 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { // Case 1: Check the paragraphs buttons after changing the NODE language // (original node langcode in GERMAN, default site langcode in english). - // Set the form display to classic. - $form_display = EntityFormDisplay::load('node.paragraphed_content_demo.default') - ->setComponent('field_paragraphs_demo', ['type' => 'entity_reference_paragraphs']); - $form_display->save(); - // Create a node and check that the node langcode is 'english'. $this->drupalGet('node/add/paragraphed_content_demo'); $this->assertOptionSelected('edit-langcode-0-value', 'en'); @@ -591,7 +598,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'files[field_paragraphs_demo_0_subform_field_paragraphs_demo_0_subform_field_images_demo_0][]' => $images->uri, ], t('Upload')); $this->assertParagraphsButtons(1); - $this->drupalPostForm(NULL, NULL, t('Save and publish')); + $this->drupalPostForm(NULL, NULL, t('Save')); $this->assertText('Title in german'); $node1 = $this->getNodeByTitle('Title in german'); @@ -612,7 +619,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { // Check the paragraph langcode is still 'de' and its buttons are shown. $this->assertParagraphsLangcode($node1->id(), 'de'); $this->assertParagraphsButtons(1); - $this->drupalPostForm(NULL, NULL, t('Save and keep published')); + $this->drupalPostForm(NULL, NULL, t('Save')); // Check the paragraph langcode is now 'en' after saving. $this->assertParagraphsLangcode($node1->id()); @@ -641,7 +648,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ]; $this->drupalPostForm(NULL, $edit, t('Upload')); $this->assertParagraphsButtons(1); - $this->drupalPostForm(NULL, NULL, t('Save and publish')); + $this->drupalPostForm(NULL, NULL, t('Save')); $this->assertText('Title in english'); $node2 = $this->drupalGetNodeByTitle('Title in english'); @@ -668,7 +675,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ], t('Upload')); $this->assertParagraphsLangcode($node2->id()); $this->assertParagraphsButtons(2); - $this->drupalPostForm(NULL, NULL, t('Save and keep published')); + $this->drupalPostForm(NULL, NULL, t('Save')); // Check the paragraphs langcode are now 'de' after saving. $this->assertParagraphsLangcode($node2->id(), 'de'); @@ -678,7 +685,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { 'title[0][value]' => 'Title in english', 'langcode[0][value]' => 'en', ]; - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); // Check the paragraphs langcode are now 'en' after saving. $this->assertParagraphsLangcode($node2->id()); @@ -708,7 +715,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ], t('Upload')); $this->assertParagraphsLangcode($node2->id()); $this->assertParagraphsButtons(3); - $this->drupalPostForm(NULL, NULL, t('Save and keep published')); + $this->drupalPostForm(NULL, NULL, t('Save')); // Check the paragraphs langcode are still 'en' after saving. $this->assertParagraphsLangcode($node2->id()); @@ -733,7 +740,7 @@ class ParagraphsTranslationTest extends ParagraphsTestBase { ], t('Upload')); $this->assertParagraphsLangcode($node2->id()); $this->assertParagraphsButtons(4); - $this->drupalPostForm(NULL, NULL, t('Save and keep published')); + $this->drupalPostForm(NULL, NULL, t('Save')); // Check the paragraphs langcode are now 'de' after saving. $this->assertParagraphsLangcode($node2->id(), 'de'); }