You are here

protected function ParagraphsFeaturesJavascriptTestBase::createTestConfiguration in Paragraphs Features 8

Same name and namespace in other branches
  1. 2.x tests/src/FunctionalJavascript/ParagraphsFeaturesJavascriptTestBase.php \Drupal\Tests\paragraphs_features\FunctionalJavascript\ParagraphsFeaturesJavascriptTestBase::createTestConfiguration()

Create content type with paragraph field and additional paragraph types.

Paragraph types are prefixed with "test_" and for text types index will be used. (fe. "$num_of_test_paragraphs = 3" will provide following test paragraphs: test_1, test_2, test_3.

Nested paragraph has type ID: test_nested.

Parameters

string $content_type: ID for new testing content type.

int $num_of_test_paragraphs: Number of additional test paragraph types beside nested one.

7 calls to ParagraphsFeaturesJavascriptTestBase::createTestConfiguration()
ParagraphsFeaturesAddInBetweenTest::testAddInBetweenFeature in tests/src/FunctionalJavascript/ParagraphsFeaturesAddInBetweenTest.php
Tests the add widget button with modal form.
ParagraphsFeaturesDeleteConfirmationTest::testCkEditorAfterCancel in tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php
This is test mainly to cover problem with initialization of CKEditor.
ParagraphsFeaturesDeleteConfirmationTest::testDeleteConfirmation in tests/src/FunctionalJavascript/ParagraphsFeaturesDeleteConfirmationTest.php
Test display of delete confirmation.
ParagraphsFeaturesExtendedParagraphsWidgetTest::testAddInBetweenFeature in tests/src/FunctionalJavascript/ParagraphsFeaturesExtendedParagraphsWidgetTest.php
Tests the add widget button with modal form.
ParagraphsFeaturesSingleActionTest::testAddAboveSupport in tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php
Test "add above" feature in combination with single action to button.

... See full list

File

tests/src/FunctionalJavascript/ParagraphsFeaturesJavascriptTestBase.php, line 85

Class

ParagraphsFeaturesJavascriptTestBase
Base class for Javascript tests for paragraphs features module.

Namespace

Drupal\Tests\paragraphs_features\FunctionalJavascript

Code

protected function createTestConfiguration($content_type, $num_of_test_paragraphs = 1) {
  $this
    ->addParagraphedContentType($content_type);
  $this
    ->loginAsAdmin([
    "administer content types",
    "administer node form display",
    "edit any {$content_type} content",
    "create {$content_type} content",
  ]);

  // Add a paragraph types.
  for ($paragraph_type_index = 1; $paragraph_type_index <= $num_of_test_paragraphs; $paragraph_type_index++) {
    $this
      ->addParagraphsType("test_{$paragraph_type_index}");
    $this
      ->addFieldtoParagraphType("test_{$paragraph_type_index}", "text_{$paragraph_type_index}", 'text_long');
  }

  // Create nested paragraph type.
  $this
    ->addParagraphsType('test_nested');

  // Add a paragraphs field.
  $this
    ->addParagraphsField('test_nested', 'field_paragraphs', 'paragraph');

  // Set cardinality to 4, because it's used in tests.
  $field_storage = FieldStorageConfig::loadByName('paragraph', 'field_paragraphs');
  $field_storage
    ->set('cardinality', 4);
  $field_storage
    ->save();

  // Set the settings for the field in the nested paragraph.
  $component = [
    'type' => 'paragraphs',
    'region' => 'content',
    'settings' => [
      'edit_mode' => 'closed',
      'add_mode' => 'modal',
      'form_display_mode' => 'default',
    ],
  ];
  EntityFormDisplay::load('paragraph.test_nested.default')
    ->setComponent('field_paragraphs', $component)
    ->save();
}