Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Experimental / ParagraphsExperimentalTranslationTest.php
index d1644ef41e556da5f4f3410263ca10f707ca358d..63710a4a2615a5c3c81c0c934c8f281aa8fedd1a 100644 (file)
@@ -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.
@@ -47,12 +48,23 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       'settings[paragraph][images][fields][field_images_demo]' => TRUE,
     ];
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
+
+    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.
@@ -88,7 +100,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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'));
 
@@ -98,7 +110,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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, t('Save'));
     $this->assertNoText(t('Example published and unpublished'));
 
     // Check the parent fields are set properly. Get the node.
@@ -129,7 +141,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     );
     // 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'));
@@ -151,7 +163,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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.
@@ -176,7 +188,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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');
 
@@ -186,7 +198,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     $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
@@ -197,7 +209,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     $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');
 
@@ -231,7 +243,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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');
@@ -241,7 +253,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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');
@@ -251,7 +263,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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');
 
@@ -284,7 +296,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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());
@@ -301,7 +313,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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.
@@ -315,7 +327,8 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     // 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'));
@@ -409,7 +422,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ];
     $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'.
@@ -424,7 +437,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     $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');
@@ -442,7 +455,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     // 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');
 
@@ -477,7 +490,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ], 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'.
@@ -523,7 +536,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     // 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');
@@ -555,7 +568,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ], 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)'));
     // Check the original node and the paragraphs langcode are now 'en'.
     $this->assertParagraphsLangcode($node->id());
   }
@@ -603,7 +616,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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');
 
@@ -624,7 +637,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     // 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());
 
@@ -653,7 +666,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ];
     $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');
 
@@ -680,7 +693,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ], 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');
 
@@ -690,7 +703,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
       '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());
 
@@ -720,7 +733,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ], 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());
 
@@ -745,7 +758,7 @@ class ParagraphsExperimentalTranslationTest extends ParagraphsExperimentalTestBa
     ], 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');
   }