diff --git a/modules/paragraphs_library/src/Tests/ParagraphsLibraryItemTest.php b/modules/paragraphs_library/src/Tests/ParagraphsLibraryItemTest.php index ca15958..ea8553f 100644 --- a/modules/paragraphs_library/src/Tests/ParagraphsLibraryItemTest.php +++ b/modules/paragraphs_library/src/Tests/ParagraphsLibraryItemTest.php @@ -20,7 +20,12 @@ class ParagraphsLibraryItemTest extends ParagraphsExperimentalTestBase { * * @var array */ - public static $modules = ['views', 'paragraphs_library']; + public static $modules = [ + 'views', + 'paragraphs_library', + 'paragraphs_collection_test', + 'link', + ]; /** * Tests the library items workflow for paragraphs. @@ -138,4 +143,46 @@ class ParagraphsLibraryItemTest extends ParagraphsExperimentalTestBase { $this->assertEqual($element[0]->p->__toString(), 're_usable_text_new', 'Paragraphs summary available.'); } + /** + * Tests converting Library item into a paragraph. + */ + public function testConvertLibraryItemIntoParagraph() { + $this->addParagraphedContentType('paragraphed_test', 'field_paragraphs'); + + $this->loginAsAdmin([ + 'create paragraphed_test content', + 'edit any paragraphed_test content', + 'administer paragraphs library', + ]); + + // Add a new library item. + $this->drupalGet('admin/content/paragraphs'); + $this->clickLink('Add library item'); + $this->assertText('From library'); + $this->drupalPostAjaxForm(NULL, [], 'paragraphs_text_add_more'); + $edit = [ + 'label[0][value]' => 're usable paragraph label', + 'paragraphs[0][subform][paragraphs_text][0][value]' => 're_usable_text', + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + + $this->drupalPostAjaxForm('node/add/paragraphed_test', [], 'field_paragraphs_from_library_add_more'); + $edit = [ + 'title[0][value]' => 'Test node', + 'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 're usable paragraph label (1)', + ]; + $this->drupalPostForm(NULL, $edit, t('Save and publish')); + + $this->assertText('re_usable_text'); + + $node = $this->getNodeByTitle('Test node'); + + $this->drupalPostAjaxForm('node/' . $node->id() . '/edit', [], 'field_paragraphs_0_remove_library_item'); + $this->assertFieldByName('field_paragraphs[0][subform][paragraphs_text][0][value]'); + $this->assertText('re_usable_text'); + + $this->drupalPostForm(NULL, [], t('Save and keep published')); + $this->assertText('re_usable_text'); + } + }