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\Helper; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\Helper\DomainConfiguration; |
||
6 | use PHPUnit\Framework\TestCase; |
||
7 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
8 | use Symfony\Component\HttpFoundation\Request; |
||
9 | |||
10 | class DomainConfigurationTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var DomainConfiguration |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | * @var ContainerInterface |
||
19 | */ |
||
20 | protected $container; |
||
21 | |||
22 | public function testGetHost() |
||
23 | { |
||
24 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
25 | $this->assertEquals('domain.tld', $object->getHost()); |
||
26 | } |
||
27 | |||
28 | public function testGetHosts() |
||
29 | { |
||
30 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
31 | $this->assertEquals(array('domain.tld'), $object->getHosts()); |
||
32 | } |
||
33 | |||
34 | public function testGetDefaultLocale() |
||
35 | { |
||
36 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
37 | $this->assertEquals('en', $object->getDefaultLocale()); |
||
38 | } |
||
39 | |||
40 | public function testGetExtraData() |
||
41 | { |
||
42 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
43 | $this->assertEquals(array(), $object->getExtraData()); |
||
44 | } |
||
45 | |||
46 | public function testGetRootNode() |
||
47 | { |
||
48 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
49 | $this->assertNull($object->getRootNode()); |
||
50 | } |
||
51 | |||
52 | public function testIsMultiDomainHost() |
||
53 | { |
||
54 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
55 | $this->assertFalse($object->isMultiDomainHost()); |
||
56 | } |
||
57 | |||
58 | public function testIsMultiLanguageWithSingleLanguage() |
||
59 | { |
||
60 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
61 | $this->assertFalse($object->isMultiLanguage()); |
||
62 | } |
||
63 | |||
64 | public function testIsMultiLanguageWithMultiLanguage() |
||
65 | { |
||
66 | $object = $this->getMultiLanguageDomainConfiguration(); |
||
67 | $this->assertTrue($object->isMultiLanguage()); |
||
68 | } |
||
69 | |||
70 | public function testGetFrontendLocalesWithSingleLanguage() |
||
71 | { |
||
72 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
73 | $this->assertEquals(array('en'), $object->getFrontendLocales()); |
||
74 | } |
||
75 | |||
76 | public function testGetFrontendLocalesWithMultiLanguage() |
||
77 | { |
||
78 | $object = $this->getMultiLanguageDomainConfiguration(); |
||
79 | $this->assertEquals(array('nl', 'fr', 'en'), $object->getFrontendLocales()); |
||
80 | } |
||
81 | |||
82 | public function testGetBackendLocalesWithSingleLanguage() |
||
83 | { |
||
84 | $object = $this->getSingleLanguageDomainConfiguration(); |
||
85 | $this->assertEquals(array('en'), $object->getBackendLocales()); |
||
86 | } |
||
87 | |||
88 | public function testGetBackendLocalesWithMultiLanguage() |
||
89 | { |
||
90 | $object = $this->getMultiLanguageDomainConfiguration(); |
||
91 | $this->assertEquals(array('nl', 'fr', 'en'), $object->getBackendLocales()); |
||
92 | } |
||
93 | |||
94 | View Code Duplication | private function getContainer($map) |
|
0 ignored issues
–
show
|
|||
95 | { |
||
96 | $this->container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
||
97 | |||
98 | $this->container |
||
99 | ->method('getParameter') |
||
100 | ->will($this->returnValueMap($map)); |
||
101 | $this->container |
||
102 | ->expects($this->any()) |
||
103 | ->method('get') |
||
104 | ->with($this->equalTo('request_stack')) |
||
105 | ->willReturn($this->getRequestStack()); |
||
106 | |||
107 | return $this->container; |
||
108 | } |
||
109 | |||
110 | View Code Duplication | private function getRequestStack() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
111 | { |
||
112 | $requestStack = $this->createMock('Symfony\Component\HttpFoundation\RequestStack'); |
||
113 | $requestStack->expects($this->any())->method('getMasterRequest')->willReturn($this->getRequest()); |
||
114 | |||
115 | return $requestStack; |
||
116 | } |
||
117 | |||
118 | private function getRequest() |
||
119 | { |
||
120 | $request = Request::create('http://domain.tld/'); |
||
121 | |||
122 | return $request; |
||
123 | } |
||
124 | |||
125 | View Code Duplication | private function getSingleLanguageDomainConfiguration() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
126 | { |
||
127 | $map = [ |
||
128 | ['kunstmaan_admin.multi_language', false], |
||
129 | ['kunstmaan_admin.default_locale', 'en'], |
||
130 | ['kunstmaan_admin.required_locales', 'en'], |
||
131 | ]; |
||
132 | |||
133 | $object = new DomainConfiguration($this->getContainer($map)); |
||
134 | |||
135 | return $object; |
||
136 | } |
||
137 | |||
138 | View Code Duplication | private function getMultiLanguageDomainConfiguration() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
139 | { |
||
140 | $map = [ |
||
141 | ['kunstmaan_admin.multi_language', true], |
||
142 | ['kunstmaan_admin.default_locale', 'nl'], |
||
143 | ['kunstmaan_admin.required_locales', 'nl|fr|en'], |
||
144 | ]; |
||
145 | |||
146 | $object = new DomainConfiguration($this->getContainer($map)); |
||
147 | |||
148 | return $object; |
||
149 | } |
||
150 | } |
||
151 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.