|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\paragraphs_editor\Unit\Plugin\dom_processor\data_processor { |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Entity\EntityViewBuilderInterface; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Field\EntityReferenceFieldItemListInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\Field\FieldConfigInterface; |
|
|
|
|
|
|
8
|
|
|
use Drupal\Core\Render\RendererInterface; |
|
|
|
|
|
|
9
|
|
|
use Drupal\Tests\UnitTestCase; |
|
|
|
|
|
|
10
|
|
|
use Drupal\Tests\dom_processor\Traits\DomProcessorTestTrait; |
|
|
|
|
|
|
11
|
|
|
use Drupal\Tests\paragraphs_editor\Traits\MockFieldValueManagerTrait; |
|
12
|
|
|
use Drupal\paragraphs\ParagraphInterface; |
|
|
|
|
|
|
13
|
|
|
use Drupal\paragraphs_editor\EditorFieldValue\FieldValueWrapperInterface; |
|
14
|
|
|
use Drupal\paragraphs_editor\Plugin\dom_processor\data_processor\ParagraphsEditorRenderer; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @coversDefaultClass \Drupal\paragraphs_editor\Plugin\dom_processor\data_processor\ParagraphsEditorRenderer |
|
18
|
|
|
* @group paragraphs_editor |
|
19
|
|
|
*/ |
|
20
|
|
|
class ParagraphsEditorRendererUnitTest extends UnitTestCase { |
|
21
|
|
|
use MockFieldValueManagerTrait; |
|
22
|
|
|
use DomProcessorTestTrait; |
|
23
|
|
|
|
|
24
|
1 |
|
public function testProcessPassThrough() { |
|
25
|
1 |
|
$entity_view_builder = $this->prophesize(EntityViewBuilderInterface::CLASS)->reveal(); |
|
26
|
1 |
|
$renderer = $this->prophesize(RendererInterface::CLASS)->reveal(); |
|
27
|
1 |
|
$field_value_manager = $this->createFieldValueManagerProphecy()->reveal(); |
|
28
|
1 |
|
$processor = new ParagraphsEditorRenderer($field_value_manager, $entity_view_builder, $renderer); |
|
29
|
1 |
|
$data = $this->createDomProcessorData('<div></div>', 'div'); |
|
30
|
1 |
|
$result = $this->createDomProcessorResult(); |
|
31
|
1 |
|
$processor->process($data, $result); |
|
32
|
1 |
|
$data = $this->createDomProcessorData('<widget></widget>', 'widget'); |
|
33
|
1 |
|
$result = $this->createDomProcessorResult(); |
|
34
|
1 |
|
$processor->process($data, $result); |
|
35
|
1 |
|
$this->assertTrue(true); |
|
36
|
1 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testProcess() { |
|
39
|
|
|
$languages = ['en', 'de']; |
|
40
|
|
|
|
|
41
|
|
|
foreach ($languages as $langcode) { |
|
42
|
|
|
$view_builder_prophecy = $this->prophesize(EntityViewBuilderInterface::CLASS); |
|
43
|
|
|
$renderer_prophecy = $this->prophesize(RendererInterface::CLASS); |
|
44
|
|
|
$manager_prophecy = $this->createFieldValueManagerProphecy(); |
|
45
|
|
|
|
|
46
|
|
|
$entities = []; |
|
47
|
|
|
|
|
48
|
|
|
$deeply_nested_prophecy = $this->createChildParagraphProphecy('uuid3', 3); |
|
49
|
|
|
$deeply_nested_field_definition = $this->createChildFieldDefinitionProphecy()->reveal(); |
|
50
|
|
|
$manager_prophecy->isParagraphsField($deeply_nested_field_definition)->willReturn(TRUE); |
|
51
|
|
|
$manager_prophecy->isParagraphsEditorField($deeply_nested_field_definition)->willReturn(FALSE); |
|
52
|
|
|
$prophecy = $this->createChildFieldItemsProphecy(); |
|
53
|
|
|
$prophecy->getFieldDefinition()->willReturn($deeply_nested_field_definition); |
|
54
|
|
|
$prophecy->referencedEntities()->willReturn([]); |
|
55
|
|
|
$deeply_nested_items = $prophecy->reveal(); |
|
|
|
|
|
|
56
|
|
|
$deeply_nested_items = $prophecy->reveal(); |
|
57
|
|
|
$deeply_nested_prophecy->getFields()->willReturn([$deeply_nested_items]); |
|
58
|
|
|
$deeply_nested_entity = $deeply_nested_prophecy->reveal(); |
|
59
|
|
|
|
|
60
|
|
|
$nested_prophecy = $this->createChildParagraphProphecy('uuid2', 2); |
|
61
|
|
|
$nested_field_definition = $this->createChildFieldDefinitionProphecy()->reveal(); |
|
62
|
|
|
$manager_prophecy->isParagraphsField($nested_field_definition)->willReturn(TRUE); |
|
63
|
|
|
$manager_prophecy->isParagraphsEditorField($nested_field_definition)->willReturn(FALSE); |
|
64
|
|
|
$prophecy = $this->createChildFieldItemsProphecy(); |
|
65
|
|
|
$prophecy->getFieldDefinition()->willReturn($nested_field_definition); |
|
66
|
|
|
$prophecy->referencedEntities()->willReturn([$deeply_nested_entity]); |
|
67
|
|
|
$nested_items = $prophecy->reveal(); |
|
68
|
|
|
$nested_prophecy->getFields()->willReturn([$nested_items]); |
|
69
|
|
|
$nested_entity = $nested_prophecy->reveal(); |
|
70
|
|
|
|
|
71
|
|
|
$child_prophecy = $this->createChildParagraphProphecy('uuid1', 1); |
|
72
|
|
|
$child_field_definition = $this->createChildFieldDefinitionProphecy()->reveal(); |
|
73
|
|
|
$prophecy = $this->createChildFieldItemsProphecy(); |
|
74
|
|
|
$prophecy->getFieldDefinition()->willReturn($child_field_definition); |
|
75
|
|
|
$child_items = $prophecy->reveal(); |
|
76
|
|
|
$child_prophecy->getFields()->willReturn([$child_items]); |
|
77
|
|
|
$child_entity = $child_prophecy->reveal(); |
|
78
|
|
|
$prophecy = $this->prophesize(FieldValueWrapperInterface::CLASS); |
|
|
|
|
|
|
79
|
|
|
$prophecy->getReferencedEntities()->willReturn(['uuid2' => $nested_entity]); |
|
80
|
|
|
$wrapper = $prophecy->reveal(); |
|
81
|
|
|
$manager_prophecy->isParagraphsField($child_field_definition)->willReturn(TRUE); |
|
82
|
|
|
$manager_prophecy->isParagraphsEditorField($child_field_definition)->willReturn(TRUE); |
|
83
|
|
|
$manager_prophecy->wrapItems($child_items)->willReturn($wrapper); |
|
84
|
|
|
|
|
85
|
|
|
$view_mode = 'test'; |
|
86
|
|
|
$entities[] = $child_entity; |
|
87
|
|
|
$entities[] = $nested_entity; |
|
88
|
|
|
foreach ($entities as $entity) { |
|
89
|
|
|
$view = [ |
|
90
|
|
|
'uuid' => $entity->uuid(), |
|
91
|
|
|
'view_mode' => $view_mode, |
|
92
|
|
|
'langcode' => $langcode, |
|
93
|
|
|
]; |
|
94
|
|
|
$view_builder_prophecy->view($entity, $view_mode, $langcode) |
|
95
|
|
|
->willReturn($view) |
|
96
|
|
|
->shouldBeCalledTimes(1); |
|
97
|
|
|
$renderer_prophecy->render($view) |
|
98
|
|
|
->willReturn(TRUE) |
|
99
|
|
|
->shouldBeCalledTimes(1); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$field_value_manager = $manager_prophecy->reveal(); |
|
103
|
|
|
$entity_view_builder = $view_builder_prophecy->reveal(); |
|
104
|
|
|
$renderer = $renderer_prophecy->reveal(); |
|
105
|
|
|
$processor = new ParagraphsEditorRenderer($field_value_manager, $entity_view_builder, $renderer); |
|
106
|
|
|
$data = $this->createDomProcessorData('<widget></widget>', 'widget', [ |
|
107
|
|
|
'context_id' => 'test_context', |
|
108
|
|
|
'paragraph' => [ |
|
109
|
|
|
'entity' => $child_entity, |
|
110
|
|
|
], |
|
111
|
|
|
'langcode' => $langcode, |
|
112
|
|
|
'settings' => [ |
|
113
|
|
|
'view_mode' => $view_mode, |
|
114
|
|
|
], |
|
115
|
|
|
]); |
|
116
|
|
|
$result = $this->createDomProcessorResult(); |
|
117
|
|
|
$processor->process($data, $result); |
|
118
|
|
|
|
|
119
|
|
|
$processor = new ParagraphsEditorRenderer($field_value_manager, $entity_view_builder, $renderer); |
|
120
|
|
|
$data = $this->createDomProcessorData('<widget></widget>', 'widget', [ |
|
121
|
|
|
'context_id' => 'test_context', |
|
122
|
|
|
'paragraph' => [ |
|
123
|
|
|
'entity' => $child_entity, |
|
124
|
|
|
], |
|
125
|
|
|
'langcode' => $langcode, |
|
126
|
|
|
'settings' => [ |
|
127
|
|
|
'view_mode' => $view_mode, |
|
128
|
|
|
], |
|
129
|
|
|
]); |
|
130
|
|
|
$result = $this->createDomProcessorResult(); |
|
131
|
|
|
$processor->process($data, $result); |
|
132
|
|
|
$this->assertTrue(true); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
1 |
View Code Duplication |
protected function createFieldValueManagerProphecy() { |
|
|
|
|
|
|
137
|
1 |
|
return $this->createFieldValueManager([ |
|
138
|
1 |
|
'elements' => [ |
|
139
|
|
|
'widget' => [ |
|
140
|
|
|
'tag' => 'widget', |
|
141
|
|
|
'attributes' => [ |
|
142
|
|
|
'data-context' => '<context>', |
|
143
|
|
|
'data-uuid' => '<uuid>', |
|
144
|
|
|
], |
|
145
|
|
|
'selector' => 'widget', |
|
146
|
|
|
], |
|
147
|
|
|
'field' => [ |
|
148
|
|
|
'tag' => 'field', |
|
149
|
|
|
'attributes' => [ |
|
150
|
|
|
'data-name' => '<name>', |
|
151
|
|
|
'data-editable' => '<editable>', |
|
152
|
|
|
'data-context' => '<context>', |
|
153
|
|
|
], |
|
154
|
|
|
'selector' => 'field', |
|
155
|
|
|
], |
|
156
|
|
|
], |
|
157
|
1 |
|
], TRUE); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
View Code Duplication |
protected function createChildFieldDefinitionProphecy() { |
|
|
|
|
|
|
161
|
|
|
$prophecy = $this->prophesize(FieldConfigInterface::CLASS); |
|
162
|
|
|
$prophecy->getName()->willReturn('field_test'); |
|
163
|
|
|
$prophecy->id()->willReturn('paragraph.field_test'); |
|
164
|
|
|
return $prophecy; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
protected function createChildFieldItemsProphecy() { |
|
168
|
|
|
$prophecy = $this->prophesize(EntityReferenceFieldItemListInterface::CLASS); |
|
169
|
|
|
return $prophecy; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
protected function createChildParagraphProphecy($uuid, $vid) { |
|
173
|
|
|
$prophecy = $this->prophesize(ParagraphInterface::CLASS); |
|
174
|
|
|
$prophecy->uuid()->willReturn($uuid); |
|
175
|
|
|
$prophecy->getRevisionId()->willReturn($vid); |
|
176
|
|
|
return $prophecy; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
namespace { |
|
183
|
|
|
if (!function_exists('drupal_static')) { |
|
184
|
|
|
function &drupal_static() { |
|
185
|
|
|
static $cache = []; |
|
186
|
|
|
return $cache; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths