Completed
Push — master ( 1e6b4e...d692a8 )
by Rafał
14:51
created

testLoadWhenPHPCRDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\MultiTenancyBundle\Tests\DependencyInjection;
15
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use SWP\Bundle\MultiTenancyBundle\DependencyInjection\SWPMultiTenancyExtension;
18
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
19
20
class SWPMultiTenancyExtensionTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @covers SWP\Bundle\MultiTenancyBundle\SWPMultiTenancyBundle
24
     * @covers SWP\Bundle\MultiTenancyBundle\DependencyInjection\SWPMultiTenancyExtension::load
25
     * @covers SWP\Bundle\MultiTenancyBundle\DependencyInjection\Configuration::getConfigTreeBuilder
26
     * @covers SWP\Bundle\MultiTenancyBundle\DependencyInjection\SWPMultiTenancyExtension::loadPhpcr
27
     */
28
    public function testLoad()
29
    {
30
        $container = $this->createContainer();
31
        $loader = $this->createLoader();
32
        $config = $this->getConfig();
33
34
        $loader->load(array($config), $container);
35
36
        $this->assertTrue($container->getParameter('swp_multi_tenancy.backend_type_phpcr'));
37
        $this->assertEquals('/swp', $container->getParameter('swp_multi_tenancy.persistence.phpcr.basepath'));
38
        $this->assertEquals(
39
            'SWP\Bundle\MultiTenancyBundle\Document\Site',
40
            $container->getParameter('swp_multi_tenancy.persistence.phpcr.site_document.class')
41
        );
42
43
        $this->assertEquals(
44
            'SWP\Bundle\MultiTenancyBundle\Document\Page',
45
            $container->getParameter('swp_multi_tenancy.persistence.phpcr.document.class')
46
        );
47
48
        $this->assertEquals('content', $container->getParameter('swp_multi_tenancy.persistence.phpcr.content_basepath'));
49
        $this->assertEquals(
50
            'SWP\Bundle\MultiTenancyBundle\Routing\TenantAwareRouter',
51
            $container->getParameter('swp_multi_tenancy.persistence.phpcr.router.class')
52
        );
53
54
        $this->assertEquals(
55
           array('routes1', 'routes2'),
56
           $container->getParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths')
57
       );
58
59
        $this->assertEquals(
60
            array('routes1', 'routes2', 'content'),
61
            $container->getParameter('swp_multi_tenancy.persistence.phpcr.base_paths')
62
        );
63
64
        $this->assertEquals(
65
            'SWP\Component\MultiTenancy\Model\Tenant',
66
            $container->getParameter('swp_multi_tenancy.tenant.class')
67
        );
68
69
        $this->assertEquals(
70
            'SWP\Component\MultiTenancy\Factory\TenantFactory',
71
            $container->getParameter('swp_multi_tenancy.factory.tenant.class')
72
        );
73
74
        $this->assertTrue($container->hasParameter('swp_multi_tenancy.backend_type_phpcr'));
75
    }
76
77
    public function testLoadWhenPHPCRDisabled()
78
    {
79
        $container = $this->createContainer();
80
        $loader = $this->createLoader();
81
        $config = $this->getConfig();
82
        $config['persistence']['phpcr']['enabled'] = false;
83
        $loader->load(array($config), $container);
84
85
        $this->assertFalse($container->hasParameter('swp_multi_tenancy.backend_type_phpcr'));
86
    }
87
88
    protected function createLoader()
89
    {
90
        return new SWPMultiTenancyExtension();
91
    }
92
93
    protected function getConfig()
94
    {
95
        return array(
96
            'persistence' => array(
97
                'phpcr' => array(
98
                    'enabled' => true,
99
                    'content_basepath' => 'content',
100
                    'route_basepaths' => array('routes1', 'routes2'),
101
                ),
102
            ),
103
        );
104
    }
105
106
    protected function createContainer(array $data = array())
107
    {
108
        return new ContainerBuilder(new ParameterBag($data));
109
    }
110
}
111