X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FClassic%2FParagraphsAdministrationTest.php;fp=web%2Fmodules%2Fcontrib%2Fparagraphs%2Fsrc%2FTests%2FClassic%2FParagraphsAdministrationTest.php;h=f36323dbac23e748c3f32c8f0cb5c0bd0a5df3a3;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsAdministrationTest.php b/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsAdministrationTest.php new file mode 100644 index 000000000..f36323dba --- /dev/null +++ b/web/modules/contrib/paragraphs/src/Tests/Classic/ParagraphsAdministrationTest.php @@ -0,0 +1,569 @@ +drupalCreateContentType(array('type' => 'paragraphs', 'name' => 'Paragraphs')); + } + /** + * Tests the revision of paragraphs. + */ + public function testParagraphsRevisions() { + $this->addParagraphedContentType('article', 'paragraphs'); + $this->loginAsAdmin([ + 'create paragraphs content', + 'administer node display', + 'edit any paragraphs content', + ]); + + // Create paragraphs type Headline + Block. + $this->addParagraphsType('text'); + // Create field types for the text. + static::fieldUIAddNewField('admin/structure/paragraphs_type/text', 'text', 'Text', 'text', array(), array()); + $this->assertText('Saved Text configuration.'); + + // Create an article with paragraphs field. + static::fieldUIAddNewField('admin/structure/types/manage/paragraphs', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array( + 'settings[target_type]' => 'paragraph', + 'cardinality' => '-1', + ), array( + 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => TRUE, + )); + // Configure article fields. + $this->drupalGet('admin/structure/types/manage/paragraphs/fields'); + $this->clickLink(t('Manage form display')); + $this->drupalPostForm(NULL, array('fields[field_paragraphs][type]' => 'entity_reference_paragraphs'), t('Save')); + + // Create node with our paragraphs. + $this->drupalGet('node/add/paragraphs'); + $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more'); + $this->drupalPostAjaxForm(NULL, array(), 'field_paragraphs_text_add_more'); + $edit = [ + 'title[0][value]' => 'TEST TITEL', + 'field_paragraphs[0][subform][field_text][0][value]' => 'Test text 1', + 'field_paragraphs[1][subform][field_text][0][value]' => 'Test text 2', + ]; + $this->drupalPostForm(NULL, $edit, t('Save and publish')); + + $node = $this->drupalGetNodeByTitle('TEST TITEL'); + $paragraph1 = $node->field_paragraphs[0]->target_id; + $paragraph2 = $node->field_paragraphs[1]->target_id; + + $this->countRevisions($node, $paragraph1, $paragraph2, 1); + + // Edit the node without creating a revision. There should still be only 1 + // revision for nodes and paragraphs. + $edit = [ + 'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 1', + 'revision' => FALSE, + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); + + $this->countRevisions($node, $paragraph1, $paragraph2, 1); + + // Edit the just created node. Create new revision. Now we should have 2 + // revisions for nodes and paragraphs. + $edit = [ + 'title[0][value]' => 'TEST TITLE', + 'field_paragraphs[0][subform][field_text][0][value]' => 'Foo Bar 2', + 'revision' => TRUE, + ]; + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); + + $this->countRevisions($node, $paragraph1, $paragraph2, 2); + + // Assert the paragraphs have been changed. + $this->assertNoText('Foo Bar 1'); + $this->assertText('Test text 2'); + $this->assertText('Foo Bar 2'); + $this->assertText('TEST TITLE'); + + // Check out the revisions page and assert there are 2 revisions. + $this->drupalGet('node/' . $node->id() . '/revisions'); + $rows = $this->xpath('//tbody/tr'); + // Make sure two revisions available. + $this->assertEqual(count($rows), 2); + // Revert to the old version. + $this->clickLink(t('Revert')); + $this->drupalPostForm(NULL, [], t('Revert')); + $this->drupalGet('node/' . $node->id()); + // Assert the node has been reverted. + $this->assertNoText('Foo Bar 2'); + $this->assertText('Test text 2'); + $this->assertText('Foo Bar 1'); + $this->assertText('TEST TITEL'); + } + + + /** + * Tests the paragraph creation. + */ + public function testParagraphsCreation() { + // Create an article with paragraphs field. + $this->addParagraphedContentType('article', 'field_paragraphs'); + $this->loginAsAdmin([ + 'administer site configuration', + 'create article content', + 'create paragraphs content', + 'administer node display', + 'administer paragraph display', + 'edit any article content', + 'delete any article content', + 'access files overview', + ]); + + // Assert suggested 'Add a paragraph type' link when there is no type yet. + $this->drupalGet('admin/structure/paragraphs_type'); + $this->assertText('There is no Paragraphs type yet.'); + $this->drupalGet('admin/structure/types/manage/paragraphs/fields/add-field'); + $edit = [ + 'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph', + 'label' => 'Paragraph', + 'field_name' => 'paragraph', + ]; + $this->drupalPostForm(NULL, $edit, 'Save and continue'); + $this->drupalPostForm(NULL, [], 'Save field settings'); + $this->assertLinkByHref('admin/structure/paragraphs_type/add'); + $this->clickLink('here'); + $this->assertUrl('admin/structure/paragraphs_type/add'); + + $this->drupalGet('admin/structure/paragraphs_type'); + $this->clickLink(t('Add paragraphs type')); + $this->assertTitle('Add paragraphs type | Drupal'); + // Create paragraph type text + image. + $this->addParagraphsType('text_image'); + $this->drupalGet('admin/structure/paragraphs_type/text_image'); + $this->assertTitle('Edit text_image paragraph type | Drupal'); + // Create field types for text and image. + static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text', 'Text', 'text_long', array(), array()); + $this->assertText('Saved Text configuration.'); + static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image', 'Image', 'image', array(), array('settings[alt_field_required]' => FALSE)); + $this->assertText('Saved Image configuration.'); + + // Create paragraph type Nested test. + $this->addParagraphsType('nested_test'); + + static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_test', 'paragraphs', 'Paragraphs', 'entity_reference_revisions', array( + 'settings[target_type]' => 'paragraph', + 'cardinality' => '-1', + ), array()); + + // Change the add more button to select mode. + $this->clickLink(t('Manage form display')); + $this->drupalPostAjaxForm(NULL, ['fields[field_paragraphs][type]' => 'entity_reference_paragraphs'], 'field_paragraphs_settings_edit'); + $this->drupalPostForm(NULL, ['fields[field_paragraphs][settings_edit_form][settings][add_mode]' => 'select'], t('Update')); + $this->drupalPostForm(NULL, [], t('Save')); + + // Create paragraph type image. + $this->addParagraphsType('image'); + // Create field types for image. + static::fieldUIAddNewField('admin/structure/paragraphs_type/image', 'image_only', 'Image only', 'image', array(), array()); + $this->assertText('Saved Image only configuration.'); + + $this->drupalGet('admin/structure/paragraphs_type'); + $rows = $this->xpath('//tbody/tr'); + // Make sure 2 types are available with their label. + $this->assertEqual(count($rows), 3); + $this->assertText('text_image'); + $this->assertText('image'); + // Make sure there is an edit link for each type. + $this->clickLink(t('Edit')); + // Make sure the field UI appears. + $this->assertLink('Manage fields'); + $this->assertLink('Manage form display'); + $this->assertLink('Manage display'); + $this->assertTitle('Edit image paragraph type | Drupal'); + + // Test for "Add mode" setting. + $this->drupalGet('admin/structure/types/manage/article/form-display'); + $field_name = 'field_paragraphs'; + + // Click on the widget settings button to open the widget settings form. + $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); + + // Enable setting. + $edit = array('fields[' . $field_name . '][settings_edit_form][settings][add_mode]' => 'button'); + $this->drupalPostForm(NULL, $edit, t('Save')); + + // Check if the setting is stored. + $this->drupalGet('admin/structure/types/manage/article/form-display'); + $this->assertText('Add mode: Buttons', 'Checking the settings value.'); + + $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); + // Assert the 'Buttons' option is selected. + $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button', 'Updated value is correct!.'); + + // Add two Text + Image paragraphs in article. + $this->drupalGet('node/add/article'); + + // Checking changes on article. + $this->assertRaw('