public function ParagraphsCollectionDemoTest::testDemoStyles

Tests the demo styles for the style plugin.

File

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

Class

ParagraphsCollectionDemoTest
Test the demo for Paragraphs Collection.

Namespace

Drupal\Tests\paragraphs_collection_demo\Functional

Code

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');
}