1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\DoctrineORMAdminBundle\DependencyInjection\Configuration; |
18
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
19
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidTypeException; |
20
|
|
|
use Symfony\Component\Config\Definition\Processor; |
21
|
|
|
|
22
|
|
|
class ConfigurationTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
public function testDefaultOptions(): void |
25
|
|
|
{ |
26
|
|
|
$config = $this->process([]); |
27
|
|
|
|
28
|
|
|
$this->assertNull($config['entity_manager']); |
29
|
|
|
$this->assertTrue($config['audit']['force']); |
30
|
|
|
$this->assertContains( |
31
|
|
|
'@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig', |
32
|
|
|
$config['templates']['form'] |
33
|
|
|
); |
34
|
|
|
$this->assertContains( |
35
|
|
|
'@SonataDoctrineORMAdmin/Form/filter_admin_fields.html.twig', |
36
|
|
|
$config['templates']['filter'] |
37
|
|
|
); |
38
|
|
|
$this->assertArrayNotHasKey('types', $config['templates']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testAuditForceWithInvalidFormat(): void |
42
|
|
|
{ |
43
|
|
|
$this->expectException(InvalidTypeException::class); |
44
|
|
|
|
45
|
|
|
$this->process([[ |
46
|
|
|
'audit' => [ |
47
|
|
|
'force' => '1', |
48
|
|
|
], |
49
|
|
|
]]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testCustomTemplates(): void |
53
|
|
|
{ |
54
|
|
|
$config = $this->process([[ |
55
|
|
|
'templates' => [ |
56
|
|
|
'form' => ['form.twig.html', 'form_extra.twig.html'], |
57
|
|
|
'filter' => ['filter.twig.html'], |
58
|
|
|
'types' => [ |
59
|
|
|
'list' => [ |
60
|
|
|
'array' => 'list_array.twig.html', |
61
|
|
|
], |
62
|
|
|
'show' => [ |
63
|
|
|
'array' => 'show_array.twig.html', |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
], |
67
|
|
|
]]); |
68
|
|
|
|
69
|
|
|
$this->assertSame(['form.twig.html', 'form_extra.twig.html'], $config['templates']['form']); |
70
|
|
|
$this->assertSame(['filter.twig.html'], $config['templates']['filter']); |
71
|
|
|
$this->assertSame([ |
72
|
|
|
'list' => [ |
73
|
|
|
'array' => 'list_array.twig.html', |
74
|
|
|
], |
75
|
|
|
'show' => [ |
76
|
|
|
'array' => 'show_array.twig.html', |
77
|
|
|
], |
78
|
|
|
], $config['templates']['types']); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testTemplateTypesWithInvalidValues(): void |
82
|
|
|
{ |
83
|
|
|
$this->expectException(InvalidConfigurationException::class); |
84
|
|
|
|
85
|
|
|
$this->process([[ |
86
|
|
|
'templates' => [ |
87
|
|
|
'types' => [ |
88
|
|
|
'edit' => [], |
89
|
|
|
], |
90
|
|
|
], |
91
|
|
|
]]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Processes an array of configurations and returns a compiled version. |
96
|
|
|
* |
97
|
|
|
* @param array $configs An array of raw configurations |
98
|
|
|
* |
99
|
|
|
* @return array A normalized array |
100
|
|
|
*/ |
101
|
|
|
protected function process($configs) |
102
|
|
|
{ |
103
|
|
|
$processor = new Processor(); |
104
|
|
|
|
105
|
|
|
return $processor->processConfiguration(new Configuration(), $configs); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|