createContentType(['type' => 'testnodetype']); // Create Admin. $this->adminUser = $this->drupalCreateUser(array_keys($this->container->get('user.permissions')->getPermissions())); $role = $this->adminUser->getRoles()[1]; $this->drupalLogin($this->adminUser); $this->drupalPlaceBlock('system_menu_block:account', ['region' => 'content']); // Create workflow. $this->drupalGet('admin/config/workflow/workflows/add'); $edit = [ 'label' => 'Workflow1', 'id' => 'workflow1', 'workflow_type' => 'content_moderation', ]; $this->submitForm($edit, 'Save'); $this->drupalGet('admin/config/workflow/workflows/manage/workflow1/type/node'); $edit = [ 'bundles[testnodetype]' => TRUE, ]; $this->submitForm($edit, 'Save'); $this->drupalGet('admin/people/permissions/' . $role); $edit = [ $role . '[use workflow1 transition create_new_draft]' => TRUE, $role . '[use workflow1 transition publish]' => TRUE, ]; $this->submitForm($edit, 'Save'); // Create child paragraph type. $this->drupalGet('admin/structure/paragraphs_type/add'); $edit = [ 'label' => 'ParagraphChild', 'id' => 'paragraphchild', ]; $this->submitForm($edit, 'Save and manage fields'); $this->drupalGet('admin/structure/paragraphs_type/paragraphchild/fields/add-field'); $edit = [ 'label' => 'TextA', 'field_name' => 'texta', 'new_storage_type' => 'plain_text', ]; $this->submitForm($edit, 'Continue'); $edit = [ 'label' => 'TextA', 'field_name' => 'texta', 'new_storage_type' => 'plain_text', 'group_field_options_wrapper' => 'string', ]; $this->submitForm($edit, 'Continue'); $this->submitForm([], 'Save'); // Create parent paragraph type. $this->drupalGet('admin/structure/paragraphs_type/add'); $edit = [ 'label' => 'ParagraphParent', 'id' => 'paragraphparent', ]; $this->submitForm($edit, 'Save and manage fields'); $this->drupalGet('admin/structure/paragraphs_type/paragraphparent/fields/add-field'); $edit = [ 'label' => 'Paragraph1', 'field_name' => 'paragraph1', 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph', ]; $this->submitForm($edit, 'Continue'); $edit = [ 'settings[handler_settings][target_bundles_drag_drop][paragraphchild][enabled]' => TRUE, 'settings[handler_settings][target_bundles_drag_drop][paragraphparent][enabled]' => TRUE, ]; $this->submitForm($edit, 'Save settings'); // Add paragraph field to node type. $this->drupalGet('admin/structure/types/manage/testnodetype/fields/add-field'); $edit = [ 'label' => 'Paragraph2', 'field_name' => 'paragraph2', 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph', ]; $this->submitForm($edit, 'Continue'); $edit = [ 'settings[handler_settings][target_bundles_drag_drop][paragraphparent][enabled]' => TRUE, ]; $this->submitForm($edit, 'Save settings'); $this->drupalGet('admin/structure/types/manage/testnodetype/display'); } /** * Tests content moderation with nested paragraphs. */ public function testNestedParagraphsDraft() { // Create Node. $node1 = $this->drupalCreateNode([ 'title' => 'Hello, world!', 'type' => 'testnodetype', ]); $this->drupalGet('/node/' . $node1->id() . '/edit'); $this->submitForm([], 'Add ParagraphParent'); $this->submitForm([], 'Add ParagraphChild'); $this->submitForm([], 'Add ParagraphParent'); $this->submitForm([], 'Add ParagraphChild'); $this->submitForm([], 'Add ParagraphParent'); $this->submitForm([], 'Add ParagraphChild'); $edit = [ 'title[0][value]' => 'TitleOriginal', 'body[0][value]' => 'TestBodyOriginal', 'field_paragraph2[0][subform][field_paragraph1][0][subform][field_texta][0][value]' => 'TestChildOriginal', 'field_paragraph2[0][subform][field_paragraph1][1][subform][field_paragraph1][0][subform][field_texta][0][value]' => 'TestChildChildOriginal', 'field_paragraph2[0][subform][field_paragraph1][1][subform][field_paragraph1][1][subform][field_paragraph1][0][subform][field_texta][0][value]' => 'TestChildChildChildOriginal', ]; $this->submitForm($edit, 'Save'); // Test original. $this->drupalGet('/node/' . $node1->id()); $this->assertSession()->pageTextContains('TitleOriginal'); $this->assertSession()->pageTextContains('TestBodyOriginal'); $this->assertSession()->pageTextContains('TestChildOriginal'); $this->assertSession()->pageTextContains('TestChildChildOriginal'); $this->assertSession()->pageTextContains('TestChildChildChildOriginal'); // Change Node and save as draft. $this->drupalGet('/node/' . $node1->id() . '/edit'); $edit = [ 'moderation_state[0][state]' => 'draft', 'title[0][value]' => 'TitleChanged', 'body[0][value]' => 'TestBodyChanged', 'field_paragraph2[0][subform][field_paragraph1][0][subform][field_texta][0][value]' => 'TestChildChanged', 'field_paragraph2[0][subform][field_paragraph1][1][subform][field_paragraph1][0][subform][field_texta][0][value]' => 'TestChildChildChanged', 'field_paragraph2[0][subform][field_paragraph1][1][subform][field_paragraph1][1][subform][field_paragraph1][0][subform][field_texta][0][value]' => 'TestChildChildChildChanged', ]; $this->submitForm($edit, 'Save'); // Test latest, should be changed. $this->assertSession()->pageTextContains('TitleChanged'); $this->assertSession()->pageTextContains('TestBodyChanged'); $this->assertSession()->pageTextContains('TestChildChanged'); $this->assertSession()->pageTextContains('TestChildChildChanged'); $this->assertSession()->pageTextContains('TestChildChildChildChanged'); // Test changed with admin, should be original. $this->drupalGet('/node/' . $node1->id()); $this->assertSession()->pageTextContains('TitleOriginal'); $this->assertSession()->pageTextContains('TestBodyOriginal'); $this->assertSession()->pageTextContains('TestChildOriginal'); $this->assertSession()->pageTextContains('TestChildChildOriginal'); $this->assertSession()->pageTextContains('TestChildChildChildOriginal'); $this->drupalGet('/user/logout'); // Test changed with anonymous, should be original. $this->drupalGet('/node/' . $node1->id()); $this->assertSession()->pageTextContains('TitleOriginal'); $this->assertSession()->pageTextContains('TestBodyOriginal'); $this->assertSession()->pageTextContains('TestChildOriginal'); $this->assertSession()->pageTextContains('TestChildChildOriginal'); $this->assertSession()->pageTextContains('TestChildChildChildOriginal'); } }