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 ResolveConfigForLayoutTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testForLayoutWithValidConfig() |
14
|
|
|
{ |
15
|
|
|
$config = [ |
16
|
|
|
'name' => 'someLayout', |
17
|
|
|
'label' => 'Some Layout' |
18
|
|
|
]; |
19
|
|
|
$output = ResolveConfig::forLayout($config); |
20
|
|
|
$config['key'] = 'field_someLayout'; |
21
|
|
|
$this->assertEquals($config, $output); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testForLayoutFailsWithoutName() |
25
|
|
|
{ |
26
|
|
|
$config = [ |
27
|
|
|
'label' => 'Some Layout' |
28
|
|
|
]; |
29
|
|
|
$this->expectException(Exception::class); |
30
|
|
|
ResolveConfig::forLayout($config); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testForLayoutFailsWithoutLabel() |
34
|
|
|
{ |
35
|
|
|
$config = [ |
36
|
|
|
'name' => 'someLayout' |
37
|
|
|
]; |
38
|
|
|
$this->expectException(Exception::class); |
39
|
|
|
ResolveConfig::forLayout($config); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testForLayoutFailsWithKey() |
43
|
|
|
{ |
44
|
|
|
$config = [ |
45
|
|
|
'name' => 'someLayout', |
46
|
|
|
'label' => 'Some Layout', |
47
|
|
|
'key' => 'someKey' |
48
|
|
|
]; |
49
|
|
|
$this->expectException(Exception::class); |
50
|
|
|
ResolveConfig::forLayout($config); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testForLayoutGetConfigFromFilter() |
54
|
|
|
{ |
55
|
|
|
$config = 'ACFComposer/Layout/someLayout'; |
56
|
|
|
$someLayout = [ |
57
|
|
|
'name' => 'someLayout', |
58
|
|
|
'label' => 'Some Layout' |
59
|
|
|
]; |
60
|
|
|
Filters\expectApplied($config) |
|
|
|
|
61
|
|
|
->once() |
62
|
|
|
->andReturn($someLayout); |
63
|
|
|
$output = ResolveConfig::forLayout($config); |
|
|
|
|
64
|
|
|
$someLayout['key'] = 'field_someLayout'; |
65
|
|
|
$this->assertEquals($someLayout, $output); |
66
|
|
|
} |
67
|
|
|
public function testForLayoutWithValidSubField() |
68
|
|
|
{ |
69
|
|
|
$subFieldConfig = [ |
70
|
|
|
'name' => 'subField', |
71
|
|
|
'label' => 'Sub Field', |
72
|
|
|
'type' => 'someType' |
73
|
|
|
]; |
74
|
|
|
$config = [ |
75
|
|
|
'name' => 'someLayout', |
76
|
|
|
'label' => 'Some Layout', |
77
|
|
|
'sub_fields' => [$subFieldConfig] |
78
|
|
|
]; |
79
|
|
|
$output = ResolveConfig::forLayout($config); |
80
|
|
|
$subFieldConfig['key'] = 'field_someLayout_subField'; |
81
|
|
|
$this->assertEquals($subFieldConfig, $output['sub_fields'][0]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testForLayoutFailWithInvalidSubField() |
85
|
|
|
{ |
86
|
|
|
$subFieldConfig = [ |
87
|
|
|
'name' => 'subField', |
88
|
|
|
'label' => 'Sub Field' |
89
|
|
|
]; |
90
|
|
|
$config = [ |
91
|
|
|
'name' => 'someLayout', |
92
|
|
|
'label' => 'Some Layout', |
93
|
|
|
'sub_fields' => [$subFieldConfig] |
94
|
|
|
]; |
95
|
|
|
$this->expectException(Exception::class); |
96
|
|
|
ResolveConfig::forLayout($config); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testforLayoutGetConfigFromFilterWithArgumentAndNestedConditionalLogic() |
100
|
|
|
{ |
101
|
|
|
$config = 'ACFComposer/Fields/someField#prefix'; |
102
|
|
|
$filter = 'ACFComposer/Fields/someField'; |
103
|
|
|
$layout = [ |
104
|
|
|
'name' => 'layout', |
105
|
|
|
'label' => 'Layout', |
106
|
|
|
'sub_fields' => [ |
107
|
|
|
[ |
108
|
|
|
'name' => 'someBoolean', |
109
|
|
|
'label' => 'Some Boolean', |
110
|
|
|
'type' => 'boolean' |
111
|
|
|
], |
112
|
|
|
[ |
113
|
|
|
'name' => 'someRepeater', |
114
|
|
|
'label' => 'Some Repeater', |
115
|
|
|
'type' => 'repeater', |
116
|
|
|
'sub_fields' => [ |
117
|
|
|
[ |
118
|
|
|
'name' => 'someNestedImage', |
119
|
|
|
'label' => 'Some Nested Image', |
120
|
|
|
'type' => 'image', |
121
|
|
|
'conditional_logic' => [ |
122
|
|
|
[ |
123
|
|
|
[ |
124
|
|
|
'fieldPath' => '../someBoolean', |
125
|
|
|
'operator' => '==', |
126
|
|
|
'value' => '1' |
127
|
|
|
] |
128
|
|
|
] |
129
|
|
|
] |
130
|
|
|
] |
131
|
|
|
] |
132
|
|
|
] |
133
|
|
|
] |
134
|
|
|
]; |
135
|
|
|
|
136
|
|
|
Filters\expectApplied($filter) |
|
|
|
|
137
|
|
|
->with(null, 'prefix') |
138
|
|
|
->once() |
139
|
|
|
->andReturn($layout); |
140
|
|
|
|
141
|
|
|
$output = ResolveConfig::forLayout($config); |
|
|
|
|
142
|
|
|
|
143
|
|
|
$layout['key'] = 'field_prefix_layout'; |
144
|
|
|
$layout['name'] = 'prefix_layout'; |
145
|
|
|
$layout['sub_fields'][0]['key'] = 'field_prefix_layout_someBoolean'; |
146
|
|
|
$layout['sub_fields'][1]['key'] = 'field_prefix_layout_someRepeater'; |
147
|
|
|
$layout['sub_fields'][1]['sub_fields'][0]['key'] = 'field_prefix_layout_someRepeater_someNestedImage'; |
148
|
|
|
$layout['sub_fields'][1]['sub_fields'][0]['conditional_logic'][0][0]['field'] = 'field_prefix_layout_someBoolean'; |
149
|
|
|
unset($layout['sub_fields'][1]['sub_fields'][0]['conditional_logic'][0][0]['fieldPath']); |
150
|
|
|
$this->assertEquals($layout, $output); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
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