|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\paragraphs_editor\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Component\Uuid; |
|
6
|
|
|
use Drupal\Core\Field\FieldConfigInterface; |
|
7
|
|
|
use Drupal\paragraphs\ParagraphInterface; |
|
8
|
|
|
use Drupal\paragraphs_editor\EditBuffer\EditBufferInterface; |
|
9
|
|
|
use Drupal\paragraphs_editor\EditBuffer\EditBufferItemInterface; |
|
10
|
|
|
use Drupal\paragraphs_editor\EditorCommand\CommandContextFactoryInterface; |
|
11
|
|
|
use Drupal\paragraphs_editor\EditorCommand\CommandContextInterface; |
|
12
|
|
|
use Prophecy\Argument; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
trait MockContextTrait { |
|
15
|
|
|
|
|
16
|
17 |
|
protected function mockParagraphDefaults() { |
|
17
|
|
|
return [ |
|
18
|
17 |
|
'id' => rand(), |
|
|
|
|
|
|
19
|
17 |
|
'uuid' => (new Uuid\Php())->generate(), |
|
20
|
17 |
|
'bundle' => 'default', |
|
21
|
|
|
]; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
5 |
|
protected function contextDefaults() { |
|
25
|
5 |
|
$prophecy = $this->prophesize(FieldConfigInterface::CLASS); |
|
|
|
|
|
|
26
|
5 |
|
$prophecy->id()->willReturn('default_field_id'); |
|
27
|
|
|
return [ |
|
28
|
5 |
|
'context_id' => md5(rand() . rand() . rand()), |
|
|
|
|
|
|
29
|
|
|
'bundle_filter' => [], |
|
30
|
|
|
'entity' => NULL, |
|
31
|
5 |
|
'field_definition' => $prophecy->reveal(), |
|
32
|
|
|
'edit_buffer' => [], |
|
33
|
|
|
'valid' => TRUE, |
|
34
|
|
|
'settings' => [], |
|
35
|
|
|
]; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function editBufferDefaults() { |
|
39
|
|
|
return [ |
|
40
|
|
|
'uid' => 1, |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
5 |
|
protected function createContext(array $options = []) { |
|
45
|
5 |
|
$options += $this->contextDefaults(); |
|
46
|
5 |
|
$options['edit_buffer']['context_id'] = $options['context_id']; |
|
47
|
|
|
|
|
48
|
5 |
|
$prophecy = $this->prophesize(CommandContextInterface::CLASS); |
|
|
|
|
|
|
49
|
5 |
|
$prophecy->getEntity()->willReturn($options['entity']); |
|
50
|
5 |
|
$prophecy->getFieldConfig()->willReturn($options['field_definition']); |
|
51
|
|
|
|
|
52
|
5 |
|
if (!empty($options['bundle_filter'])) { |
|
53
|
|
|
$prophecy->isValidBundle(Argument::any())->will(function ($args) use ($options) { |
|
54
|
|
|
return isset(array_flip($options)[$args[0]]); |
|
55
|
|
|
}); |
|
56
|
|
|
} |
|
57
|
|
|
else { |
|
58
|
5 |
|
$prophecy->isValidBundle(Argument::any())->willReturn(TRUE); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$prophecy->getEditBuffer()->willReturn($this->createEditBuffer($options['edit_buffer'])); |
|
62
|
|
|
$prophecy->getContextString()->willReturn($options['context_id']); |
|
63
|
|
|
|
|
64
|
|
|
$prophecy->getTemporary(Argument::any())->willReturn(NULL); |
|
65
|
|
|
$prophecy->setTemporary(Argument::cetera())->will(function ($args, $prophecy) { |
|
66
|
|
|
$prophecy->getTemporary($args[0])->willReturn($args[1]); |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
$prophecy->isValid()->willReturn($options['valid']); |
|
70
|
|
|
|
|
71
|
|
|
$prophecy->getPlugin(Argument::any())->willReturn(NULL); |
|
72
|
|
|
$prophecy->setPlugin(Argument::any())->will(function ($args, $prophecy) { |
|
73
|
|
|
$prophecy->getPlugin($args[0])->willReturn($args[1]); |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
$prophecy->getSettings()->willReturn($options['settings']); |
|
77
|
|
|
$prophecy->getSetting(Argument::any())->willReturn(NULL); |
|
78
|
|
|
foreach ($options['settings'] as $key => $val) { |
|
79
|
|
|
$prophecy->getSetting($key)->willReturn($val); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$prophecy->getAdditionalContext(Argument::any())->willReturn(NULL); |
|
83
|
|
|
$prophecy->addAdditionalContext(Argument::cetera())->will(function ($args, $prophecy) { |
|
84
|
|
|
$prophecy->getAdditionalContext($args[0])->willReturn($args[1]); |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
return $prophecy->reveal(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
15 |
|
protected function createContextFactory(array $options = [], $return_prophecy = FALSE) { |
|
91
|
15 |
|
$prophecy_factory = $this; |
|
92
|
15 |
|
$prophecy = $this->prophesize(CommandContextFactoryInterface::CLASS); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$prophecy->get(Argument::any())->will(function ($args) use ($options, $prophecy_factory) { |
|
95
|
4 |
|
if (!empty($options['contexts'][$args[0]])) { |
|
96
|
|
|
return $prophecy_factory->createContext($options['contexts'][$args[0]]); |
|
97
|
|
|
} |
|
98
|
|
|
else { |
|
99
|
4 |
|
return $prophecy_factory->createContext(); |
|
100
|
|
|
} |
|
101
|
15 |
|
}); |
|
102
|
15 |
|
return $return_prophecy ? $prophecy : $prophecy->reveal(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
protected function createEditBuffer(array $options = []) { |
|
106
|
|
|
$options += $this->editBufferDefaults(); |
|
107
|
|
|
$prophecy = $this->prophesize(EditBufferInterface::CLASS); |
|
|
|
|
|
|
108
|
|
|
$prophecy->getUser()->willReturn($options['uid']); |
|
109
|
|
|
$prophecy->getContextString()->willReturn($options['context_id']); |
|
110
|
|
|
|
|
111
|
|
|
$prophecy->getItem(Argument::any())->willReturn(NULL); |
|
112
|
|
|
|
|
113
|
|
|
$prophecy->setItem(Argument::any())->will(function ($args, $prophecy) { |
|
114
|
|
|
$prophecy->getItem($item->getEntity()->uuid())->willReturn($item->getEntity()); |
|
|
|
|
|
|
115
|
|
|
}); |
|
116
|
|
|
|
|
117
|
|
|
$prophecy_factory = $this; |
|
118
|
|
|
$prophecy->createItem(Argument::any())->will(function ($args, $prophecy) use($prophecy_factory) { |
|
119
|
|
|
$item_prophecy = $prophecy_factory->prophesize(EditBufferItemInterface::CLASS); |
|
|
|
|
|
|
120
|
|
|
$item_prophecy->getEntity()->willReturn($args[0]); |
|
121
|
|
|
$item_prophecy->overwrite(Argument::any())->will(function ($args, $item_prophecy) { |
|
122
|
|
|
$item_prophecy->getEntity()->willReturn($args[0]); |
|
123
|
|
|
}); |
|
124
|
|
|
$item_prophecy->save()->willReturn(NULL); |
|
125
|
|
|
$item = $item_prophecy->reveal(); |
|
126
|
|
|
|
|
127
|
|
|
$prophecy->getItem($args[0]->uuid())->willReturn($item); |
|
128
|
|
|
|
|
129
|
|
|
return $item; |
|
130
|
|
|
}); |
|
131
|
|
|
|
|
132
|
|
|
$edit_buffer = $prophecy->reveal(); |
|
133
|
|
|
|
|
134
|
|
|
if (!empty($options['default_items'])) { |
|
135
|
|
|
foreach ($options['default_items'] as $entity) { |
|
136
|
|
|
$edit_buffer->createItem($entity); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $edit_buffer; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
17 |
|
protected function createMockParagraph(array $options = []) { |
|
144
|
17 |
|
$options += $this->mockParagraphDefaults(); |
|
145
|
17 |
|
$prophecy = $this->prophesize(ParagraphInterface::CLASS); |
|
|
|
|
|
|
146
|
17 |
|
$prophecy->id()->willReturn($options['id']); |
|
147
|
17 |
|
$prophecy->uuid()->willReturn($options['uuid']); |
|
148
|
17 |
|
$prophecy->bundle()->willReturn($options['bundle']); |
|
149
|
17 |
|
return $prophecy->reveal(); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
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