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