0ded68125a339ab53f4c497919f4761d0df82277
[yaffs-website] / web / modules / contrib / paragraphs / tests / src / Kernel / ParagraphsTypeHasEnabledBehaviorPluginTest.php
1 <?php
2
3 namespace Drupal\Tests\paragraphs\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\paragraphs\Entity\ParagraphsType;
7
8 /**
9  * Tests the ParagraphsType entity hasEnabledBehaviorPlugin functionality.
10  *
11  * @group paragraphs
12  */
13 class ParagraphsTypeHasEnabledBehaviorPluginTest extends KernelTestBase {
14
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'paragraphs',
23     'user',
24     'paragraphs_test',
25   ];
26
27   /**
28    * ParagraphsType entity build in setUp()
29    *
30    * @var ParagraphsType
31    */
32   protected $paragraphsType;
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function setUp() {
38     parent::setUp();
39     $this->installEntitySchema('user');
40     $this->installEntitySchema('paragraph');
41     \Drupal::moduleHandler()->loadInclude('paragraphs', 'install');
42
43     // Create a paragraph with an enabled and disabled plugin.
44     $this->paragraphsType = ParagraphsType::create([
45       'label' => 'test_text',
46       'id' => 'test_text',
47       'behavior_plugins' => [
48         'test_text_color' => [
49           'enabled' => TRUE,
50         ],
51         'test_dummy_behavior' => [
52           'enabled' => FALSE,
53         ],
54       ],
55     ]);
56     $this->paragraphsType->save();
57   }
58
59   /**
60    * Tests the behavior settings API.
61    */
62   public function testValidPluginIds() {
63     $this->assertTrue($this->paragraphsType->hasEnabledBehaviorPlugin('test_text_color'));
64     $this->assertFalse($this->paragraphsType->hasEnabledBehaviorPlugin('test_dummy_behavior'));
65   }
66
67   /**
68    * Test that invalid plugin id's return false.
69    */
70   public function testInvalidPluginId() {
71     $this->assertFalse($this->paragraphsType->hasEnabledBehaviorPlugin('i_do_not_exist'));
72   }
73
74 }