-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathParagraphsBehaviorTest.php
More file actions
91 lines (79 loc) · 2.24 KB
/
Copy pathParagraphsBehaviorTest.php
File metadata and controls
91 lines (79 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Drupal\Tests\thunder_gqls\Kernel\DataProducer;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\Entity\ParagraphsType;
/**
* Tests the paragraphs behavior data producer.
*
* @group Thunder
*/
class ParagraphsBehaviorTest extends GraphQLTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'thunder_gqls',
'paragraphs',
'entity_reference_revisions',
'paragraphs_test',
'file',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('paragraph');
\Drupal::moduleHandler()->loadInclude('paragraphs', 'install');
}
/**
* Tests the behavior settings API.
*/
public function testBehaviorSettings(): void {
// Create a paragraph type.
$paragraph_type = ParagraphsType::create([
'label' => 'test_text',
'id' => 'test_text',
'behavior_plugins' => [
'test_text_color' => [
'enabled' => TRUE,
],
],
]);
$paragraph_type->save();
// Create a paragraph and set empty feature settings to test plugin_default.
$paragraph = Paragraph::create([
'type' => 'test_text',
]);
$feature_settings = [];
$paragraph->setAllBehaviorSettings($feature_settings);
$paragraph->save();
$result = $this->executeDataProducer('paragraph_behavior', [
'paragraph' => $paragraph,
'behavior_plugin_id' => 'test_text_color',
'behavior_plugin_key' => 'text_color',
'behavior_plugin_default' => NULL,
]);
$this->assertNull($result);
// Create a paragraph and set its feature settings.
$paragraph = Paragraph::create([
'type' => 'test_text',
]);
$feature_settings = [
'test_text_color' => [
'text_color' => 'red',
],
];
$paragraph->setAllBehaviorSettings($feature_settings);
$paragraph->save();
$result = $this->executeDataProducer('paragraph_behavior', [
'paragraph' => $paragraph,
'behavior_plugin_id' => 'test_text_color',
'behavior_plugin_key' => 'text_color',
'behavior_plugin_default' => NULL,
]);
// Now we should not get the default value.
$this->assertEquals('red', $result);
}
}