class ParagraphsTypesTest

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

Tests the Paragraphs Collection paragraph types.

@group paragraphs_collection @requires module paragraphs

Hierarchy

Expanded class hierarchy of ParagraphsTypesTest

File

paragraphs_collection/tests/src/Functional/ParagraphsTypesTest.php, line 13

Namespace

Drupal\Tests\paragraphs_collection\Functional
View source
class ParagraphsTypesTest extends ParagraphsTestBase {

  /**
   * Modules to be enabled.
   */
  protected static $modules = [
    'paragraphs_collection',
    'paragraphs_library',
  ];

  /**
   * Tests adding the existing paragraph types.
   */
  public function testAddParagraphTypes() {
    $this
      ->addParagraphedContentType('paragraphed_test');
    $this
      ->loginAsAdmin([
      'create paragraphed_test content',
      'edit any paragraphed_test content',
      'administer paragraphs library',
    ]);
    $this
      ->drupalGet('/node/add/paragraphed_test');
    $this
      ->submitForm([], 'field_paragraphs_intro_add_more');
    $this
      ->submitForm([], 'field_paragraphs_quote_add_more');
    $this
      ->submitForm([], 'field_paragraphs_separator_add_more');
    $this
      ->submitForm([], 'field_paragraphs_subtitle_add_more');
    $this
      ->submitForm([], 'field_paragraphs_title_add_more');
    $this
      ->submitForm([], 'field_paragraphs_user_add_more');
    $this
      ->submitForm([], 'field_paragraphs_footer_add_more');
    $edit = [
      'title[0][value]' => 'Paragraph types example',
      'field_paragraphs[0][subform][paragraphs_text][0][value]' => 'Intro test',
      'field_paragraphs[1][subform][paragraphs_quote_text][0][value]' => 'Quote test',
      'field_paragraphs[1][subform][paragraphs_quote_author][0][value]' => 'Author test',
      'field_paragraphs[3][subform][paragraphs_subtitle][0][value]' => 'Subtitle test',
      'field_paragraphs[4][subform][paragraphs_title][0][value]' => 'Title test',
      'field_paragraphs[5][subform][paragraphs_user][0][target_id]' => $this->admin_user
        ->getAccountName() . ' (' . $this->admin_user
        ->id() . ')',
      'field_paragraphs[6][subform][paragraphs_text][0][value]' => 'Footer test',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Checks content.
    $this
      ->assertSession()
      ->pageTextContains('Intro test');
    $this
      ->assertSession()
      ->pageTextContains($this->admin_user
      ->getDisplayName());
    $this
      ->assertSession()
      ->pageTextContains('Footer test');
    $this
      ->assertSession()
      ->pageTextContains('Subtitle test');
    $this
      ->assertSession()
      ->pageTextContains('Title test');

    // Asserts the quote paragraph type.
    $elements = $this
      ->xpath('//blockquote[contains(@class, class)]', [
      ':class' => 'paragraph--type--quote',
    ]);
    $this
      ->assertCount(1, $elements);
    $this
      ->assertSession()
      ->pageTextContains('Quote test');
    $this
      ->assertSession()
      ->pageTextContains('Author test');

    // Adds the link paragraph type.
    $this
      ->drupalGet('/node/add/paragraphed_test');
    $this
      ->submitForm([], 'field_paragraphs_link_add_more');
    $edit = [
      'title[0][value]' => 'Link example',
      'field_paragraphs[0][subform][paragraphs_link][0][uri]' => 'Paragraph types example (1)',
      'field_paragraphs[0][subform][paragraphs_link][0][title]' => 'Link test',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Checks if the link type is working properly.
    $this
      ->clickLink('Link test');
    $this
      ->assertSession()
      ->pageTextContains('Paragraph types example');
  }

  /**
   * Ensures that a new paragraph type is created.
   */
  public function testCreateParagraphType() {
    $this
      ->loginAsAdmin();
    $this
      ->drupalGet('/admin/structure/paragraphs_type');
    $this
      ->clickLink(t('Add paragraph type'));
    $edit = [
      'label' => 'test_paragraph',
      'id' => 'test_paragraph',
    ];
    $this
      ->submitForm($edit, t('Save and manage fields'));
    $this
      ->assertSession()
      ->pageTextContains('Saved the test_paragraph Paragraphs type');
  }

}

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.
ParagraphsTypesTest::$modules protected static property Modules to be enabled. Overrides ParagraphsTestBase::$modules
ParagraphsTypesTest::testAddParagraphTypes public function Tests adding the existing paragraph types.
ParagraphsTypesTest::testCreateParagraphType public function Ensures that a new paragraph type is created.