Error message

  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1075 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1079 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1075 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1079 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public function ParagraphsStylePluginTest::testStyleTemplate

Tests the style template picking.

File

paragraphs_collection/tests/src/FunctionalJavascript/ParagraphsStylePluginTest.php, line 746

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
    ->submitForm([], 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
    ->submitForm($edit, 'Save');

  // Assert that the Paragraph type template is used.
  $this
    ->assertSession()
    ->pageTextContainsOnce('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
    ->submitForm($edit, 'Save');

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