|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\RouterPortHostURITest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess; |
|
13
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Router; |
|
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest; |
|
15
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\MatcherBuilder; |
|
16
|
|
|
use Psr\Log\LoggerInterface; |
|
17
|
|
|
|
|
18
|
|
|
class RouterPortHostURITest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\MatcherBuilder */ |
|
21
|
|
|
private $matcherBuilder; |
|
22
|
|
|
|
|
23
|
|
|
/** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessProviderInterface */ |
|
24
|
|
|
private $siteAccessProvider; |
|
25
|
|
|
|
|
26
|
|
View Code Duplication |
protected function setUp(): void |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
$this->matcherBuilder = new MatcherBuilder(); |
|
30
|
|
|
$this->siteAccessProvider = $this->createMock(SiteAccess\SiteAccessProviderInterface::class); |
|
|
|
|
|
|
31
|
|
|
$this->siteAccessProvider |
|
|
|
|
|
|
32
|
|
|
->method('isDefined') |
|
33
|
|
|
->willReturnMap([ |
|
34
|
|
|
['first_sa', true], |
|
35
|
|
|
['second_sa', true], |
|
36
|
|
|
['third_sa', true], |
|
37
|
|
|
['fourth_sa', true], |
|
38
|
|
|
['fifth_sa', true], |
|
39
|
|
|
]); |
|
40
|
|
|
$this->siteAccessProvider |
|
|
|
|
|
|
41
|
|
|
->method('getSiteAccess') |
|
42
|
|
|
->willReturnMap([ |
|
43
|
|
|
['first_sa', new SiteAccess('first_sa', Router::DEFAULT_SA_MATCHING_TYPE)], |
|
44
|
|
|
['second_sa', new SiteAccess('second_sa', Router::DEFAULT_SA_MATCHING_TYPE)], |
|
45
|
|
|
['third_sa', new SiteAccess('third_sa', Router::DEFAULT_SA_MATCHING_TYPE)], |
|
46
|
|
|
['fourth_sa', new SiteAccess('fourth_sa', Router::DEFAULT_SA_MATCHING_TYPE)], |
|
47
|
|
|
['fifth_sa', new SiteAccess('fifth_sa', Router::DEFAULT_SA_MATCHING_TYPE)], |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testConstruct() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->createRouter(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @dataProvider matchProvider |
|
58
|
|
|
*/ |
|
59
|
|
View Code Duplication |
public function testMatch(SimplifiedRequest $request, string $siteAccess) |
|
60
|
|
|
{ |
|
61
|
|
|
$router = $this->createRouter(); |
|
62
|
|
|
$sa = $router->match($request); |
|
63
|
|
|
$this->assertInstanceOf(SiteAccess::class, $sa); |
|
64
|
|
|
$this->assertSame($siteAccess, $sa->name); |
|
65
|
|
|
$router->setSiteAccess(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
public function matchProvider() |
|
69
|
|
|
{ |
|
70
|
|
|
return [ |
|
71
|
|
|
[SimplifiedRequest::fromUrl('http://example.com'), 'fifth_sa'], |
|
72
|
|
|
[SimplifiedRequest::fromUrl('https://example.com'), 'fourth_sa'], |
|
73
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/'), 'fifth_sa'], |
|
74
|
|
|
[SimplifiedRequest::fromUrl('https://example.com/'), 'fourth_sa'], |
|
75
|
|
|
[SimplifiedRequest::fromUrl('http://example.com//'), 'fifth_sa'], |
|
76
|
|
|
[SimplifiedRequest::fromUrl('https://example.com//'), 'fourth_sa'], |
|
77
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:8080/'), 'default_sa'], |
|
78
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_siteaccess/'), 'fifth_sa'], |
|
79
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/?first_siteaccess'), 'fifth_sa'], |
|
80
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/?first_sa'), 'fifth_sa'], |
|
81
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_salt'), 'fifth_sa'], |
|
82
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa.foo'), 'fifth_sa'], |
|
83
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test'), 'fifth_sa'], |
|
84
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/'), 'fifth_sa'], |
|
85
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/'), 'fifth_sa'], |
|
86
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/first_sa'), 'fifth_sa'], |
|
87
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/default_sa'), 'fifth_sa'], |
|
88
|
|
|
|
|
89
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa'), 'fifth_sa'], |
|
90
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/'), 'fifth_sa'], |
|
91
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa//'), 'fifth_sa'], |
|
92
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa///test'), 'fifth_sa'], |
|
93
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/foo'), 'fifth_sa'], |
|
94
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/foo/bar'), 'fifth_sa'], |
|
95
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/first_sa/'), 'fourth_sa'], |
|
96
|
|
|
[SimplifiedRequest::fromUrl('http://third_siteaccess/first_sa/'), 'fifth_sa'], |
|
97
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/'), 'fifth_sa'], |
|
98
|
|
|
[SimplifiedRequest::fromUrl('https://first_sa/'), 'fourth_sa'], |
|
99
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:81/'), 'third_sa'], |
|
100
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/'), 'fifth_sa'], |
|
101
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/'), 'fourth_sa'], |
|
102
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/'), 'first_sa'], |
|
103
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/foo/'), 'fifth_sa'], |
|
104
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/foo/'), 'fourth_sa'], |
|
105
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/foo/'), 'first_sa'], |
|
106
|
|
|
|
|
107
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa'), 'fifth_sa'], |
|
108
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa/'), 'fifth_sa'], |
|
109
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa?param1=foo'), 'fifth_sa'], |
|
110
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa/foo/'), 'fifth_sa'], |
|
111
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/second_sa/'), 'fourth_sa'], |
|
112
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:83/second_sa/'), 'first_sa'], |
|
113
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/second_sa/'), 'fourth_sa'], |
|
114
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/second_sa/'), 'first_sa'], |
|
115
|
|
|
|
|
116
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:123/second_sa'), 'first_sa'], |
|
117
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:123/second_sa/'), 'first_sa'], |
|
118
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa?param1=foo'), 'second_sa'], |
|
119
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa/foo/'), 'second_sa'], |
|
120
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa'), 'second_sa'], |
|
121
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa/'), 'second_sa'], |
|
122
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa?param1=foo'), 'second_sa'], |
|
123
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:123/second_sa/foo/'), 'second_sa'], |
|
124
|
|
|
|
|
125
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:81/'), 'third_sa'], |
|
126
|
|
|
[SimplifiedRequest::fromUrl('https://example.com:81/'), 'third_sa'], |
|
127
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:81/foo'), 'third_sa'], |
|
128
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:81/foo/bar'), 'third_sa'], |
|
129
|
|
|
|
|
130
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/'), 'fourth_sa'], |
|
131
|
|
|
[SimplifiedRequest::fromUrl('https://example.com:82/'), 'fourth_sa'], |
|
132
|
|
|
[SimplifiedRequest::fromUrl('https://example.com:82/foo'), 'fourth_sa'], |
|
133
|
|
|
]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
View Code Duplication |
private function createRouter(): Router |
|
137
|
|
|
{ |
|
138
|
|
|
return new Router( |
|
139
|
|
|
$this->matcherBuilder, |
|
140
|
|
|
$this->createMock(LoggerInterface::class), |
|
141
|
|
|
'default_sa', |
|
142
|
|
|
[ |
|
143
|
|
|
'Map\\Port' => [ |
|
144
|
|
|
80 => 'fifth_sa', |
|
145
|
|
|
81 => 'third_sa', |
|
146
|
|
|
82 => 'fourth_sa', |
|
147
|
|
|
83 => 'first_sa', |
|
148
|
|
|
85 => 'first_sa', |
|
149
|
|
|
443 => 'fourth_sa', |
|
150
|
|
|
], |
|
151
|
|
|
'Map\\Host' => [ |
|
152
|
|
|
'first_sa' => 'first_sa', |
|
153
|
|
|
'first_siteaccess' => 'first_sa', |
|
154
|
|
|
'third_siteaccess' => 'third_sa', |
|
155
|
|
|
], |
|
156
|
|
|
'Map\\URI' => [ |
|
157
|
|
|
'first_sa' => 'first_sa', |
|
158
|
|
|
'second_sa' => 'second_sa', |
|
159
|
|
|
], |
|
160
|
|
|
], |
|
161
|
|
|
$this->siteAccessProvider |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..