Completed
Push — 2.x-dev-kit ( 971030 )
by
unknown
07:52
created

ConfigurationTest::processConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project 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\SeoBundle\Tests\DependencyInjection;
13
14
use Sonata\SeoBundle\DependencyInjection\Configuration;
15
use Symfony\Component\Config\Definition\Processor;
16
use Symfony\Component\Yaml\Yaml;
17
18
class ConfigurationTest extends \PHPUnit_Framework_TestCase
19
{
20
    public function testDefaultConfiguration()
21
    {
22
        $config = $this->processConfiguration(array(array()));
23
24
        $expected = $this->getDefaultConfiguration();
25
26
        $this->assertEquals($expected, $config);
27
    }
28
29
    public function testKeysAreNotNormalized()
30
    {
31
        $values = array(
32
            'page' => array(
33
                'head' => array('data-example' => 'abc-123'),
34
                'metas' => array(
35
                    'http-equiv' => array(
36
                        'Content-Type' => 'text/html; charset=utf-8',
37
                    ),
38
                ),
39
            ),
40
        );
41
42
        $config = $this->processConfiguration(array($values));
43
44
        $expected = array_merge_recursive(
45
            $this->getDefaultConfiguration(),
46
            $values
47
        );
48
49
        $this->assertEquals($expected, $config);
50
    }
51
52
    public function testWithYamlConfig()
53
    {
54
        $values = Yaml::parse(file_get_contents(__DIR__.'/data/config.yml'), true);
55
56
        $config = $this->processConfiguration(array($values));
57
58
        $expected = array_merge_recursive(
59
            $this->getDefaultConfiguration(),
60
            $values
61
        );
62
63
        $this->assertEquals($expected, $config);
64
65
        $this->assertEquals('website', $config['page']['metas']['property']['og:type']);
66
    }
67
68
    private function getDefaultConfiguration()
69
    {
70
        return array(
71
            'encoding' => 'UTF-8',
72
            'page' => array(
73
                'default' => 'sonata.seo.page.default',
74
                'head' => array(),
75
                'metas' => array(),
76
                'separator' => ' - ',
77
                'title' => 'Sonata Project',
78
            ),
79
            'sitemap' => array(
80
                'doctrine_orm' => array(),
81
                'services' => array(),
82
            ),
83
        );
84
    }
85
86
    private function processConfiguration(array $configs)
87
    {
88
        $configuration = new Configuration();
89
        $processor = new Processor();
90
91
        return $processor->processConfiguration($configuration, $configs);
92
    }
93
}
94