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',
33 protected function setUp() {
35 $this->installEntitySchema('user');
36 $this->installEntitySchema('paragraph');
37 $this->installSchema('system', ['sequences']);
38 \Drupal::moduleHandler()->loadInclude('paragraphs', 'install');
42 * Tests the behavior settings API.
44 public function testBehaviorSettings() {
45 // Create a paragraph type.
46 $paragraph_type = ParagraphsType::create(array(
47 'label' => 'test_text',
49 'behavior_plugins' => [
50 'test_text_color' => [
55 $paragraph_type->save();
57 // Create a paragraph and set its feature settings.
58 $paragraph = Paragraph::create([
59 'type' => 'test_text',
62 'test_text_color' => [
66 $paragraph->setAllBehaviorSettings($feature_settings);
69 // Load the paragraph and assert its stored feature settings.
70 $paragraph = Paragraph::load($paragraph->id());
71 $this->assertEquals($paragraph->getAllBehaviorSettings(), $feature_settings);
73 // Check the text color plugin settings summary.
74 $plugin = $paragraph->getParagraphType()->getBehaviorPlugins()->getEnabled();
75 $this->assertEquals($plugin['test_text_color']->settingsSummary($paragraph)[0], 'Text color: red');
77 // Update the value of an specific plugin.
78 $paragraph->setBehaviorSettings('test_text_color', ['text_color' => 'blue']);
81 // Assert the values have been updated.
82 $paragraph = Paragraph::load($paragraph->id());
83 $this->assertEquals($paragraph->getBehaviorSetting('test_text_color', 'text_color'), 'blue');
85 // Check the text color plugin settings summary.
86 $plugin = $paragraph->getParagraphType()->getBehaviorPlugins()->getEnabled();
87 $this->assertEquals($plugin['test_text_color']->settingsSummary($paragraph)[0], 'Text color: blue');