View source
<?php
namespace Drupal\Tests\paragraphs\Functional\WidgetStable;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
class ParagraphsInlineEntityFormTest extends ParagraphsTestBase {
use ParagraphsTestBaseTrait;
public static $modules = [
'inline_entity_form',
];
public function testParagraphsIEFPreview() {
$this
->addParagraphedContentType('article');
$this
->loginAsAdmin([
'create article content',
'edit any article content',
]);
$this
->addParagraphsType('simple');
$this
->addParagraphsType('text');
$this
->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
'settings[target_type]' => 'node',
'cardinality' => 'number',
'cardinality_number' => 1,
], [
'required' => TRUE,
'settings[handler_settings][target_bundles][article]' => TRUE,
]);
$this
->drupalGet('admin/structure/paragraphs_type/simple/form-display');
$edit = [
'fields[field_article][type]' => 'inline_entity_form_simple',
];
$this
->submitForm($edit, 'Save');
$settings = [
'edit_mode' => 'closed',
'closed_mode' => 'preview',
];
$this
->setParagraphsWidgetSettings('article', 'field_paragraphs', $settings);
$this
->drupalGet('node/add/article');
$this
->submitForm([], 'field_paragraphs_simple_add_more');
$edit = [
'title[0][value]' => 'Dummy1',
'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Dummy2',
];
$this
->submitForm($edit, 'Save');
$node = $this
->getNodeByTitle('Dummy1');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([], 'field_paragraphs_0_edit');
}
public function testParagraphsIEFChangeOrder() {
$this
->addParagraphedContentType('article');
$this
->loginAsAdmin([
'create article content',
'edit any article content',
]);
$this
->addParagraphsType('simple');
$this
->addParagraphsType('text');
$this
->fieldUIAddNewField('admin/structure/paragraphs_type/simple', 'article', 'Article', 'field_ui:entity_reference:node', [
'settings[target_type]' => 'node',
'cardinality' => 'number',
'cardinality_number' => '1',
], [
'required' => TRUE,
'settings[handler_settings][target_bundles][article]' => TRUE,
]);
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs/storage');
$edit = [
'settings[target_type]' => 'paragraph',
'cardinality' => '-1',
];
$this
->submitForm($edit, 'Save field settings');
$this
->drupalGet('admin/structure/paragraphs_type/simple/form-display');
$edit = [
'fields[field_article][type]' => 'inline_entity_form_simple',
];
$this
->submitForm($edit, 'Save');
$this
->setParagraphsWidgetSettings('article', 'field_paragraphs', [
'closed_mode' => 'preview',
]);
$this
->drupalGet('node/add/article');
$this
->submitForm([], 'field_paragraphs_simple_add_more');
$edit = [
'title[0][value]' => 'Article 1',
'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic page 1',
];
$this
->submitForm($edit, 'Save');
$node = $this
->getNodeByTitle('Article 1');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([], 'field_paragraphs_simple_add_more');
$edit = [
'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2',
];
$this
->submitForm($edit, 'Save');
}
}