class ParagraphsInlineEntityFormTest

Same name in this branch
  1. 8.x-1.x paragraphs/tests/src/Functional/WidgetStable/ParagraphsInlineEntityFormTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsInlineEntityFormTest
  2. 8.x-1.x paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsInlineEntityFormTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsInlineEntityFormTest

Tests the configuration of paragraphs in relation to ief.

@group paragraphs

Hierarchy

Expanded class hierarchy of ParagraphsInlineEntityFormTest

File

paragraphs/tests/src/Functional/WidgetStable/ParagraphsInlineEntityFormTest.php, line 12

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable
View source
class ParagraphsInlineEntityFormTest extends ParagraphsTestBase {
  use ParagraphsTestBaseTrait;

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'inline_entity_form',
  ];

  /**
   * Tests the revision of paragraphs.
   */
  public function testParagraphsIEFPreview() {

    // Create article content type with a paragraphs field.
    $this
      ->addParagraphedContentType('article');
    $this
      ->loginAsAdmin([
      'create article content',
      'edit any article content',
    ]);

    // Create the paragraphs type simple.
    $this
      ->addParagraphsType('simple');
    $this
      ->addParagraphsType('text');

    // Create a reference to an article.
    $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,
    ]);

    // Enable IEF simple widget.
    $this
      ->drupalGet('admin/structure/paragraphs_type/simple/form-display');
    $edit = [
      'fields[field_article][type]' => 'inline_entity_form_simple',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Set the paragraphs widget edit mode to "Closed" and the closed mode to
    // "Preview".
    $settings = [
      'edit_mode' => 'closed',
      'closed_mode' => 'preview',
    ];
    $this
      ->setParagraphsWidgetSettings('article', 'field_paragraphs', $settings);

    // Create node with one paragraph.
    $this
      ->drupalGet('node/add/article');
    $this
      ->submitForm([], 'field_paragraphs_simple_add_more');

    // Set the values and save.
    $edit = [
      'title[0][value]' => 'Dummy1',
      'field_paragraphs[0][subform][field_article][0][inline_entity_form][title][0][value]' => 'Dummy2',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Go back into edit page.
    $node = $this
      ->getNodeByTitle('Dummy1');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');

    // Try to open the previewed paragraph.
    $this
      ->submitForm([], 'field_paragraphs_0_edit');
  }

  /**
   * Tests the reordering of previewed paragraphs.
   */
  public function testParagraphsIEFChangeOrder() {

    // Create article content type with a paragraphs field.
    $this
      ->addParagraphedContentType('article');
    $this
      ->loginAsAdmin([
      'create article content',
      'edit any article content',
    ]);

    // Create the paragraphs type simple.
    $this
      ->addParagraphsType('simple');
    $this
      ->addParagraphsType('text');

    // Create a reference to an article.
    $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,
    ]);

    // Set cardinality explicit to -1.
    $this
      ->drupalGet('admin/structure/types/manage/article/fields/node.article.field_paragraphs');
    $edit = [
      'field_storage[subform][cardinality]' => '-1',
    ];
    $this
      ->submitForm($edit, 'Save settings');

    // Enable IEF simple widget.
    $this
      ->drupalGet('admin/structure/paragraphs_type/simple/form-display');
    $edit = [
      'fields[field_article][type]' => 'inline_entity_form_simple',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Set the paragraphs widget closed mode to preview.
    $this
      ->setParagraphsWidgetSettings('article', 'field_paragraphs', [
      'closed_mode' => 'preview',
    ]);

    // Create node with one paragraph.
    $this
      ->drupalGet('node/add/article');
    $this
      ->submitForm([], 'field_paragraphs_simple_add_more');

    // Set the values and save.
    $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');

    // Go back into edit page.
    $node = $this
      ->getNodeByTitle('Article 1');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');

    // Create second paragraph.
    $this
      ->submitForm([], 'field_paragraphs_simple_add_more');

    // Set the values of second paragraph.
    $edit = [
      'field_paragraphs[1][subform][field_article][0][inline_entity_form][title][0][value]' => 'Basic 2',
    ];
    $this
      ->submitForm($edit, 'Save');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsInlineEntityFormTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules
ParagraphsInlineEntityFormTest::testParagraphsIEFChangeOrder public function Tests the reordering of previewed paragraphs.
ParagraphsInlineEntityFormTest::testParagraphsIEFPreview public function Tests the revision of paragraphs.
ParagraphsTestBase::$admin_permissions protected property List of permissions used by loginAsAdmin().
ParagraphsTestBase::$admin_user protected property Drupal user object created by loginAsAdmin(). 1
ParagraphsTestBase::$defaultTheme protected property 2
ParagraphsTestBase::loginAsAdmin function Creates an user with admin permissions and log in.
ParagraphsTestBase::removeDefaultParagraphType protected function Removes the default paragraph type. Overrides ParagraphsTestBase::removeDefaultParagraphType
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. Overrides ParagraphsTestBase::setAddMode
ParagraphsTestBase::setAllowedParagraphsTypes protected function Sets the allowed Paragraphs types that can be added.
ParagraphsTestBase::setDefaultParagraphType protected function Sets the default paragraph type.
ParagraphsTestBase::setParagraphsTypeWeight protected function Sets the weight of a given Paragraphs type.
ParagraphsTestBase::setParagraphsWidgetMode protected function Sets the Paragraphs widget display mode.
ParagraphsTestBase::setUp protected function 19
ParagraphsTestBaseTrait::$workflow protected property The workflow entity.
ParagraphsTestBaseTrait::addFieldtoParagraphType protected function Adds a field to a given paragraph type.
ParagraphsTestBaseTrait::addParagraphedContentType protected function Adds a content type with a Paragraphs field.
ParagraphsTestBaseTrait::addParagraphsField protected function Adds a Paragraphs field to a given entity type.
ParagraphsTestBaseTrait::addParagraphsType protected function Adds a Paragraphs type.
ParagraphsTestBaseTrait::addParagraphsTypeIcon protected function Adds an icon to a paragraphs type.
ParagraphsTestBaseTrait::coreVersion protected function Checks the core version.
ParagraphsTestBaseTrait::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.