Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / paragraphs / src / Tests / Experimental / ParagraphsExperimentalConfigTest.php
index 6e994053f5c2f05e68e333049535dd6c473e8cdc..728136208d493b7c8a1ba0cdfca197904db87d13 100644 (file)
@@ -33,8 +33,8 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     ]);
 
     // Add a paragraphed content type.
-    $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field');
 
+    $this->addParagraphedContentType('paragraphed_test');
     $this->addParagraphsType('paragraph_type_test');
     $this->addParagraphsType('text');
 
@@ -47,20 +47,21 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     $edit = [
       'entity_types[node]' => TRUE,
       'settings[node][paragraphed_test][translatable]' => TRUE,
-      'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE,
+      'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
     ];
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
 
     // Create a node with a paragraph.
-    $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'paragraphs_field_paragraph_type_test_add_more');
-    $this->drupalPostForm(NULL, ['title[0][value]' => 'paragraphed_title'], t('Save and publish'));
+    $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_paragraph_type_test_add_more');
+    $edit = ['title[0][value]' => 'paragraphed_title'];
+    $this->drupalPostForm(NULL, $edit, t('Save'));
 
     // Attempt to add a translation.
     $node = $this->drupalGetNodeByTitle('paragraphed_title');
     $this->drupalGet('node/' . $node->id() . '/translations');
     $this->clickLink(t('Add'));
     // Save the translation.
-    $this->drupalPostForm(NULL, [], t('Save and keep published (this translation)'));
+    $this->drupalPostForm(NULL, [], t('Save (this translation)'));
     $this->assertText('paragraphed_test paragraphed_title has been updated.');
   }
 
@@ -79,7 +80,7 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     $this->drupalGet('admin/config/regional/content-language');
     $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
 
-    $this->addParagraphedContentType('paragraphed_test', 'paragraphs_field');
+    $this->addParagraphedContentType('paragraphed_test');
     // Check error message is not displayed.
     $this->drupalGet('admin/config/regional/content-language');
     $this->assertText('(* unsupported) Paragraphs fields do not support translation.');
@@ -92,7 +93,7 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     $edit = [
       'entity_types[node]' => TRUE,
       'settings[node][paragraphed_test][translatable]' => TRUE,
-      'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE,
+      'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
     ];
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
 
@@ -102,19 +103,19 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     $this->assertNoRaw('<div class="messages messages--error');
 
     // Check content type field management warning.
-    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field');
+    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
     $this->assertText('Paragraphs fields do not support translation.');
 
     // Make the paragraphs field translatable.
     $edit = [
       'entity_types[node]' => TRUE,
       'settings[node][paragraphed_test][translatable]' => TRUE,
-      'settings[node][paragraphed_test][fields][paragraphs_field]' => TRUE,
+      'settings[node][paragraphed_test][fields][field_paragraphs]' => TRUE,
     ];
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
 
     // Check content type field management error.
-    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field');
+    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
     $this->assertText('Paragraphs fields do not support translation.');
     $this->assertRaw('<div class="messages messages--error');
 
@@ -122,8 +123,8 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
     $edit = [
       'new_storage_type' => 'field_ui:entity_reference:node',
-      'label' => 'new_no_paragraphs_field',
-      'field_name' => 'new_no_paragraphs_field',
+      'label' => 'new_no_field_paragraphs',
+      'field_name' => 'new_no_field_paragraphs',
     ];
     $this->drupalPostForm(NULL, $edit, t('Save and continue'));
     $this->drupalPostForm(NULL, [], t('Save field settings'));
@@ -158,4 +159,94 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase {
     $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs');
   }
 
+  /**
+   * Test included Paragraph types.
+   */
+  public function testIncludedParagraphTypes() {
+    $this->loginAsAdmin();
+    // Add a Paragraph content type and 2 Paragraphs types.
+    $this->addParagraphedContentType('paragraphed_test', 'paragraphs');
+    $this->addParagraphsType('paragraph_type_test');
+    $this->addParagraphsType('text');
+
+    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
+    $edit = [
+      'settings[handler_settings][negate]' => 0,
+      'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
+    ];
+    $this->drupalPostForm(NULL, $edit, 'Save settings');
+    $this->assertText('Saved paragraphs configuration.');
+
+    $this->drupalGet('node/add/paragraphed_test');
+    $this->assertText('Add paragraph_type_test');
+    $this->assertNoText('Add text');
+    $edit = [
+      'title[0][value]' => 'Testing included types'
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save'));
+    $this->assertText('paragraphed_test Testing included types has been created.');
+
+    // Include all types.
+    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
+    $edit = [
+      'settings[handler_settings][negate]' => 0,
+      'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
+      'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
+    ];
+    $this->drupalPostForm(NULL, $edit, 'Save settings');
+    $this->drupalGet('node/add/paragraphed_test');
+    $button_paragraphed_type_test = $this->xpath('//input[@id=:id]', [':id' => 'paragraphs-paragraph-type-test-add-more']);
+    $button_text = $this->xpath('//input[@id=:id]', [':id' => 'paragraphs-text-add-more']);
+    $this->assertNotNull($button_paragraphed_type_test);
+    $this->assertNotNull($button_text);
+    $edit = [
+      'title[0][value]' => 'Testing all excluded types'
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save'));
+    $this->assertText('paragraphed_test Testing all excluded types has been created.');
+  }
+
+  /**
+   * Test excluded Paragraph types.
+   */
+  public function testExcludedParagraphTypes() {
+    $this->loginAsAdmin();
+    // Add a Paragraph content type and 2 Paragraphs types.
+    $this->addParagraphedContentType('paragraphed_test', 'paragraphs');
+    $this->addParagraphsType('paragraph_type_test');
+    $this->addParagraphsType('text');
+
+    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
+    $edit = [
+      'settings[handler_settings][negate]' => 1,
+      'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
+    ];
+    $this->drupalPostForm(NULL, $edit, 'Save settings');
+    $this->assertText('Saved paragraphs configuration.');
+
+    $this->drupalGet('node/add/paragraphed_test');
+    $this->assertText('Add paragraph_type_test');
+    $this->assertNoText('Add text');
+    $edit = [
+      'title[0][value]' => 'Testing excluded types'
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save'));
+    $this->assertText('paragraphed_test Testing excluded types has been created.');
+
+    // Exclude all types.
+    $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
+    $edit = [
+      'settings[handler_settings][negate]' => 1,
+      'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
+      'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
+    ];
+    $this->drupalPostForm(NULL, $edit, 'Save settings');
+    $this->drupalGet('node/add/paragraphed_test');
+    $this->assertText('You are not allowed to add any of the Paragraph types.');
+    $edit = [
+      'title[0][value]' => 'Testing all excluded types'
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save'));
+    $this->assertText('paragraphed_test Testing all excluded types has been created.');
+  }
 }