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/ParagraphsUiTest.php, line 12

Namespace

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

  /**
   * Modules to enable.
   *
   * @var string[]
   */
  protected static $modules = [
    'node',
    'paragraphs',
    'field',
    'field_ui',
    'block',
  ];

  /**
   * Tests if the paragraph type class is present when added.
   */
  public function testParagraphTypeClass() {
    $this
      ->loginAsAdmin();

    // Add a Paragraphed test content.
    $this
      ->addParagraphedContentType('paragraphed_test', 'paragraphs');
    $this
      ->addParagraphsType('test_paragraph');
    $this
      ->addParagraphsType('text');

    // Add paragraphs to a node and check if their type is present as a class.
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->getSession()
      ->getPage()
      ->findButton('paragraphs_test_paragraph_add_more')
      ->press();
    $this
      ->assertSession()
      ->responseContains('paragraph-type--test-paragraph');
    $this
      ->getSession()
      ->getPage()
      ->findButton('paragraphs_text_add_more')
      ->press();
    $this
      ->assertSession()
      ->responseContains('paragraph-type--text');
    $this
      ->getSession()
      ->getPage()
      ->findButton('paragraphs_0_remove')
      ->press();
    $this
      ->assertSession()
      ->responseContains('paragraph-type--text');
  }

  /**
   * Test paragraphs summary with markup text.
   */
  public function testSummary() {
    $this
      ->addParagraphedContentType('paragraphed_test', 'paragraphs');
    $this
      ->addParagraphsType('text');
    $this
      ->addFieldtoParagraphType('text', 'field_text_demo', 'text');
    $this
      ->loginAsAdmin([
      'edit any paragraphed_test content',
    ]);
    $settings = [
      'edit_mode' => 'closed',
      'closed_mode' => 'summary',
    ];
    $this
      ->setParagraphsWidgetSettings('paragraphed_test', 'paragraphs', $settings, 'paragraphs');

    // Create a node and add a paragraph.
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->getSession()
      ->getPage()
      ->findButton('paragraphs_text_add_more')
      ->press();
    $edit = [
      'title[0][value]' => 'Llama test',
      'paragraphs[0][subform][field_text_demo][0][value]' => '<iframe src="https://www.llamatest.neck"></iframe>',
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->assertSession()
      ->pageTextContains('paragraphed_test Llama test has been created.');

    // Assert that the summary contains the html text.
    $node = $this
      ->getNodeByTitle('Llama test');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertSession()
      ->pageTextContains('<iframe src="https://www.llamatest.neck');
    $this
      ->assertSession()
      ->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">&lt;iframe src=');

    // Assert that the summary keeps showing html even with longer html.
    $this
      ->getSession()
      ->getPage()
      ->pressButton('paragraphs_0_edit');
    $edit = [
      'paragraphs[0][subform][field_text_demo][0][value]' => '<iframe src="https://www.llamatest.neck" class="this-is-a-pretty-long-class-that-needs-to-be-really-long-for-testing-purposes-so-we-have-a-better-summary-test-and-it-has-exactly-144-characters"></iframe>',
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->assertSession()
      ->pageTextContains('paragraphed_test Llama test has been updated.');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertSession()
      ->pageTextContains('<iframe src="https://www.llamatest.neck" class="this-is-a-pretty-long-class-that-needs-to-be-really-long-for-testing-purposes-so-we-');
    $this
      ->assertSession()
      ->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">&lt;iframe src=');

    // Asset that the summary does not display markup even when we have long
    // html.
    $this
      ->getSession()
      ->getPage()
      ->pressButton('paragraphs_0_edit');
    $edit = [
      'paragraphs[0][subform][field_text_demo][0][value]' => '<iframe src="https://www.llamatest.neck" class="this-is-a-pretty-long-class-that-needs-to-be-really-long-for-testing-purposes-so-we-have-a-better-summary-test-and-it-has-exactly-144-characters"></iframe><h1>This is a title</h1>',
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->assertSession()
      ->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">This is a title');
  }

  /**
   * Test the default paragraphs widget used.
   */
  public function testDefaultWidget() {
    $this
      ->loginAsAdmin();

    // Create a new content type.
    $this
      ->drupalGet('admin/structure/types/add');
    $this
      ->submitForm([
      'name' => 'Test',
      'type' => 'test',
    ], 'Save and manage fields');

    // Add a new paragraphs field to the content type.
    $this
      ->clickLink('Create a new field');
    $this
      ->getSession()
      ->getPage()
      ->fillField('new_storage_type', 'field_ui:entity_reference_revisions:paragraph');
    if ($this
      ->coreVersion('10.3')) {
      $this
        ->getSession()
        ->getPage()
        ->pressButton('Continue');
    }
    $edit = [
      'label' => 'Paragraph',
      'field_name' => 'paragraph',
    ];
    $this
      ->submitForm($edit, 'Continue');
    $this
      ->submitForm([], 'Save settings');

    // Visit the "Manage form display" page of the new content type.
    $this
      ->drupalGet('admin/structure/types/manage/test/form-display');

    // The selected widget should be "paragraphs".
    $this
      ->assertSession()
      ->fieldValueEquals('fields[field_paragraph][type]', 'paragraphs');
  }

}

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.
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.
ParagraphsUiTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules
ParagraphsUiTest::testDefaultWidget public function Test the default paragraphs widget used.
ParagraphsUiTest::testParagraphTypeClass public function Tests if the paragraph type class is present when added.
ParagraphsUiTest::testSummary public function Test paragraphs summary with markup text.