diff --git a/src/Tests/ParagraphsAccessTest.php b/src/Tests/ParagraphsAccessTest.php index 3a2a6d2..92ec242 100644 --- a/src/Tests/ParagraphsAccessTest.php +++ b/src/Tests/ParagraphsAccessTest.php @@ -7,6 +7,7 @@ use Drupal\field_ui\Tests\FieldUiTestTrait; use Drupal\simpletest\WebTestBase; use Drupal\user\RoleInterface; use Drupal\user\Entity\Role; +use Drupal\paragraphs\Entity\Paragraph; /** * Tests the access check of paragraphs. @@ -159,4 +160,62 @@ class ParagraphsAccessTest extends WebTestBase { $node = $this->getNodeByTitle('delete_permissions'); $this->assertUrl('node/' . $node->id()); } + + /** + * Test validation of closed paragraphs. + */ + public function testValidationClosedParagraphs() { + // Create a Paragraphs with an entity reference field. + + $admin_user = $this->drupalCreateUser(array( + 'administer node fields', + 'administer content types', + 'administer node fields', + 'administer node display', + 'administer paragraphs types', + 'administer paragraph fields', + 'administer paragraph display', + 'administer paragraph form display', + 'administer node form display', + 'create paragraphed_content_demo content', + 'edit any paragraphed_content_demo content', + )); + $this->drupalLogin($admin_user); + // Adding Entity Reference to Paragraph Content Type. + $this->drupalPostForm('admin/structure/types/manage/paragraphed_content_demo/fields/add-field', [ + 'new_storage_type' => 'field_ui:entity_reference:node', + 'label' => 'Content reference test', + 'field_name' => 'content', + ], t('Save and continue')); + + // Create a paragraph. + $paragraph_1 = Paragraph::create([ + 'title' => 'Paragraph1', + 'type' => 'text', + 'langcode' => 'en', + 'field_text_demo' => 'english_text_1', + ]); + $paragraph_1->save(); + + // Create second paragraph and add entity reference of created first paragraph. + $this->drupalGet('node/add/paragraphed_content_demo'); + $this->assertText('Content reference test'); + $paragraph_2 = Paragraph::create([ + 'title' => 'Paragraph1', + 'type' => 'text', + 'langcode' => 'en', + 'field_text_demo' => 'english_text_1', + 'field_test_reference[0][target_id]' => 'Paragraph1', + ]); + $paragraph_2->save(); + + // Change the form-display to closed. + $this->drupalGet('admin/structure/types/manage/article/form-display'); +// $edit = array('fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed'); +// $this->drupalPostForm(NULL, $edit, t('Save')); +// // Check if the setting is stored. +// $this->assertText('Edit mode: Closed', 'Checking the settings value.'); +// $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit"); + + } }