Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / tests / src / Functional / ParagraphsExperimentalBehaviorsTest.php
1 <?php
2
3 namespace Drupal\Tests\paragraphs\Functional;
4
5 use Drupal\paragraphs\Tests\Classic\ParagraphsCoreVersionUiTestTrait;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
8
9 /**
10  * Tests support for Paragraphs behavior plugins.
11  *
12  * @group paragraphs
13  */
14 class ParagraphsExperimentalBehaviorsTest extends BrowserTestBase {
15
16   use ParagraphsCoreVersionUiTestTrait;
17   use ParagraphsTestBaseTrait;
18
19   /**
20    * Modules to enable.
21    *
22    * @var string[]
23    */
24   public static $modules = [
25     'node',
26     'paragraphs_test',
27   ];
28
29   /**
30    * Tests that behavior settings have empty leaves removed before being saved.
31    */
32   public function testBehaviorPluginsSettingsFiltering() {
33     $this->addParagraphedContentType('paragraphed_test');
34
35     $admin = $this->drupalCreateUser([
36       'create paragraphed_test content',
37       'edit any paragraphed_test content',
38       'edit behavior plugin settings',
39       'administer paragraphs types',
40     ]);
41     $this->drupalLogin($admin);
42
43     // Add a text Paragraph type.
44     $paragraph_type = 'text_paragraph';
45     $this->addParagraphsType($paragraph_type);
46     $this->addFieldtoParagraphType($paragraph_type, 'field_text', 'text_long');
47
48     // Enable the "Test bold text plugin" to have a behavior form.
49     $this->drupalGet('/admin/structure/paragraphs_type/' . $paragraph_type);
50     $edit = [
51       'behavior_plugins[test_bold_text][enabled]' => TRUE,
52     ];
53     $this->drupalPostForm(NULL, $edit, 'Save');
54
55     // Add a note that uses the behavior plugin give it an empty setting.
56     $this->drupalGet('node/add/paragraphed_test');
57     $edit = [
58       'title[0][value]' => 'Test Node',
59       'field_paragraphs[0][subform][field_text][0][value]' => 'Non-bold text',
60       'field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]' => FALSE,
61     ];
62     $this->drupalPostForm(NULL, $edit, 'Save');
63     $bolded_elements = $this->getSession()->getPage()->findAll('css', '.bold_plugin_text');
64     $this->assertFalse(count($bolded_elements), 'Test plugin did not add a CSS class.');
65
66     // Check that empty leaves are not saved in the behavior settings.
67     $node = $this->getNodeByTitle('Test Node', TRUE);
68     /** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
69     $paragraph = $node->get('field_paragraphs')->entity;
70     $behavior_settings = $paragraph->getBehaviorSetting('test_bold_text', []);
71     $expected_settings = [];
72     self::assertEquals($expected_settings, $behavior_settings);
73
74     // Save a non-empty setting.
75     $this->drupalGet('node/' . $node->id() . '/edit');
76     $edit = [
77       'field_paragraphs[0][subform][field_text][0][value]' => 'Bold text',
78       'field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]' => TRUE,
79     ];
80     $this->drupalPostForm(NULL, $edit, 'Save');
81     $bolded_elements = $this->getSession()->getPage()->findAll('css', '.bold_plugin_text');
82     $this->assertTrue(count($bolded_elements), 'Test plugin added a CSS class.');
83
84     // Check that non-empty leaves are saved in the behavior settings.
85     $node = $this->getNodeByTitle('Test Node', TRUE);
86     /** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
87     $paragraph = $node->get('field_paragraphs')->entity;
88     $behavior_settings = $paragraph->getBehaviorSetting('test_bold_text', []);
89     $expected_settings = [
90       'bold_text' => 1,
91     ];
92     self::assertEquals($expected_settings, $behavior_settings);
93   }
94
95 }