Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / tests / src / Kernel / ParagraphsBehaviorPluginsTest.php
1 <?php
2
3 namespace Drupal\Tests\paragraphs\Kernel;
4
5 use Drupal\paragraphs\Entity\Paragraph;
6 use Drupal\paragraphs\Entity\ParagraphsType;
7 use Drupal\KernelTests\KernelTestBase;
8
9 /**
10  * Tests the behavior plugins API.
11  *
12  * @group paragraphs
13  */
14 class ParagraphsBehaviorPluginsTest extends KernelTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'paragraphs',
23     'user',
24     'system',
25     'field',
26     'entity_reference_revisions',
27     'paragraphs_test',
28     'file',
29   ];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36     $this->installEntitySchema('user');
37     $this->installEntitySchema('paragraph');
38     $this->installSchema('system', ['sequences']);
39     \Drupal::moduleHandler()->loadInclude('paragraphs', 'install');
40   }
41
42   /**
43    * Tests the behavior settings API.
44    */
45   public function testBehaviorSettings() {
46     // Create a paragraph type.
47     $paragraph_type = ParagraphsType::create(array(
48       'label' => 'test_text',
49       'id' => 'test_text',
50       'behavior_plugins' => [
51         'test_text_color' => [
52           'enabled' => TRUE,
53         ]
54       ],
55     ));
56     $paragraph_type->save();
57
58     // Create a paragraph and set its feature settings.
59     $paragraph = Paragraph::create([
60       'type' => 'test_text',
61     ]);
62     $feature_settings = [
63       'test_text_color' => [
64         'text_color' => 'red'
65       ],
66     ];
67     $paragraph->setAllBehaviorSettings($feature_settings);
68     $paragraph->save();
69
70     // Load the paragraph and assert its stored feature settings.
71     $paragraph = Paragraph::load($paragraph->id());
72     $this->assertEquals($paragraph->getAllBehaviorSettings(), $feature_settings);
73
74     // Check the text color plugin settings summary.
75     $plugin = $paragraph->getParagraphType()->getBehaviorPlugins()->getEnabled();
76     $this->assertEquals($plugin['test_text_color']->settingsSummary($paragraph)[0], 'Text color: red');
77
78     // Update the value of an specific plugin.
79     $paragraph->setBehaviorSettings('test_text_color', ['text_color' => 'blue']);
80     $paragraph->save();
81
82     // Assert the values have been updated.
83     $paragraph = Paragraph::load($paragraph->id());
84     $this->assertEquals($paragraph->getBehaviorSetting('test_text_color', 'text_color'), 'blue');
85
86     // Check the text color plugin settings summary.
87     $plugin = $paragraph->getParagraphType()->getBehaviorPlugins()->getEnabled();
88     $this->assertEquals($plugin['test_text_color']->settingsSummary($paragraph)[0], 'Text color: blue');
89
90   }
91
92 }