|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace FH\Bundle\MultiSiteBundle\Tests\Site; |
|
5
|
|
|
|
|
6
|
|
|
use FH\Bundle\MultiSiteBundle\Site\IdentifierMapping; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
final class IdentifierMappingTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
private const MAPPING = [ |
|
12
|
|
|
'amsterdam' => [ |
|
13
|
|
|
'hostnames' => [ |
|
14
|
|
|
'amsterdam.local', |
|
15
|
|
|
'amsterdam.nl' |
|
16
|
|
|
], |
|
17
|
|
|
'locales' => ['nl', 'en'] |
|
18
|
|
|
], |
|
19
|
|
|
'tilburg' => [ |
|
20
|
|
|
'hostnames' => [ |
|
21
|
|
|
'tilburg.local', |
|
22
|
|
|
'tilburg.nl' |
|
23
|
|
|
], |
|
24
|
|
|
'locales' => ['nl'] |
|
25
|
|
|
], |
|
26
|
|
|
'den-bosch' => [ |
|
27
|
|
|
'hostnames' => [ |
|
28
|
|
|
'denbosch.local', |
|
29
|
|
|
'denbosch.nl' |
|
30
|
|
|
], |
|
31
|
|
|
'locales' => [] |
|
32
|
|
|
] |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var IdentifierMapping |
|
37
|
|
|
*/ |
|
38
|
|
|
private $identifierMapping; |
|
39
|
|
|
|
|
40
|
|
|
protected function setUp() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->identifierMapping = new IdentifierMapping(self::MAPPING); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @dataProvider identifierMappingData |
|
47
|
|
|
* @param string $hostname |
|
48
|
|
|
* @param string|null $expectedIdentifier |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testFindIdentifierByHostnameReturnsCorrectIdentifier(string $hostname, string $expectedIdentifier = null): void |
|
51
|
|
|
{ |
|
52
|
|
|
$identifier = $this->identifierMapping->findIdentifierByHostname($hostname); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertEquals($expectedIdentifier, $identifier); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testFindIdentifierByHostnameReturnsNullWhenNoIdentifierMatches(): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertNull($this->identifierMapping->findIdentifierByHostname('xxxx.xxx')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testFindHostnamesByIdentifierWithoutLocaleReturnsCorrectHostnames(): void |
|
63
|
|
|
{ |
|
64
|
|
|
foreach (self::MAPPING as $identifier => $item) { |
|
65
|
|
|
$this->assertEquals($item['hostnames'], $this->identifierMapping->findHostnamesByIdentifier($identifier)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testFindHostnamesByIdentifierWithLocaleReturnsCorrectHostnames(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$hostnames = $this->identifierMapping->findHostnamesByIdentifier('amsterdam', 'nl'); |
|
72
|
|
|
$this->assertEquals(self::MAPPING['amsterdam']['hostnames'], $hostnames); |
|
73
|
|
|
|
|
74
|
|
|
$hostnames = $this->identifierMapping->findHostnamesByIdentifier('amsterdam', 'en'); |
|
75
|
|
|
$this->assertEquals(self::MAPPING['amsterdam']['hostnames'], $hostnames); |
|
76
|
|
|
|
|
77
|
|
|
$hostnames = $this->identifierMapping->findHostnamesByIdentifier('tilburg', 'en'); |
|
78
|
|
|
$this->assertEmpty($hostnames); |
|
79
|
|
|
|
|
80
|
|
|
$hostnames = $this->identifierMapping->findHostnamesByIdentifier('den-bosch', 'nl'); |
|
81
|
|
|
$this->assertEmpty($hostnames); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testFindHostnamesByIdentifierReturnsEmptyHostnamesOnNonExistentIdentifier(): void |
|
85
|
|
|
{ |
|
86
|
|
|
$hostnames = $this->identifierMapping->findHostnamesByIdentifier('xxxx'); |
|
87
|
|
|
$this->assertEmpty($hostnames); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function identifierMappingData(): array |
|
91
|
|
|
{ |
|
92
|
|
|
return [ |
|
93
|
|
|
['amsterdam.local', 'amsterdam'], |
|
94
|
|
|
['amsterdam.nl', 'amsterdam'], |
|
95
|
|
|
['tilburg.local', 'tilburg'], |
|
96
|
|
|
['tilburg.nl', 'tilburg'] |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|