You are here

public function ParagraphsStylePluginTest::testStyleTemplate in Paragraphs Collection 8

Tests the style template picking.

File

tests/src/FunctionalJavascript/ParagraphsStylePluginTest.php, line 741

Class

ParagraphsStylePluginTest
Tests the style selection plugin.

Namespace

Drupal\Tests\paragraphs_collection\FunctionalJavascript

Code

public function testStyleTemplate() {

  // Install paragraphs collection test to use test style plugins.
  \Drupal::service('module_installer')
    ->install([
    'paragraphs_collection_test',
  ]);
  \Drupal::service('theme_installer')
    ->install([
    'paragraphs_collection_test_theme_a',
  ]);
  $theme_config = \Drupal::configFactory()
    ->getEditable('system.theme');
  $theme_config
    ->set('default', 'paragraphs_collection_test_theme_a');
  $theme_config
    ->save();
  $this
    ->addParagraphedContentType('paragraphed_test', 'paragraphs');
  $this
    ->loginAsAdmin([
    'edit any paragraphed_test content',
    'edit behavior plugin settings',
  ]);

  // Enable the style plugin.
  $this
    ->drupalGet('admin/structure/paragraphs_type/separator');
  $this
    ->click('#edit-behavior-plugins-style-enabled');
  $this
    ->click('#edit-behavior-plugins-style-settings-groups-regular-test-group');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->drupalPostForm(NULL, [], t('Save'));

  // Add a Separator paragraph and check if it uses the paragraph type
  // template.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->pressButton('List additional actions');
  $page
    ->pressButton('paragraphs_separator_add_more');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $edit = [
    'title[0][value]' => 'test_title',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Assert that the Paragraph type template is used.
  $this
    ->assertUniqueText('paragraph-type-template');
  $this
    ->assertSession()
    ->pageTextNotContains('paragraph-style-template');

  // Set the style for the paragraphs and check if it uses the style template.
  $node = $this
    ->getNodeByTitle('test_title');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $page
    ->clickLink('Behavior');
  $edit = [
    'paragraphs[0][behavior_plugins][style][style_wrapper][styles][regular_test_group]' => 'style-overridden',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Assert that the Style template is used.
  $this
    ->assertUniqueText('paragraph-style-template');
  $this
    ->assertSession()
    ->pageTextNotContains('paragraph-type-template');
}