|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ACFComposer\Tests; |
|
4
|
|
|
|
|
5
|
|
|
require_once dirname(__DIR__) . '/lib/ACFComposer/ResolveConfig.php'; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use Brain\Monkey\Filters; |
|
|
|
|
|
|
9
|
|
|
use ACFComposer\ResolveConfig; |
|
10
|
|
|
|
|
11
|
|
|
class ResolveConfigForFieldGroupTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testForFieldGroupWithValidConfig() |
|
14
|
|
|
{ |
|
15
|
|
|
$filterName = 'ACFComposer/Fields/someField'; |
|
16
|
|
|
$fieldConfig = [ |
|
17
|
|
|
'name' => 'someField', |
|
18
|
|
|
'label' => 'Some Field', |
|
19
|
|
|
'type' => 'someType' |
|
20
|
|
|
]; |
|
21
|
|
|
$fieldConfigMulti = [ |
|
22
|
|
|
[ |
|
23
|
|
|
'name' => 'someField1', |
|
24
|
|
|
'label' => 'Some Field1', |
|
25
|
|
|
'type' => 'someType' |
|
26
|
|
|
], |
|
27
|
|
|
[ |
|
28
|
|
|
'name' => 'someField2', |
|
29
|
|
|
'label' => 'Some Field2', |
|
30
|
|
|
'type' => 'someType' |
|
31
|
|
|
] |
|
32
|
|
|
]; |
|
33
|
|
|
$locationConfig = [ |
|
34
|
|
|
'param' => 'someParam', |
|
35
|
|
|
'operator' => 'someOperator', |
|
36
|
|
|
'value' => 'someValue' |
|
37
|
|
|
]; |
|
38
|
|
|
$config = [ |
|
39
|
|
|
'name' => 'someGroup', |
|
40
|
|
|
'title' => 'Some Group', |
|
41
|
|
|
'fields' => [ |
|
42
|
|
|
$filterName, |
|
43
|
|
|
$fieldConfig, |
|
44
|
|
|
$fieldConfigMulti |
|
45
|
|
|
], |
|
46
|
|
|
'location' => [ |
|
47
|
|
|
[$locationConfig] |
|
48
|
|
|
] |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
Filters\expectApplied($filterName) |
|
|
|
|
|
|
52
|
|
|
->once() |
|
53
|
|
|
->andReturn($fieldConfig); |
|
54
|
|
|
|
|
55
|
|
|
$output = ResolveConfig::forFieldGroup($config); |
|
56
|
|
|
$fieldConfig['key'] = 'field_someGroup_someField'; |
|
57
|
|
|
$fieldConfigMulti[0]['key'] = 'field_someGroup_someField1'; |
|
58
|
|
|
$fieldConfigMulti[1]['key'] = 'field_someGroup_someField2'; |
|
59
|
|
|
$config['key'] = 'group_someGroup'; |
|
60
|
|
|
$config['fields'] = [$fieldConfig, $fieldConfig, $fieldConfigMulti[0], $fieldConfigMulti[1]]; |
|
61
|
|
|
$this->assertEquals($config, $output); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testForFieldGroupFailsWithInvalidField() |
|
65
|
|
|
{ |
|
66
|
|
|
$fieldConfig = [ |
|
67
|
|
|
'name' => 'someField', |
|
68
|
|
|
'label' => 'Some Field' |
|
69
|
|
|
]; |
|
70
|
|
|
$locationConfig = [ |
|
71
|
|
|
'param' => 'someParam', |
|
72
|
|
|
'operator' => 'someOperator', |
|
73
|
|
|
'value' => 'someValue' |
|
74
|
|
|
]; |
|
75
|
|
|
$config = [ |
|
76
|
|
|
'name' => 'someGroup', |
|
77
|
|
|
'title' => 'Some Group', |
|
78
|
|
|
'fields' => [$fieldConfig], |
|
79
|
|
|
'location' => [ |
|
80
|
|
|
[$locationConfig] |
|
81
|
|
|
] |
|
82
|
|
|
]; |
|
83
|
|
|
$this->expectException(Exception::class); |
|
84
|
|
|
ResolveConfig::forFieldGroup($config); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testForFieldGroupFailsWithInvalidLocation() |
|
88
|
|
|
{ |
|
89
|
|
|
$fieldConfig = [ |
|
90
|
|
|
'name' => 'someField', |
|
91
|
|
|
'label' => 'Some Field', |
|
92
|
|
|
'type' => 'someType' |
|
93
|
|
|
]; |
|
94
|
|
|
$locationConfig = [ |
|
95
|
|
|
'operator' => 'someOperator', |
|
96
|
|
|
'value' => 'someValue' |
|
97
|
|
|
]; |
|
98
|
|
|
$config = [ |
|
99
|
|
|
'name' => 'someGroup', |
|
100
|
|
|
'title' => 'Some Group', |
|
101
|
|
|
'fields' => [$fieldConfig], |
|
102
|
|
|
'location' => [ |
|
103
|
|
|
[$locationConfig] |
|
104
|
|
|
] |
|
105
|
|
|
]; |
|
106
|
|
|
$this->expectException(Exception::class); |
|
107
|
|
|
ResolveConfig::forFieldGroup($config); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testForFieldGroupWithNestedFilters() |
|
111
|
|
|
{ |
|
112
|
|
|
$subFieldFilter = 'ACFComposer/Layout/subFieldLayout/SubFields'; |
|
113
|
|
|
$subFieldConfig = [ |
|
114
|
|
|
[ |
|
115
|
|
|
'name' => 'nestedSubField', |
|
116
|
|
|
'label' => 'Nested Sub Field', |
|
117
|
|
|
'type' => 'text' |
|
118
|
|
|
] |
|
119
|
|
|
]; |
|
120
|
|
|
$someLayoutFilter = 'ACFComposer/Layout/someLayout'; |
|
121
|
|
|
$someLayoutConfig = [ |
|
122
|
|
|
[ |
|
123
|
|
|
'name' => 'SubField', |
|
124
|
|
|
'label' => 'Sub Field', |
|
125
|
|
|
'type' => 'text' |
|
126
|
|
|
], |
|
127
|
|
|
$subFieldFilter |
|
128
|
|
|
]; |
|
129
|
|
|
$masterLayout = [ |
|
130
|
|
|
'name' => 'masterLayout', |
|
131
|
|
|
'title' => 'Master Layout', |
|
132
|
|
|
'fields' => [ |
|
133
|
|
|
$someLayoutFilter |
|
134
|
|
|
], |
|
135
|
|
|
'location' => [ |
|
136
|
|
|
[ |
|
137
|
|
|
[ |
|
138
|
|
|
'param' => 'someParam', |
|
139
|
|
|
'operator' => 'someOperator', |
|
140
|
|
|
'value' => 'someValue' |
|
141
|
|
|
] |
|
142
|
|
|
] |
|
143
|
|
|
] |
|
144
|
|
|
]; |
|
145
|
|
|
Filters\expectApplied($subFieldFilter) |
|
|
|
|
|
|
146
|
|
|
->once() |
|
147
|
|
|
->andReturn($subFieldConfig); |
|
148
|
|
|
Filters\expectApplied($someLayoutFilter) |
|
149
|
|
|
->once() |
|
150
|
|
|
->andReturn($someLayoutConfig); |
|
151
|
|
|
$output = ResolveConfig::forFieldGroup($masterLayout); |
|
152
|
|
|
$resolved_subfields = $output['fields']; |
|
153
|
|
|
$expectedResult = [ |
|
154
|
|
|
[ |
|
155
|
|
|
'name' => 'SubField', |
|
156
|
|
|
'label' => 'Sub Field', |
|
157
|
|
|
'type' => 'text', |
|
158
|
|
|
'key' => 'field_masterLayout_SubField' |
|
159
|
|
|
], |
|
160
|
|
|
[ |
|
161
|
|
|
'name' => 'nestedSubField', |
|
162
|
|
|
'label' => 'Nested Sub Field', |
|
163
|
|
|
'type' => 'text', |
|
164
|
|
|
'key' => 'field_masterLayout_nestedSubField' |
|
165
|
|
|
] |
|
166
|
|
|
]; |
|
167
|
|
|
$this->assertEquals($expectedResult, $resolved_subfields); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
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