|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\RouterHostElementTest 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 eZ\Publish\Core\MVC\Symfony\SiteAccess; |
|
12
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\HostElement; |
|
13
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Router; |
|
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Map\Host as HostMapMatcher; |
|
15
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest; |
|
16
|
|
|
use Psr\Log\LoggerInterface; |
|
17
|
|
|
|
|
18
|
|
|
class RouterHostElementTest extends RouterBaseTest |
|
19
|
|
|
{ |
|
20
|
|
View Code Duplication |
public function matchProvider(): array |
|
21
|
|
|
{ |
|
22
|
|
|
return [ |
|
23
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com'), 'example'], |
|
24
|
|
|
[SimplifiedRequest::fromUrl('https://www.example.com'), 'example'], |
|
25
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/'), 'example'], |
|
26
|
|
|
[SimplifiedRequest::fromUrl('https://www.example.com/'), 'example'], |
|
27
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com//'), 'example'], |
|
28
|
|
|
[SimplifiedRequest::fromUrl('https://www.example.com//'), 'example'], |
|
29
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com:8080/'), 'example'], |
|
30
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/first_siteaccess/'), 'example'], |
|
31
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/?first_siteaccess'), 'example'], |
|
32
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/?first_sa'), 'example'], |
|
33
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/first_salt'), 'example'], |
|
34
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/first_sa.foo'), 'example'], |
|
35
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/test'), 'example'], |
|
36
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/test/foo/'), 'example'], |
|
37
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/test/foo/bar/'), 'example'], |
|
38
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/test/foo/bar/first_sa'), 'example'], |
|
39
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/default_sa'), 'example'], |
|
40
|
|
|
|
|
41
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/first_sa'), 'example'], |
|
42
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/first_sa/'), 'example'], |
|
43
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com//first_sa//'), 'example'], |
|
44
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com///first_sa///test'), 'example'], |
|
45
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com//first_sa//foo/bar'), 'example'], |
|
46
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com/first_sa/foo'), 'example'], |
|
47
|
|
|
[SimplifiedRequest::fromUrl('http://www.example.com:82/first_sa/'), 'example'], |
|
48
|
|
|
[SimplifiedRequest::fromUrl('http://third_siteaccess/first_sa/'), 'first_sa'], |
|
49
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/'), 'first_sa'], |
|
50
|
|
|
[SimplifiedRequest::fromUrl('https://first_sa/'), 'first_sa'], |
|
51
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:81/'), 'first_sa'], |
|
52
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/'), 'first_sa'], |
|
53
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:82/'), 'first_sa'], |
|
54
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:83/'), 'first_sa'], |
|
55
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/foo/'), 'first_sa'], |
|
56
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:82/foo/'), 'first_sa'], |
|
57
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:83/foo/'), 'first_sa'], |
|
58
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/foobar/'), 'first_sa'], |
|
59
|
|
|
[SimplifiedRequest::fromUrl('http://second_sa:82/'), 'second_sa'], |
|
60
|
|
|
[SimplifiedRequest::fromUrl('http://second_sa:83/'), 'second_sa'], |
|
61
|
|
|
[SimplifiedRequest::fromUrl('http://second_sa/foo/'), 'second_sa'], |
|
62
|
|
|
[SimplifiedRequest::fromUrl('http://second_sa:82/foo/'), 'second_sa'], |
|
63
|
|
|
[SimplifiedRequest::fromUrl('http://second_sa:83/foo/'), 'second_sa'], |
|
64
|
|
|
[SimplifiedRequest::fromUrl('http://second_sa/foobar/'), 'second_sa'], |
|
65
|
|
|
|
|
66
|
|
|
[SimplifiedRequest::fromUrl('http://dev.example.com/second_sa'), 'example'], |
|
67
|
|
|
[SimplifiedRequest::fromUrl('http://dev.example.com/second_sa/'), 'example'], |
|
68
|
|
|
[SimplifiedRequest::fromUrl('http://dev.example.com/second_sa?param1=foo'), 'example'], |
|
69
|
|
|
[SimplifiedRequest::fromUrl('http://dev.example.com/second_sa/foo/'), 'example'], |
|
70
|
|
|
[SimplifiedRequest::fromUrl('http://dev.example.com:82/second_sa/'), 'example'], |
|
71
|
|
|
[SimplifiedRequest::fromUrl('http://dev.example.com:83/second_sa/'), 'example'], |
|
72
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/second_sa/'), 'second_sa'], |
|
73
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/second_sa/'), 'second_sa'], |
|
74
|
|
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testGetName() |
|
78
|
|
|
{ |
|
79
|
|
|
$matcher = new HostMapMatcher(['host' => 'foo'], []); |
|
80
|
|
|
$this->assertSame('host:map', $matcher->getName()); |
|
81
|
|
|
|
|
82
|
|
|
$matcherHostElement = new HostElement([1]); |
|
83
|
|
|
$this->assertSame('host:element', $matcherHostElement->getName()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @dataProvider reverseMatchProvider |
|
88
|
|
|
*/ |
|
89
|
|
View Code Duplication |
public function testReverseMatch($siteAccessName, $elementNumber, SimplifiedRequest $request, $expectedHost) |
|
90
|
|
|
{ |
|
91
|
|
|
$matcher = new HostElement([$elementNumber]); |
|
92
|
|
|
$matcher->setRequest($request); |
|
93
|
|
|
$result = $matcher->reverseMatch($siteAccessName); |
|
94
|
|
|
$this->assertInstanceOf(HostElement::class, $result); |
|
95
|
|
|
$this->assertSame($expectedHost, $result->getRequest()->host); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function reverseMatchProvider() |
|
99
|
|
|
{ |
|
100
|
|
|
return [ |
|
101
|
|
|
['foo', 1, SimplifiedRequest::fromUrl('http://bar.example.com/'), 'foo.example.com'], |
|
102
|
|
|
['ezdemo_site', 1, SimplifiedRequest::fromUrl('http://ezflow_site.ez.no/'), 'ezdemo_site.ez.no'], |
|
103
|
|
|
['metalfrance', 2, SimplifiedRequest::fromUrl('http://www.lolart.net/'), 'www.metalfrance.net'], |
|
104
|
|
|
['fm', 3, SimplifiedRequest::fromUrl('http://www.phoenix-rises.fr/'), 'www.phoenix-rises.fm'], |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function testReverseMatchFail() |
|
109
|
|
|
{ |
|
110
|
|
|
$matcher = new HostElement([3]); |
|
111
|
|
|
$matcher->setRequest(new SimplifiedRequest(['host' => 'ez.no'])); |
|
112
|
|
|
$this->assertNull($matcher->reverseMatch('foo')); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
public function testSerialize() |
|
116
|
|
|
{ |
|
117
|
|
|
$matcher = new HostElement([1]); |
|
118
|
|
|
$matcher->setRequest(new SimplifiedRequest(['host' => 'ez.no', 'pathinfo' => '/foo/bar'])); |
|
119
|
|
|
$sa = new SiteAccess('test', 'test', $matcher); |
|
120
|
|
|
$serializedSA1 = serialize($sa); |
|
121
|
|
|
|
|
122
|
|
|
$matcher->setRequest(new SimplifiedRequest(['host' => 'ez.no', 'pathinfo' => '/foo/bar/baz'])); |
|
123
|
|
|
$serializedSA2 = serialize($sa); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertSame($serializedSA1, $serializedSA2); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
View Code Duplication |
protected function createRouter(): Router |
|
129
|
|
|
{ |
|
130
|
|
|
return new Router( |
|
131
|
|
|
$this->matcherBuilder, |
|
132
|
|
|
$this->createMock(LoggerInterface::class), |
|
133
|
|
|
'default_sa', |
|
134
|
|
|
[ |
|
135
|
|
|
'HostElement' => [ |
|
136
|
|
|
'value' => 2, |
|
137
|
|
|
], |
|
138
|
|
|
'Map\\URI' => [ |
|
139
|
|
|
'first_sa' => 'first_sa', |
|
140
|
|
|
'second_sa' => 'second_sa', |
|
141
|
|
|
], |
|
142
|
|
|
'Map\\Host' => [ |
|
143
|
|
|
'first_sa' => 'first_sa', |
|
144
|
|
|
'first_siteaccess' => 'first_sa', |
|
145
|
|
|
'second_sa' => 'second_sa', |
|
146
|
|
|
], |
|
147
|
|
|
], |
|
148
|
|
|
$this->siteAccessProvider |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return \eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\SiteAccessSetting[] |
|
154
|
|
|
*/ |
|
155
|
|
View Code Duplication |
public function getSiteAccessProviderSettings(): array |
|
156
|
|
|
{ |
|
157
|
|
|
return [ |
|
158
|
|
|
new SiteAccessSetting('first_sa', true), |
|
159
|
|
|
new SiteAccessSetting('second_sa', true), |
|
160
|
|
|
new SiteAccessSetting('third_sa', true), |
|
161
|
|
|
new SiteAccessSetting('fourth_sa', true), |
|
162
|
|
|
new SiteAccessSetting('fifth_sa', true), |
|
163
|
|
|
new SiteAccessSetting('example', true), |
|
164
|
|
|
]; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|