3 namespace Drupal\Tests\paragraphs\Kernel;
5 use Drupal\paragraphs\Entity\Paragraph;
6 use Drupal\paragraphs\Entity\ParagraphsType;
7 use Drupal\KernelTests\KernelTestBase;
10 * Tests the behavior plugins API.
14 class ParagraphsBehaviorPluginsTest extends KernelTestBase {
21 public static $modules = [
26 'entity_reference_revisions',
34 protected function setUp() {
36 $this->installEntitySchema('user');
37 $this->installEntitySchema('paragraph');
38 $this->installSchema('system', ['sequences']);
39 \Drupal::moduleHandler()->loadInclude('paragraphs', 'install');
43 * Tests the behavior settings API.
45 public function testBehaviorSettings() {
46 // Create a paragraph type.
47 $paragraph_type = ParagraphsType::create(array(
48 'label' => 'test_text',
50 'behavior_plugins' => [
51 'test_text_color' => [
56 $paragraph_type->save();
58 // Create a paragraph and set its feature settings.
59 $paragraph = Paragraph::create([
60 'type' => 'test_text',
63 'test_text_color' => [
67 $paragraph->setAllBehaviorSettings($feature_settings);
70 // Load the paragraph and assert its stored feature settings.
71 $paragraph = Paragraph::load($paragraph->id());
72 $this->assertEquals($paragraph->getAllBehaviorSettings(), $feature_settings);
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');
78 // Update the value of an specific plugin.
79 $paragraph->setBehaviorSettings('test_text_color', ['text_color' => 'blue']);
82 // Assert the values have been updated.
83 $paragraph = Paragraph::load($paragraph->id());
84 $this->assertEquals($paragraph->getBehaviorSetting('test_text_color', 'text_color'), 'blue');
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');