class ParagraphsCollectionDemoTest

Test the demo for Paragraphs Collection.

@group paragraphs_collection_demo

Hierarchy

Expanded class hierarchy of ParagraphsCollectionDemoTest

File

paragraphs_collection/modules/paragraphs_collection_demo/tests/src/Functional/ParagraphsCollectionDemoTest.php, line 14

Namespace

Drupal\Tests\paragraphs_collection_demo\Functional
View source
class ParagraphsCollectionDemoTest extends ParagraphsTestBase {

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

  /**
   * Checks that generic container is created with all plugins enabled.
   */
  public function testConfiguration() {
    $this
      ->loginAsAdmin([
      'administer content types',
      'access administration pages',
      'access content overview',
    ]);

    // Check for pre-configured paragraph type.
    $this
      ->drupalGet('admin/structure/paragraphs_type/container');
    $this
      ->assertSession()
      ->pageTextContains('Container');
    $this
      ->assertSession()
      ->checkboxChecked('edit-behavior-plugins-style-enabled');
    $this
      ->assertSession()
      ->checkboxChecked('edit-behavior-plugins-style-settings-groups-general-group');
    $this
      ->assertSession()
      ->checkboxNotChecked('edit-behavior-plugins-style-settings-groups-slideshow-group');
    $options = $this
      ->xpath('//input[contains(@id, :id)]', [
      ':id' => 'edit-behavior-plugins-style-settings-groups',
    ]);
    $this
      ->assertCount(2, $options);

    // @todo When other plugins are available, add assertion.
    $this
      ->drupalGet('admin/structure/paragraphs_type/text');
    $this
      ->assertSession()
      ->checkboxChecked('edit-behavior-plugins-language-enabled');

    // Check that demo content has paragraph with enabled plugins.
    $this
      ->drupalGet('admin/content');
    $this
      ->clickLink('Paragraphs Collection Demo Article!');
    $this
      ->assertSession()
      ->responseContains('Paragraphs');
    $this
      ->drupalGet('');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->assertSession()
      ->linkExists('Paragraphs Collection Demo Article!');
    $this
      ->assertSession()
      ->pageTextContains('This is content from the library. We can reuse it multiple times without duplicating it.');
  }

  /**
   * Tests the demo styles for the style plugin.
   */
  public function testDemoStyles() {
    $this
      ->loginAsAdmin([
      'administer content types',
      'access administration pages',
      'access content overview',
      'administer site configuration',
      'create paragraphed_content_demo content',
      'edit any paragraphed_content_demo content',
      'delete any paragraphed_content_demo content',
    ]);

    // Create text paragraph.
    $text_paragraph = Paragraph::create([
      'type' => 'text',
      'paragraphs_text' => [
        'value' => '<p>Introduces a new set of styles for the style plugin.</p>',
        'format' => 'basic_html',
      ],
    ]);
    $text_paragraph
      ->save();

    // Create container that contains the text paragraph.
    $paragraph = Paragraph::create([
      'title' => 'Styled paragraph',
      'type' => 'container',
      'paragraphs_container_paragraphs' => [
        $text_paragraph,
      ],
    ]);

    // Add demo content with one paragraph.
    $node = Node::create([
      'type' => 'paragraphed_content_demo',
      'title' => 'Style plugin test',
      'langcode' => 'en',
      'uid' => '0',
      'status' => 1,
      'field_paragraphs_demo' => [
        $paragraph,
      ],
    ]);
    $node
      ->save();

    // Use green style for this container.
    $paragraph
      ->setBehaviorSettings('style', [
      'styles' => [
        'general_group' => 'paragraphs-green',
      ],
    ]);
    $paragraph
      ->save();

    // Check the applied style on the paragraph.
    $this
      ->drupalGet('node/' . $node
      ->id());
    $this
      ->assertSession()
      ->responseContains('paragraphs-behavior-background');
    $this
      ->assertSession()
      ->responseContains('paragraphs-behavior-style--paragraphs-green');
    $this
      ->assertSession()
      ->responseContains('paragraph--type--container');
    $this
      ->assertSession()
      ->responseContains('paragraph--view-mode--default');

    // Use blue style for the container.
    $paragraph
      ->setBehaviorSettings('style', [
      'styles' => [
        'general_group' => 'paragraphs-blue',
      ],
    ]);
    $paragraph
      ->save();

    // Check that the blue style is applied on the paragraph.
    $this
      ->drupalGet('node/' . $node
      ->id());
    $this
      ->assertSession()
      ->responseContains('paragraphs-behavior-background');
    $this
      ->assertSession()
      ->responseContains('paragraphs-behavior-style--paragraphs-blue');
    $this
      ->assertSession()
      ->responseContains('paragraph--type--container');
    $this
      ->assertSession()
      ->responseContains('paragraph--view-mode--default');
  }

  /**
   * Tests the "Paragraphs Collection Demo Article!" demo node.
   */
  public function testDemoNode() {
    $this
      ->loginAsAdmin([
      'edit any paragraphed_content_demo content',
      'administer lockable paragraph',
      'use text format basic_html',
    ]);

    // Edit and save "Paragraphs Collection Demo Article!" to test validity.
    $this
      ->drupalGet('node/1/edit');
    $this
      ->assertSession()
      ->pageTextContains('Edit Paragraphed Content Demo Paragraphs Collection Demo Article!');
    $this
      ->submitForm([], 'field_paragraphs_demo_0_edit');
    $this
      ->submitForm([], 'field_paragraphs_demo_0_subform_paragraphs_container_paragraphs_0_duplicate');
    $this
      ->submitForm([], 'Save');
    $this
      ->assertSession()
      ->pageTextContains('Paragraphed Content Demo Paragraphs Collection Demo Article! has been updated.');
  }

  /**
   * Tests that demo node is using experimental widget.
   */
  public function testUsingExperimentalWidget() {
    $this
      ->loginAsAdmin([
      'edit any paragraphed_content_demo content',
    ]);
    $this
      ->drupalGet('admin/structure/types/manage/paragraphed_content_demo/form-display');
    $this
      ->assertTrue($this
      ->assertSession()
      ->optionExists('edit-fields-field-paragraphs-demo-type', 'paragraphs')
      ->isSelected());
  }

  /**
   * Tests paragraph types.
   */
  public function testParagraphTypes() {
    $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_image_add_more');
    $this
      ->submitForm([], 'field_paragraphs_image_text_add_more');
    $image = current($this
      ->getTestFiles('image'));
    $file_system = \Drupal::service('file_system');
    $edit = [
      'title[0][value]' => 'Paragraph types example',
      'files[field_paragraphs_0_subform_paragraphs_image_0]' => $file_system
        ->realpath($image->uri),
      'field_paragraphs[1][subform][paragraphs_text][0][value]' => 'Text test with image',
      'files[field_paragraphs_1_subform_paragraphs_image_0]' => $file_system
        ->realpath($image->uri),
    ];
    $this
      ->submitForm($edit, 'Save');

    // Asserts the text and image type.
    $this
      ->assertSession()
      ->pageTextContains('Text test with image');
    $this
      ->assertSession()
      ->responseContains($image->filename);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsCollectionDemoTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules
ParagraphsCollectionDemoTest::testConfiguration public function Checks that generic container is created with all plugins enabled.
ParagraphsCollectionDemoTest::testDemoNode public function Tests the "Paragraphs Collection Demo Article!" demo node.
ParagraphsCollectionDemoTest::testDemoStyles public function Tests the demo styles for the style plugin.
ParagraphsCollectionDemoTest::testParagraphTypes public function Tests paragraph types.
ParagraphsCollectionDemoTest::testUsingExperimentalWidget public function Tests that demo node is using experimental widget.
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::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.