|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\MediaBundle\Tests\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\MediaBundle\DependencyInjection\Configuration; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
|
|
18
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testDefaultOptions() |
|
21
|
|
|
{ |
|
22
|
|
|
$processor = new Processor(); |
|
23
|
|
|
$configuration = new Configuration(); |
|
24
|
|
|
$config = $processor->processConfiguration($configuration, $this->getConfig()); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testAdminOptions() |
|
28
|
|
|
{ |
|
29
|
|
|
$adminConfig = array( |
|
30
|
|
|
'admin' => array( |
|
31
|
|
|
'media' => array( |
|
32
|
|
|
'show_in_dashboard' => false, |
|
33
|
|
|
'class' => 'SomeCustomClass', |
|
34
|
|
|
'controller' => 'SomeCustomController', |
|
35
|
|
|
), |
|
36
|
|
|
'gallery' => array( |
|
37
|
|
|
'translation' => 'SomeCustomDomain', |
|
38
|
|
|
) |
|
39
|
|
|
) |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$processor = new Processor(); |
|
43
|
|
|
$configuration = new Configuration(); |
|
44
|
|
|
$config = $processor->processConfiguration($configuration, $this->getConfig($adminConfig)); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertArrayHasKey('class', $config['admin']['media']); |
|
47
|
|
|
$this->assertArrayHasKey('controller', $config['admin']['media']); |
|
48
|
|
|
$this->assertArrayHasKey('translation', $config['admin']['media']); |
|
49
|
|
|
$this->assertArrayHasKey('show_in_dashboard', $config['admin']['media']); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals($config['admin']['media']['class'], 'SomeCustomClass'); |
|
52
|
|
|
$this->assertEquals($config['admin']['media']['controller'], 'SomeCustomController'); |
|
53
|
|
|
$this->assertEquals($config['admin']['media']['translation'], 'SonataMediaBundle'); |
|
54
|
|
|
$this->assertFalse($config['admin']['media']['show_in_dashboard']); |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$this->assertFalse(array_key_exists('class', $config['admin']['gallery'])); |
|
58
|
|
|
$this->assertArrayHasKey('controller', $config['admin']['gallery']); |
|
59
|
|
|
$this->assertArrayHasKey('translation', $config['admin']['gallery']); |
|
60
|
|
|
$this->assertArrayHasKey('show_in_dashboard', $config['admin']['gallery']); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals($config['admin']['gallery']['controller'], 'SonataMediaBundle:GalleryAdmin'); |
|
63
|
|
|
$this->assertEquals($config['admin']['gallery']['translation'], 'SomeCustomDomain'); |
|
64
|
|
|
$this->assertTrue($config['admin']['gallery']['show_in_dashboard']); |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$this->assertFalse(array_key_exists('class', $config['admin']['gallery_has_media'])); |
|
68
|
|
|
$this->assertArrayHasKey('controller', $config['admin']['gallery_has_media']); |
|
69
|
|
|
$this->assertArrayHasKey('translation', $config['admin']['gallery_has_media']); |
|
70
|
|
|
$this->assertArrayHasKey('show_in_dashboard', $config['admin']['gallery_has_media']); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals($config['admin']['gallery_has_media']['controller'], 'SonataAdminBundle:CRUD'); |
|
73
|
|
|
$this->assertEquals($config['admin']['gallery_has_media']['translation'], 'SonataMediaBundle'); |
|
74
|
|
|
$this->assertFalse($config['admin']['gallery_has_media']['show_in_dashboard']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
private function getConfig($config = array()) { |
|
78
|
|
|
$default = array( |
|
79
|
|
|
'default_context' => 'default', |
|
80
|
|
|
'db_driver' => 'orm', |
|
81
|
|
|
'contexts' => array( |
|
82
|
|
|
'default' => array( |
|
83
|
|
|
'providers' => array( |
|
84
|
|
|
'sonata.media.provider.file' |
|
85
|
|
|
), |
|
86
|
|
|
'formats' => array( |
|
87
|
|
|
'small' => array( |
|
88
|
|
|
'width' => 100, |
|
89
|
|
|
'quality' => 70, |
|
90
|
|
|
) |
|
91
|
|
|
) |
|
92
|
|
|
) |
|
93
|
|
|
), |
|
94
|
|
|
'cdn' => array( |
|
95
|
|
|
'server' => array( |
|
96
|
|
|
'path' => '/uploads/media' |
|
97
|
|
|
) |
|
98
|
|
|
), |
|
99
|
|
|
'filesystem' => array( |
|
100
|
|
|
'local' => array( |
|
101
|
|
|
'directory' => '%kernel.root_dir%/../web/uploads/media', |
|
102
|
|
|
'create' => false, |
|
103
|
|
|
) |
|
104
|
|
|
) |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
return (array($default, $config)); |
|
108
|
|
|
} |
|
109
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.