class ParagraphsWidgetButtonsTest

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

Tests paragraphs widget buttons.

@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 ParagraphsWidgetButtonsTest

File

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

Namespace

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

  /**
   * Tests the widget buttons of paragraphs.
   */
  public function testWidgetButtons() {
    $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 = 'text_paragraph';
    $this
      ->addParagraphsType($paragraph_type);
    $this
      ->addParagraphsType('text');

    // Add a text field to the text_paragraph type.
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->submitForm([], 'field_paragraphs_text_paragraph_add_more');

    // Create a node with a Paragraph.
    $text = 'recognizable_text';
    $edit = [
      'title[0][value]' => 'paragraphs_mode_test',
      'field_paragraphs[0][subform][field_text][0][value]' => $text,
    ];
    $this
      ->submitForm([], 'field_paragraphs_text_paragraph_add_more');
    $this
      ->submitForm($edit, 'Save');
    $node = $this
      ->drupalGetNodeByTitle('paragraphs_mode_test');

    // Test the 'Open' mode.
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertSession()
      ->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $text);
    $this
      ->submitForm([], 'Save');
    $this
      ->assertSession()
      ->pageTextContains($text);

    // Test the 'Closed' mode.
    $this
      ->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');

    // Click "Edit" button.
    $this
      ->submitForm([], 'field_paragraphs_0_edit');
    $this
      ->submitForm([], 'field_paragraphs_1_edit');
    $this
      ->assertSession()
      ->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $text);
    $closed_mode_text = 'closed_mode_text';

    // Click "Collapse" button on both paragraphs.
    $edit = [
      'field_paragraphs[0][subform][field_text][0][value]' => $closed_mode_text,
    ];
    $this
      ->submitForm($edit, 'field_paragraphs_0_collapse');
    $edit = [
      'field_paragraphs[1][subform][field_text][0][value]' => $closed_mode_text,
    ];
    $this
      ->submitForm($edit, 'field_paragraphs_1_collapse');

    // Verify that we have warning message for each paragraph.
    $page_text = $this
      ->getSession()
      ->getPage()
      ->getText();
    $nr_found = substr_count($page_text, 'You have unsaved changes on this Paragraph item.');
    $this
      ->assertGreaterThan(1, $nr_found);
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">' . $closed_mode_text);
    $this
      ->submitForm([], 'Save');
    $this
      ->assertSession()
      ->pageTextContains('paragraphed_test ' . $node
      ->label() . ' has been updated.');
    $this
      ->assertSession()
      ->pageTextContains($closed_mode_text);

    // Test the 'Preview' mode.
    $this
      ->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'preview');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');

    // Click "Edit" button.
    $this
      ->submitForm([], 'field_paragraphs_0_edit');
    $this
      ->assertSession()
      ->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $closed_mode_text);
    $preview_mode_text = 'preview_mode_text';
    $edit = [
      'field_paragraphs[0][subform][field_text][0][value]' => $preview_mode_text,
    ];

    // Click "Collapse" button.
    $this
      ->submitForm($edit, 'field_paragraphs_0_collapse');
    $this
      ->assertSession()
      ->pageTextContains('You have unsaved changes on this Paragraph item.');
    $this
      ->assertSession()
      ->pageTextContains($preview_mode_text);
    $this
      ->submitForm([], 'Save');
    $this
      ->assertSession()
      ->pageTextContains('paragraphed_test ' . $node
      ->label() . ' has been updated.');
    $this
      ->assertSession()
      ->pageTextContains($preview_mode_text);

    // Test the remove/restore function.
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertSession()
      ->pageTextContains($preview_mode_text);

    // Click "Remove" button.
    $this
      ->submitForm([], 'field_paragraphs_0_remove');
    $this
      ->assertSession()
      ->pageTextContains('Deleted Paragraph: text_paragraph');

    // Click "Restore" button.
    $this
      ->submitForm([], 'field_paragraphs_0_restore');
    $this
      ->assertSession()
      ->fieldValueEquals('field_paragraphs[0][subform][field_text][0][value]', $preview_mode_text);
    $restore_text = 'restore_text';
    $edit = [
      'field_paragraphs[0][subform][field_text][0][value]' => $restore_text,
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->assertSession()
      ->pageTextContains('paragraphed_test ' . $node
      ->label() . ' has been updated.');
    $this
      ->assertSession()
      ->pageTextContains($restore_text);

    // Test the remove/confirm remove function.
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertSession()
      ->pageTextContains($restore_text);

    // Click "Remove" button.
    $this
      ->submitForm([], 'field_paragraphs_0_remove');
    $this
      ->assertSession()
      ->pageTextContains('Deleted Paragraph: text_paragraph');

    // Click "Confirm Removal" button.
    $this
      ->submitForm([], 'field_paragraphs_0_confirm_remove');
    $this
      ->submitForm([], 'Save');
    $this
      ->assertSession()
      ->pageTextContains('paragraphed_test ' . $node
      ->label() . ' has been updated.');
    $this
      ->assertSession()
      ->pageTextNotContains($restore_text);
  }

}

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::$modules protected static property Modules to enable. 48
ParagraphsTestBase::loginAsAdmin function Creates an user with admin permissions and log in.
ParagraphsTestBase::removeDefaultParagraphType protected function Removes the default paragraph type. 1
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. 1
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
ParagraphsWidgetButtonsTest::testWidgetButtons public function Tests the widget buttons of paragraphs.