Completed
Pull Request — master (#406)
by
unknown
03:31
created

ConfigurationTest::testAdminOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 9.2258
cc 1
eloc 34
nc 1
nop 0
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());
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
}