Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

KunstmaanAdminExtensionTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\DependencyInjection;
4
5
use Kunstmaan\AdminBundle\DependencyInjection\KunstmaanAdminExtension;
6
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
7
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
8
9
class KunstmaanAdminExtensionTest extends AbstractExtensionTestCase
10
{
11
    /**
12
     * @return ExtensionInterface[]
0 ignored issues
show
Consider making the return type a bit more specific; maybe use KunstmaanAdminExtension[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
13
     */
14
    protected function getContainerExtensions()
15
    {
16
        return [new KunstmaanAdminExtension()];
17
    }
18
19
    public function testCorrectParametersHaveBeenSet()
20
    {
21
        $this->load([
22
            'dashboard_route' => true,
23
            'admin_password' => 'omgchangethis',
24
            'menu_items' => [
25
                [
26
                    'route' => 'route66',
27
                    'label' => 'Route 66',
28
                ],
29
            ],
30
            'website_title' => 'Example title',
31
            'multi_language' => true,
32
            'required_locales' => 'nl|fr|en',
33
            'default_locale' => 'nl',
34
        ]);
35
36
        $this->assertContainerBuilderHasParameter('version_checker.url', 'https://cms.kunstmaan.be/version-check');
37
        $this->assertContainerBuilderHasParameter('version_checker.timeframe', 60 * 60 * 24);
38
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.admin_locales');
39
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_admin_locale');
40
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.session_security.ip_check');
41
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.session_security.user_agent_check');
42
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.enabled');
43
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.client_id');
44
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.client_secret');
45
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.hosted_domains');
46
    }
47
48
    /**
49
     * @group legacy
50
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.website_title" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
51
     */
52
    public function testWebsiteTitleWithParameterSet()
53
    {
54
        $this->setParameter('websitetitle', 'Mywebsite');
55
56
        $this->load($this->getRequiredConfig('website_title'));
57
58
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.website_title', 'Mywebsite');
59
    }
60
61
    public function testWebsiteTitleWithParameterAndConfigSet()
62
    {
63
        $this->setParameter('websitetitle', 'Mywebsite');
64
65
        $this->load(array_merge($this->getRequiredConfig(), ['website_title' => 'My real website']));
66
67
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.website_title', 'My real website');
68
    }
69
70
    /**
71
     * @group legacy
72
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.multi_language" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
73
     */
74
    public function testMultiLanguageWithParameterSet()
75
    {
76
        $this->setParameter('multilanguage', true);
77
78
        $this->load($this->getRequiredConfig('multi_language'));
79
80
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', true);
81
    }
82
83 View Code Duplication
    public function testMultiLanguageWithParameterAndConfigSet()
84
    {
85
        $this->setParameter('multilanguage', false);
86
87
        $this->load(array_merge($this->getRequiredConfig(), ['multi_language' => true]));
88
89
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', true);
90
    }
91
92
    /**
93
     * @group legacy
94
     */
95 View Code Duplication
    public function testMultiLanguageScalarParameter()
96
    {
97
        $this->setParameter('multilanguage', true);
98
99
        $this->load(array_merge($this->getRequiredConfig(), ['multi_language' => 'randomvalue']));
100
101
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', true);
102
    }
103
104
    /**
105
     * @group legacy
106
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.required_locales" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
107
     */
108
    public function testRequiredLocalesWithParameterSet()
109
    {
110
        $this->setParameter('requiredlocales', 'nl|en');
111
112
        $this->load($this->getRequiredConfig('required_locales'));
113
114
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.required_locales', 'nl|en');
115
    }
116
117
    public function testRequiredLocalesWithParameterAndConfigSet()
118
    {
119
        $this->setParameter('requiredlocales', 'nl|en');
120
121
        $this->load(array_merge($this->getRequiredConfig(), ['required_locales' => 'nl|en|fr']));
122
123
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.required_locales', 'nl|en|fr');
124
    }
125
126
    /**
127
     * @group legacy
128
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.default_locale" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
129
     */
130
    public function testDefaultLocaleWithParameterSet()
131
    {
132
        $this->setParameter('defaultlocale', 'en');
133
134
        $this->load($this->getRequiredConfig('default_locale'));
135
136
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_locale', 'en');
137
    }
138
139
    public function testDefaultLocaleWithParameterAndConfigSet()
140
    {
141
        $this->setParameter('defaultlocale', 'en');
142
143
        $this->load(array_merge($this->getRequiredConfig(), ['default_locale' => 'nl']));
144
145
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_locale', 'nl');
146
    }
147
148
    /**
149
     * @group legacy
150
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.website_title" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
151
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.multi_language" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
152
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.required_locales" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
153
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.default_locale" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
154
     */
155
    public function testLegacyParameters()
156
    {
157
        $this->load();
158
159
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.website_title', '');
160
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', '');
161
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.required_locales', '');
162
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_locale', '');
163
    }
164
165
    protected function setUp()
166
    {
167
        parent::setUp();
168
169
        // Some parameters required for the admin extension
170
        $this->container->setParameter('kernel.logs_dir', '/somewhere/over/the/rainbow');
171
        $this->container->setParameter('kernel.environment', 'staging');
172
    }
173
174
    private function getRequiredConfig(string $excludeKey = null)
175
    {
176
        $requiredConfig = [
177
            'website_title' => 'Example title',
178
            'multi_language' => true,
179
            'required_locales' => 'nl|fr|en',
180
            'default_locale' => 'nl',
181
        ];
182
183
        if (array_key_exists($excludeKey, $requiredConfig)) {
184
            unset($requiredConfig[$excludeKey]);
185
        }
186
187
        return $requiredConfig;
188
    }
189
}
190