|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Lochmueller\LanguageDetection\Tests\Unit\Service; |
|
6
|
|
|
|
|
7
|
|
|
use Lochmueller\LanguageDetection\Service\TcaLanguageSelection; |
|
8
|
|
|
use Lochmueller\LanguageDetection\Tests\Unit\AbstractUnitTest; |
|
9
|
|
|
use TYPO3\CMS\Core\Exception\SiteNotFoundException; |
|
10
|
|
|
use TYPO3\CMS\Core\Site\Entity\Site; |
|
11
|
|
|
use TYPO3\CMS\Core\Site\SiteFinder; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @internal |
|
15
|
|
|
* |
|
16
|
|
|
* @coversNothing |
|
17
|
|
|
*/ |
|
18
|
|
|
class TcaLanguageSelectionTest extends AbstractUnitTest |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @covers \Lochmueller\LanguageDetection\Service\TcaLanguageSelection |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testLanguageSelectionNoConfiguration(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$tcaLanguageSelection = new TcaLanguageSelection($this->getSiteFinder()); |
|
26
|
|
|
$configuration = []; |
|
27
|
|
|
|
|
28
|
|
|
$tcaLanguageSelection->get($configuration); |
|
29
|
|
|
|
|
30
|
|
|
self::assertSame([], $configuration); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @covers \Lochmueller\LanguageDetection\Service\TcaLanguageSelection |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testLanguageSelectionWithNoFoundedSite(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$siteFinder = $this->createStub(SiteFinder::class); |
|
39
|
|
|
$siteFinder->method('getSiteByIdentifier')->willThrowException(new SiteNotFoundException()); |
|
40
|
|
|
|
|
41
|
|
|
$tcaLanguageSelection = new TcaLanguageSelection($siteFinder); |
|
42
|
|
|
$configuration = [ |
|
43
|
|
|
'row' => [ |
|
44
|
|
|
'identifier' => '1', |
|
45
|
|
|
], |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$tcaLanguageSelection->get($configuration); |
|
49
|
|
|
|
|
50
|
|
|
self::assertSame([ |
|
51
|
|
|
'row' => [ |
|
52
|
|
|
'identifier' => '1', |
|
53
|
|
|
], |
|
54
|
|
|
], $configuration); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @covers \Lochmueller\LanguageDetection\Service\TcaLanguageSelection |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testLanguageSelectionWithConfiguration(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$tcaLanguageSelection = new TcaLanguageSelection($this->getSiteFinder()); |
|
63
|
|
|
$configuration = [ |
|
64
|
|
|
'row' => [ |
|
65
|
|
|
'identifier' => '1', |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
$tcaLanguageSelection->get($configuration); |
|
70
|
|
|
|
|
71
|
|
|
$assert = [ |
|
72
|
|
|
'row' => [ |
|
73
|
|
|
'identifier' => '1', |
|
74
|
|
|
], |
|
75
|
|
|
'items' => [ |
|
76
|
|
|
['', ''], |
|
77
|
|
|
['DE', 1], |
|
78
|
|
|
['EN', 2], |
|
79
|
|
|
], |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
self::assertSame($assert, $configuration); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
protected function getSiteFinder(): SiteFinder |
|
86
|
|
|
{ |
|
87
|
|
|
$site = new Site('dummy', 1, [ |
|
88
|
|
|
'base' => 'https://www.dummy.de/', |
|
89
|
|
|
'forwardRedirectParameters' => '', |
|
90
|
|
|
'languages' => [ |
|
91
|
|
|
[ |
|
92
|
|
|
'languageId' => 1, |
|
93
|
|
|
'base' => '/', |
|
94
|
|
|
'locale' => 'de_DE', |
|
95
|
|
|
'title' => 'DE', |
|
96
|
|
|
], |
|
97
|
|
|
[ |
|
98
|
|
|
'languageId' => 2, |
|
99
|
|
|
'base' => '/en/', |
|
100
|
|
|
'locale' => 'en_GB', |
|
101
|
|
|
'title' => 'EN', |
|
102
|
|
|
], |
|
103
|
|
|
], |
|
104
|
|
|
]); |
|
105
|
|
|
|
|
106
|
|
|
$siteFinder = $this->createStub(SiteFinder::class); |
|
107
|
|
|
$siteFinder->method('getSiteByIdentifier')->willReturn($site); |
|
108
|
|
|
|
|
109
|
|
|
return $siteFinder; |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|