class ParagraphsUiTest

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

Tests the Paragraphs user interface.

@group paragraphs

Hierarchy

Expanded class hierarchy of ParagraphsUiTest

File

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

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable
View source
class ParagraphsUiTest extends ParagraphsTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = array(
    'content_translation',
    'image',
    'field',
    'field_ui',
    'block',
    'language',
    'node',
  );

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    ConfigurableLanguage::create([
      'id' => 'de',
      'label' => '1German',
    ])
      ->save();
    ConfigurableLanguage::create([
      'id' => 'fr',
      'label' => '2French',
    ])
      ->save();
    $this
      ->addParagraphedContentType('paragraphed_content_demo', 'field_paragraphs_demo');
    $this
      ->loginAsAdmin([
      'administer site configuration',
      'administer content translation',
      'administer languages',
    ]);
    $this
      ->addParagraphsType('nested_paragraph');
    $this
      ->addParagraphsField('nested_paragraph', 'field_paragraphs_demo', 'paragraph');
    $this
      ->addParagraphsType('images');
    static::fieldUIAddNewField('admin/structure/paragraphs_type/images', 'images_demo', 'Images', 'image', [
      'cardinality' => -1,
    ], [
      'settings[alt_field]' => FALSE,
    ]);
    $this
      ->addParagraphsType('text_image');
    static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'image_demo', 'Images', 'image', [
      'cardinality' => -1,
    ], [
      'settings[alt_field]' => FALSE,
    ]);
    static::fieldUIAddNewField('admin/structure/paragraphs_type/text_image', 'text_demo', 'Text', 'text_long', [], []);
    $this
      ->addParagraphsType('text');
    static::fieldUIAddExistingField('admin/structure/paragraphs_type/text', 'field_text_demo', 'Text', []);
    $edit = [
      'entity_types[node]' => TRUE,
      'entity_types[paragraph]' => TRUE,
      'settings[node][paragraphed_content_demo][translatable]' => TRUE,
      'settings[node][paragraphed_content_demo][fields][field_paragraphs_demo]' => FALSE,
      'settings[paragraph][images][translatable]' => TRUE,
      'settings[paragraph][text_image][translatable]' => TRUE,
      'settings[paragraph][text][translatable]' => TRUE,
      'settings[paragraph][nested_paragraph][translatable]' => TRUE,
      'settings[paragraph][nested_paragraph][fields][field_paragraphs_demo]' => FALSE,
      'settings[paragraph][nested_paragraph][settings][language][language_alterable]' => TRUE,
      'settings[paragraph][images][fields][field_images_demo]' => TRUE,
      'settings[paragraph][text_image][fields][field_image_demo]' => TRUE,
      'settings[paragraph][text_image][fields][field_text_demo]' => TRUE,
      'settings[node][paragraphed_content_demo][settings][language][language_alterable]' => TRUE,
    ];
    $this
      ->drupalGet('admin/config/regional/content-language');
    $this
      ->submitForm($edit, 'Save configuration');
  }

  /**
   * Tests displaying an error message a required paragraph field that is empty.
   */
  public function testEmptyRequiredField() {
    $admin_user = $this
      ->drupalCreateUser([
      'administer node fields',
      'administer paragraph form display',
      'administer node form display',
      'create paragraphed_content_demo content',
      'edit any paragraphed_content_demo content',
    ]);
    $this
      ->drupalLogin($admin_user);

    // Add required field to paragraphed content type.
    $bundle_path = 'admin/structure/types/manage/paragraphed_content_demo';
    $field_title = 'Content Test';
    $field_type = 'field_ui:entity_reference_revisions:paragraph';
    $field_edit = [
      'required' => TRUE,
    ];
    $this
      ->fieldUIAddNewField($bundle_path, 'content', $field_title, $field_type, [], $field_edit);
    $form_display_edit = [
      'fields[field_content][type]' => 'paragraphs',
    ];
    $this
      ->drupalGet($bundle_path . '/form-display');
    $this
      ->submitForm($form_display_edit, 'Save');

    // Attempt to create a paragraphed node with an empty required field.
    $title = 'Empty';
    $this
      ->drupalGet('node/add/paragraphed_content_demo');
    $this
      ->submitForm([
      'title[0][value]' => $title,
    ], 'Save');
    $this
      ->assertSession()
      ->pageTextContains($field_title . ' field is required');

    // Attempt to create a paragraphed node with only a paragraph in the
    // "remove" mode in the required field.
    $title = 'Remove all items';
    $this
      ->drupalGet('node/add/paragraphed_content_demo');
    $this
      ->submitForm([], 'field_content_text_image_add_more');
    $this
      ->submitForm([], 'field_content_0_remove');
    $this
      ->assertSession()
      ->pageTextNotContains($field_title . ' field is required');
    $this
      ->submitForm([
      'title[0][value]' => $title,
    ], 'Save');
    $this
      ->assertSession()
      ->pageTextContains($field_title . ' field is required');

    // Attempt to create a paragraphed node with a valid paragraph and a
    // removed paragraph.
    $title = 'Valid Removal';
    $this
      ->drupalGet('node/add/paragraphed_content_demo');
    $this
      ->submitForm([], 'field_content_text_image_add_more');
    $this
      ->submitForm([], 'field_content_text_image_add_more');
    $this
      ->submitForm([], 'field_content_1_remove');
    $this
      ->assertSession()
      ->pageTextNotContains($field_title . ' field is required');
    $this
      ->submitForm([
      'title[0][value]' => $title,
    ], 'Save');
    $this
      ->assertSession()
      ->pageTextNotContains($field_title . ' field is required');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
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.
ParagraphsUiTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules
ParagraphsUiTest::setUp protected function Overrides ParagraphsTestBase::setUp
ParagraphsUiTest::testEmptyRequiredField public function Tests displaying an error message a required paragraph field that is empty.