Completed
Push — master ( f413dd...7f4a11 )
by Ivo
08:26
created

testStorageTypeConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Ivoaz ContentEditable bundle.
5
 *
6
 * (c) Ivo Azirjans <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Ivoaz\Bundle\ContentEditableBundle\Tests\DependencyInjection;
13
14
use Ivoaz\Bundle\ContentEditableBundle\DependencyInjection\IvoazContentEditableExtension;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class IvoazContentEditableExtensionTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var IvoazContentEditableExtension
22
     */
23
    private $extension;
24
25
    /**
26
     * @var ContainerBuilder
27
     */
28
    private $container;
29
30
    public function setUp()
31
    {
32
        $this->extension = new IvoazContentEditableExtension();
33
        $this->container = new ContainerBuilder();
34
    }
35
36
    /**
37
     * @dataProvider getEditorConfigurationTestData
38
     *
39
     * @param string $expectedEditor
40
     * @param array  $configs
41
     * @param string $message
42
     */
43
    public function testEditorConfiguration($expectedEditor, $configs, $message = '')
44
    {
45
        $this->extension->load($configs, $this->container);
46
47
        $definition = $this->container->getDefinition('ivoaz_content_editable.twig_extension');
48
        $editor = $definition->getArgument(2);
49
50
        $expectedEditor = new Reference($expectedEditor);
51
52
        $this->assertEquals($expectedEditor, $editor, $message);
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getEditorConfigurationTestData()
59
    {
60
        return [
61
            ['ivoaz_content_editable.default_editor', [], 'The default editor was not used.'],
62
            [
63
                'custom_editor_service',
64
                ['ivoaz_content_editable' => ['editor' => 'custom_editor_service']],
65
                'Custom editor service was not set.',
66
            ],
67
        ];
68
    }
69
70
    /**
71
     * @dataProvider getStorageTypeConfigurationTestData
72
     *
73
     * @param string $expectedType
74
     * @param array  $configs
75
     * @param string $message
76
     */
77
    public function testStorageTypeConfiguration($expectedType, $configs, $message = '')
78
    {
79
        $this->extension->load($configs, $this->container);
80
81
        try {
82
            $parameter = $this->container->getParameter(sprintf('ivoaz_content_editable.model_type_%s', $expectedType));
83
        } catch (\InvalidArgumentException $e) {
84
            $parameter = false;
85
        }
86
87
        $this->assertTrue($parameter, $message);
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getStorageTypeConfigurationTestData()
94
    {
95
        return [
96
            ['orm', [], 'The default storage type was not used.'],
97
            [
98
                'orm',
99
                ['ivoaz_content_editable' => ['storage' => ['type' => 'orm']]],
100
                'The orm storage type was not used.',
101
            ],
102
            [
103
                'mongodb',
104
                [
105
                    'ivoaz_content_editable' => ['storage' => ['type' => 'mongodb']],
106
                ],
107
                'The mongodb storage type was not used.',
108
            ],
109
        ];
110
    }
111
112
    /**
113
     * @dataProvider getObjectManagerConfigurationTestData
114
     *
115
     * @param string $expected
116
     * @param array  $configs
117
     * @param string $message
118
     */
119
    public function testObjectManagerConfiguration($expected, $configs, $message = '')
120
    {
121
        $this->extension->load($configs, $this->container);
122
123
        $alias = $this->container->getAlias('ivoaz_content_editable.object_manager');
124
        $modelManagerName = $this->container->getParameter('ivoaz_content_editable.model_manager_name');
125
126
        $this->assertEquals($expected, $alias, $message);
127
        $this->assertEquals($expected, $modelManagerName, $message);
128
    }
129
130
    /**
131
     * @return array
132
     */
133
    public function getObjectManagerConfigurationTestData()
134
    {
135
        return [
136
            ['doctrine.default_entity_manager', [], 'The default orm object manager was not used.'],
137
            [
138
                'doctrine.default_entity_manager',
139
                ['ivoaz_content_editable' => ['storage' => ['type' => 'orm']]],
140
                'The default orm object manager was not used.',
141
            ],
142
            [
143
                'doctrine_mongodb.odm.default_document_manager',
144
                ['ivoaz_content_editable' => ['storage' => ['type' => 'mongodb']]],
145
                'The default mongodb object manager was not used.',
146
            ],
147
            [
148
                'custom',
149
                ['ivoaz_content_editable' => ['storage' => ['type' => 'mongodb', 'object_manager' => 'custom']]],
150
                'A custom object manager was not used.',
151
            ],
152
        ];
153
    }
154
}
155