class ParagraphsEditModesTest

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

Tests paragraphs edit modes.

@group paragraphs

Hierarchy

  • class \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsTestBase extends \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\field_ui\Traits\FieldUiTestTrait

Expanded class hierarchy of ParagraphsEditModesTest

File

paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsEditModesTest.php, line 10

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy
View source
class ParagraphsEditModesTest extends ParagraphsTestBase {

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

  /**
   * Tests the collapsed summary of paragraphs.
   */
  public function testCollapsedSummary() {
    $this
      ->addParagraphedContentType('paragraphed_test', 'field_paragraphs', 'entity_reference_paragraphs');
    $this
      ->loginAsAdmin([
      'create paragraphed_test content',
      'edit any paragraphed_test content',
    ]);

    // Add a Paragraph type.
    $paragraph_type = 'image_text_paragraph';
    $this
      ->addParagraphsType($paragraph_type);
    $title_paragraphs_type = 'title';
    $this
      ->addParagraphsType($title_paragraphs_type);
    $this
      ->addParagraphsType('text');
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'image', 'Image', 'image', [], [
      'settings[alt_field_required]' => FALSE,
    ]);
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $title_paragraphs_type, 'title', 'Title', 'string', [], []);

    // Set edit mode to closed.
    $this
      ->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
    $this
      ->submitForm([], "field_paragraphs_settings_edit");
    $edit = [
      'fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Add a paragraph.
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->submitForm([], 'field_paragraphs_image_text_paragraph_add_more');
    $this
      ->submitForm([], 'field_paragraphs_title_add_more');
    $files = $this
      ->getTestFiles('image');
    $file_system = \Drupal::service('file_system');

    // Create a node with an image and text.
    $edit = [
      'title[0][value]' => 'Test article',
      'field_paragraphs[0][subform][field_text][0][value]' => 'text_summary',
      'files[field_paragraphs_0_subform_field_image_0]' => $file_system
        ->realpath($files[0]->uri),
      'field_paragraphs[1][subform][field_title][0][value]' => 'Title example',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Assert the summary is correctly generated.
    $this
      ->clickLink('Edit');
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">' . $files[0]->filename . '</span>, <span class="summary-content">text_summary</span>');
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">Title example');

    // Edit and remove alternative text.
    $this
      ->submitForm([], 'field_paragraphs_0_edit');
    $edit = [
      'field_paragraphs[0][subform][field_image][0][alt]' => 'alternative_text_summary',
    ];
    $this
      ->submitForm($edit, 'field_paragraphs_0_collapse');

    // Assert the summary is correctly generated.
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">alternative_text_summary</span>, <span class="summary-content">text_summary</span>');

    // Remove image.
    $this
      ->submitForm([], 'field_paragraphs_0_edit');
    $this
      ->submitForm([], 'field_paragraphs_0_subform_field_image_0_remove_button');
    $this
      ->submitForm([], 'Save');

    // Assert the summary is correctly generated.
    $this
      ->clickLink('Edit');
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">text_summary');

    // Add a Block Paragraphs type.
    $this
      ->addParagraphsType('block_paragraph');
    $this
      ->addFieldtoParagraphType('block_paragraph', 'field_block', 'block_field');

    // Test the summary of a Block field.
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->submitForm([], 'field_paragraphs_block_paragraph_add_more');
    $edit = [
      'title[0][value]' => 'Node with a Block Paragraph',
      'field_paragraphs[0][subform][field_block][0][plugin_id]' => 'system_breadcrumb_block',
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->clickLink('Edit');
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">Breadcrumbs');
  }

}

Members

Name Modifiers Type Description Overridessort ascending
ParagraphsTestBase::setUp protected function 19
ParagraphsTestBase::$defaultTheme protected property 2
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. 1
ParagraphsTestBase::removeDefaultParagraphType protected function Removes the default paragraph type. 1
ParagraphsTestBase::$admin_user protected property Drupal user object created by loginAsAdmin(). 1
ParagraphsEditModesTest::testCollapsedSummary public function Tests the collapsed summary of paragraphs.
ParagraphsTestBase::loginAsAdmin function Creates an user with admin permissions and log in.
ParagraphsTestBase::setAllowedParagraphsTypes protected function Sets the allowed Paragraphs types that can be added.
ParagraphsTestBase::setParagraphsTypeWeight protected function Sets the weight of a given Paragraphs type.
ParagraphsTestBase::setDefaultParagraphType protected function Sets the default paragraph type.
ParagraphsTestBase::setParagraphsWidgetMode protected function Sets the Paragraphs widget display mode.
ParagraphsEditModesTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules
ParagraphsTestBase::$admin_permissions protected property List of permissions used by loginAsAdmin().