|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the TemplatesTest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Configuration\Parser; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldDefinitionSettingsTemplates; |
|
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldTemplates; |
|
13
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension; |
|
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Provider\StaticSiteAccessProvider; |
|
15
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface; |
|
16
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
17
|
|
|
|
|
18
|
|
|
class TemplatesTest extends AbstractParserTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
private $config; |
|
21
|
|
|
|
|
22
|
|
|
protected function getContainerExtensions(): array |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
new EzPublishCoreExtension( |
|
26
|
|
|
[new FieldTemplates(), new FieldDefinitionSettingsTemplates()] |
|
27
|
|
|
), |
|
28
|
|
|
]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function getMinimalConfiguration(): array |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->config = Yaml::parse(file_get_contents(__DIR__ . '/../../Fixtures/ezpublish_templates.yml')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
public function testFieldTemplates() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->load(); |
|
39
|
|
|
$fixedUpConfig = $this->getExpectedConfigFieldTemplates($this->config); |
|
40
|
|
|
$groupFieldTemplates = $fixedUpConfig['system']['ezdemo_frontend_group']['field_templates']; |
|
41
|
|
|
$demoSiteFieldTemplates = $fixedUpConfig['system']['ezdemo_site']['field_templates']; |
|
42
|
|
|
$this->assertConfigResolverParameterValue( |
|
43
|
|
|
'field_templates', |
|
44
|
|
|
array_merge( |
|
45
|
|
|
// Adding default kernel value. |
|
46
|
|
|
[['template' => '%ezplatform.default_templates.field_templates%', 'priority' => 0]], |
|
47
|
|
|
$groupFieldTemplates, |
|
48
|
|
|
$demoSiteFieldTemplates |
|
49
|
|
|
), |
|
50
|
|
|
'ezdemo_site', |
|
51
|
|
|
false |
|
52
|
|
|
); |
|
53
|
|
|
$this->assertConfigResolverParameterValue( |
|
54
|
|
|
'field_templates', |
|
55
|
|
|
array_merge( |
|
56
|
|
|
// Adding default kernel value. |
|
57
|
|
|
[['template' => '%ezplatform.default_templates.field_templates%', 'priority' => 0]], |
|
58
|
|
|
$groupFieldTemplates |
|
59
|
|
|
), |
|
60
|
|
|
'fre', |
|
61
|
|
|
false |
|
62
|
|
|
); |
|
63
|
|
|
$this->assertConfigResolverParameterValue( |
|
64
|
|
|
'field_templates', |
|
65
|
|
|
[['template' => '%ezplatform.default_templates.field_templates%', 'priority' => 0]], |
|
66
|
|
|
'ezdemo_site_admin', |
|
67
|
|
|
false |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function getSiteAccessProviderMock(): SiteAccessProviderInterface |
|
72
|
|
|
{ |
|
73
|
|
|
$siteAccessProvider = $this->createMock(SiteAccessProviderInterface::class); |
|
74
|
|
|
$siteAccessProvider |
|
|
|
|
|
|
75
|
|
|
->method('isDefined') |
|
76
|
|
|
->willReturnMap([ |
|
77
|
|
|
['ezdemo_site', true], |
|
78
|
|
|
['fre', true], |
|
79
|
|
|
['ezdemo_site_admin', true], |
|
80
|
|
|
]); |
|
81
|
|
|
$siteAccessProvider |
|
|
|
|
|
|
82
|
|
|
->method('getSiteAccess') |
|
83
|
|
|
->willReturnMap([ |
|
84
|
|
|
['ezdemo_site', $this->getSiteAccess('ezdemo_site', StaticSiteAccessProvider::class, ['ezdemo_group', 'ezdemo_frontend_group'])], |
|
85
|
|
|
['fre', $this->getSiteAccess('fre', StaticSiteAccessProvider::class, ['ezdemo_group', 'ezdemo_frontend_group'])], |
|
86
|
|
|
['ezdemo_site_admin', $this->getSiteAccess('ezdemo_site_admin', StaticSiteAccessProvider::class, ['ezdemo_group'])], |
|
87
|
|
|
]); |
|
88
|
|
|
|
|
89
|
|
|
return $siteAccessProvider; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Fixes up input configuration for field_templates as semantic configuration parser does, adding a default priority of 0 when not set. |
|
94
|
|
|
* |
|
95
|
|
|
* @param array $config |
|
96
|
|
|
* |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
|
View Code Duplication |
private function getExpectedConfigFieldTemplates(array $config) |
|
100
|
|
|
{ |
|
101
|
|
|
foreach ($config['system']['ezdemo_frontend_group']['field_templates'] as &$block) { |
|
102
|
|
|
if (!isset($block['priority'])) { |
|
103
|
|
|
$block['priority'] = 0; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $config; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
View Code Duplication |
public function testFieldDefinitionSettingsTemplates() |
|
111
|
|
|
{ |
|
112
|
|
|
$this->load(); |
|
113
|
|
|
$fixedUpConfig = $this->getExpectedConfigFieldDefinitionSettingsTemplates($this->config); |
|
114
|
|
|
$groupFieldTemplates = $fixedUpConfig['system']['ezdemo_frontend_group']['fielddefinition_settings_templates']; |
|
115
|
|
|
$demoSiteFieldTemplates = $fixedUpConfig['system']['ezdemo_site']['fielddefinition_settings_templates']; |
|
116
|
|
|
|
|
117
|
|
|
$this->assertConfigResolverParameterValue( |
|
118
|
|
|
'fielddefinition_settings_templates', |
|
119
|
|
|
array_merge( |
|
120
|
|
|
// Adding default kernel value. |
|
121
|
|
|
[['template' => '%ezplatform.default_templates.fielddefinition_settings_templates%', 'priority' => 0]], |
|
122
|
|
|
$groupFieldTemplates, |
|
123
|
|
|
$demoSiteFieldTemplates |
|
124
|
|
|
), |
|
125
|
|
|
'ezdemo_site', |
|
126
|
|
|
false |
|
127
|
|
|
); |
|
128
|
|
|
$this->assertConfigResolverParameterValue( |
|
129
|
|
|
'fielddefinition_settings_templates', |
|
130
|
|
|
array_merge( |
|
131
|
|
|
// Adding default kernel value. |
|
132
|
|
|
[['template' => '%ezplatform.default_templates.fielddefinition_settings_templates%', 'priority' => 0]], |
|
133
|
|
|
$groupFieldTemplates |
|
134
|
|
|
), |
|
135
|
|
|
'fre', |
|
136
|
|
|
false |
|
137
|
|
|
); |
|
138
|
|
|
$this->assertConfigResolverParameterValue( |
|
139
|
|
|
'fielddefinition_settings_templates', |
|
140
|
|
|
[['template' => '%ezplatform.default_templates.fielddefinition_settings_templates%', 'priority' => 0]], |
|
141
|
|
|
'ezdemo_site_admin', |
|
142
|
|
|
false |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Fixes up input configuration for fielddefinition_settings_templates as semantic configuration parser does, adding a default priority of 0 when not set. |
|
148
|
|
|
* |
|
149
|
|
|
* @param array $config |
|
150
|
|
|
* |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
|
View Code Duplication |
private function getExpectedConfigFieldDefinitionSettingsTemplates(array $config) |
|
154
|
|
|
{ |
|
155
|
|
|
foreach ($config['system']['ezdemo_frontend_group']['fielddefinition_settings_templates'] as &$block) { |
|
156
|
|
|
if (!isset($block['priority'])) { |
|
157
|
|
|
$block['priority'] = 0; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
return $config; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.