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
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
10
|
|
|
|
11
|
|
|
class DomainConfigurationTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var DomainConfiguration |
15
|
|
|
*/ |
16
|
|
|
protected $object; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ContainerInterface |
20
|
|
|
*/ |
21
|
|
|
protected $container; |
22
|
|
|
|
23
|
|
|
public function testGetHost() |
24
|
|
|
{ |
25
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
26
|
|
|
$this->assertEquals('domain.tld', $object->getHost()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetHosts() |
30
|
|
|
{ |
31
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
32
|
|
|
$this->assertEquals(array('domain.tld'), $object->getHosts()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetDefaultLocale() |
36
|
|
|
{ |
37
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
38
|
|
|
$this->assertEquals('en', $object->getDefaultLocale()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetExtraData() |
42
|
|
|
{ |
43
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
44
|
|
|
$this->assertEquals(array(), $object->getExtraData()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetRootNode() |
48
|
|
|
{ |
49
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
50
|
|
|
$this->assertNull($object->getRootNode()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testIsMultiDomainHost() |
54
|
|
|
{ |
55
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
56
|
|
|
$this->assertFalse($object->isMultiDomainHost()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testIsMultiLanguageWithSingleLanguage() |
60
|
|
|
{ |
61
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
62
|
|
|
$this->assertFalse($object->isMultiLanguage()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testIsMultiLanguageWithMultiLanguage() |
66
|
|
|
{ |
67
|
|
|
$object = $this->getMultiLanguageDomainConfiguration(); |
68
|
|
|
$this->assertTrue($object->isMultiLanguage()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testGetFrontendLocalesWithSingleLanguage() |
72
|
|
|
{ |
73
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
74
|
|
|
$this->assertEquals(array('en'), $object->getFrontendLocales()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testGetFrontendLocalesWithMultiLanguage() |
78
|
|
|
{ |
79
|
|
|
$object = $this->getMultiLanguageDomainConfiguration(); |
80
|
|
|
$this->assertEquals(array('nl', 'fr', 'en'), $object->getFrontendLocales()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetBackendLocalesWithSingleLanguage() |
84
|
|
|
{ |
85
|
|
|
$object = $this->getSingleLanguageDomainConfiguration(); |
86
|
|
|
$this->assertEquals(array('en'), $object->getBackendLocales()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testGetBackendLocalesWithMultiLanguage() |
90
|
|
|
{ |
91
|
|
|
$object = $this->getMultiLanguageDomainConfiguration(); |
92
|
|
|
$this->assertEquals(array('nl', 'fr', 'en'), $object->getBackendLocales()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
private function getRequestStack() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$requestStack = $this->createMock(RequestStack::class); |
98
|
|
|
$requestStack->expects($this->any())->method('getMasterRequest')->willReturn(Request::create('http://domain.tld/')); |
99
|
|
|
|
100
|
|
|
return $requestStack; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function getSingleLanguageDomainConfiguration() |
104
|
|
|
{ |
105
|
|
|
return new DomainConfiguration($this->getRequestStack(), false, 'en', 'en'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function getMultiLanguageDomainConfiguration() |
109
|
|
|
{ |
110
|
|
|
return new DomainConfiguration($this->getRequestStack(), true, 'nl', 'nl|fr|en'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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.