Tests style settings summary.
public function testStyleSettingsSummary() {
// Install Paragraph Collection Test in order to have styles.
\Drupal::service('module_installer')
->install([
'paragraphs_collection_test',
]);
$this
->addParagraphedContentType('paragraphed_test');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
'edit behavior plugin settings',
]);
// Create text paragraph.
$text_paragraph = Paragraph::create([
'type' => 'text',
'paragraphs_text' => [
'value' => '<p>Test text 1.</p>',
'format' => 'basic_html',
],
]);
$text_paragraph
->save();
// Create a container paragraph for the text paragraph.
$paragraph = Paragraph::create([
'title' => 'Demo Paragraph',
'type' => 'container',
'paragraphs_container_paragraphs' => [
$text_paragraph,
],
]);
$paragraph
->save();
// Create a node with the paragraphs content.
$node = Node::create([
'title' => 'Style plugin test',
'type' => 'paragraphed_test',
'field_paragraphs' => [
$paragraph,
],
]);
$node
->save();
// Check the empty summary.
$behavior_plugins = $paragraph
->getParagraphType()
->get('behavior_plugins');
$behavior_plugins['style'] = [
'enabled' => TRUE,
'groups' => [
'bold_test_group' => [
'default' => '',
],
],
];
$paragraph
->getParagraphType()
->set('behavior_plugins', $behavior_plugins);
$paragraph
->getParagraphType()
->save();
$style_plugin = $paragraph
->getParagraphType()
->getEnabledBehaviorPlugins()['style'];
$this
->assertEquals([], $style_plugin
->settingsSummary($paragraph));
// Use bold style for this container.
$paragraph
->setBehaviorSettings('style', [
'styles' => [
'bold_test_group' => 'bold',
],
]);
$paragraph
->save();
$this
->assertEquals([
[
'label' => 'Bold CONTEXT',
'value' => 'Bold',
],
], $style_plugin
->settingsSummary($paragraph));
$this
->drupalGet('admin/structure/paragraphs_type/' . $paragraph
->getParagraphType()
->id());
$this
->assertSession()
->pageTextContains('Bold Test Group');
// Check the settings summary in a closed mode.
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/form-display');
$this
->submitForm([], 'field_paragraphs_settings_edit');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->submitForm([
'fields[field_paragraphs][settings_edit_form][settings][edit_mode]' => 'closed',
], t('Update'));
$this
->submitForm([], 'Save');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->responseContains('edit-field-paragraphs-0-top-icons');
$this
->assertSession()
->responseContains('<span class="summary-content">Test text 1.</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold CONTEXT</span>Bold');
// Configure style bold as default.
$this
->drupalGet('admin/structure/paragraphs_type/' . $paragraph
->getType());
$edit = [
'behavior_plugins[style][settings][groups_defaults][bold_test_group][default]' => 'bold',
];
$this
->submitForm($edit, t('Save'));
// Check that the settings summary does not show the default style.
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->responseContains('<span class="summary-content">Test text 1.');
$this
->assertSession()
->responseNotContains('Style: Bold');
$this
->assertSession()
->responseNotContains('Style: - Bold -');
}