X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FExperimental%2FParagraphsExperimentalDuplicateFeatureTest.php;fp=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FExperimental%2FParagraphsExperimentalDuplicateFeatureTest.php;h=278e0a7b92e0acd45aea4d97a3d0a999bc751a61;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=5eb2a03698d52d75d13ff39edda0533728f9e906;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/modules/contrib/paragraphs/src/Tests/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php b/web/modules/contrib/paragraphs/src/Tests/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php index 5eb2a0369..278e0a7b9 100644 --- a/web/modules/contrib/paragraphs/src/Tests/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php +++ b/web/modules/contrib/paragraphs/src/Tests/Experimental/ParagraphsExperimentalDuplicateFeatureTest.php @@ -22,47 +22,77 @@ class ParagraphsExperimentalDuplicateFeatureTest extends ParagraphsExperimentalT * Tests duplicate paragraph feature. */ public function testDuplicateButton() { - $this->addParagraphedContentType('paragraphed_test', 'field_paragraphs'); + $this->addParagraphedContentType('paragraphed_test'); $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']); // Add a Paragraph type. $paragraph_type = 'text_paragraph'; $this->addParagraphsType($paragraph_type); - $this->addParagraphsType('text'); // Add a text field to the text_paragraph type. static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []); $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_text_paragraph_add_more'); + $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_text_paragraph_add_more'); // Create a node with a Paragraph. - $text = 'recognizable_text'; + $text_01 = 'recognizable_text_01'; + $text_02 = 'recognizable_text_02'; $edit = [ 'title[0][value]' => 'paragraphs_mode_test', - 'field_paragraphs[0][subform][field_text][0][value]' => $text, + 'field_paragraphs[0][subform][field_text][0][value]' => 'A', + 'field_paragraphs[1][subform][field_text][0][value]' => 'B', + 'field_paragraphs[2][subform][field_text][0][value]' => 'C', ]; - $this->drupalPostForm(NULL, $edit, t('Save and publish')); + $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle('paragraphs_mode_test'); - // Change edit mode to "closed". - $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); $this->drupalGet('node/' . $node->id() . '/edit'); - // Click "Duplicate" button. - $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_duplicate'); - $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_0_edit'); - $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', $text); - $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', $text); + // Click "Duplicate" button on A and move C to the first position. + $edit = ['field_paragraphs[2][_weight]' => -1]; + $this->drupalPostAjaxForm(NULL, $edit, 'field_paragraphs_0_duplicate'); + $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertFieldByName('field_paragraphs[0][_weight]', 1); + $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'B'); + $this->assertFieldByName('field_paragraphs[1][_weight]', 3); + $this->assertFieldByName('field_paragraphs[2][subform][field_text][0][value]', 'C'); + $this->assertFieldByName('field_paragraphs[2][_weight]', 0); + $this->assertFieldByName('field_paragraphs[3][subform][field_text][0][value]', 'A'); + $this->assertFieldByName('field_paragraphs[3][_weight]', 2); + + // Move C after the A's and save. + $edit = [ + 'field_paragraphs[0][_weight]' => -2, + 'field_paragraphs[1][_weight]' => 2, + 'field_paragraphs[2][_weight]' => 1, + 'field_paragraphs[3][_weight]' => -1, + ]; + + // Save and check if all paragraphs are present in the correct order. + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->drupalGet('node/' . $node->id() . '/edit'); + $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'A'); + $this->assertFieldByName('field_paragraphs[2][subform][field_text][0][value]', 'C'); + $this->assertFieldByName('field_paragraphs[3][subform][field_text][0][value]', 'B'); - // Save and check if both paragraphs are present. - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); - $this->assertNoUniqueText($text); + // Delete the second A, then duplicate C. + $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_1_remove'); + $this->drupalPostAjaxForm(NULL, [], 'field_paragraphs_2_duplicate'); + $this->drupalPostForm(NULL, [], t('Save')); + + $this->drupalGet('node/' . $node->id() . '/edit'); + $this->assertFieldByName('field_paragraphs[0][subform][field_text][0][value]', 'A'); + $this->assertFieldByName('field_paragraphs[1][subform][field_text][0][value]', 'C'); + $this->assertFieldByName('field_paragraphs[2][subform][field_text][0][value]', 'C'); + $this->assertFieldByName('field_paragraphs[3][subform][field_text][0][value]', 'B'); } /** * Tests duplicate paragraph feature with nested paragraphs. */ public function testDuplicateButtonWithNesting() { - $this->addParagraphedContentType('paragraphed_test', 'field_paragraphs'); + $this->addParagraphedContentType('paragraphed_test'); $this->loginAsAdmin(['create paragraphed_test content', 'edit any paragraphed_test content']); // Add nested Paragraph type. @@ -86,7 +116,7 @@ class ParagraphsExperimentalDuplicateFeatureTest extends ParagraphsExperimentalT $edit = [ 'title[0][value]' => 'paragraphs_mode_test', ]; - $this->drupalPostForm(NULL, $edit, t('Save and publish')); + $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->drupalGetNodeByTitle('paragraphs_mode_test'); // Add a text field to nested paragraph. @@ -95,7 +125,7 @@ class ParagraphsExperimentalDuplicateFeatureTest extends ParagraphsExperimentalT $edit = [ 'field_paragraphs[0][subform][field_nested][0][subform][field_text][0][value]' => $text, ]; - $this->drupalPostForm(NULL, $edit, 'Save and keep published'); + $this->drupalPostForm(NULL, $edit, t('Save')); // Switch mode to closed. $this->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed'); @@ -115,7 +145,7 @@ class ParagraphsExperimentalDuplicateFeatureTest extends ParagraphsExperimentalT // Save and check if the changed text paragraph value of the duplicated // paragraph is not the same as in the original paragraph. - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertUniqueText($text); $this->assertUniqueText($second_paragraph_text); }