1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIText; |
10
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Router; |
11
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIText as URITextMatcher; |
12
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest; |
13
|
|
|
use Psr\Log\LoggerInterface; |
14
|
|
|
|
15
|
|
|
class RouterURITextTest extends RouterBaseTest |
16
|
|
|
{ |
17
|
|
View Code Duplication |
public function matchProvider(): array |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
[SimplifiedRequest::fromUrl('http://example.com'), 'default_sa'], |
21
|
|
|
[SimplifiedRequest::fromUrl('https://example.com'), 'default_sa'], |
22
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/'), 'default_sa'], |
23
|
|
|
[SimplifiedRequest::fromUrl('https://example.com/'), 'default_sa'], |
24
|
|
|
[SimplifiedRequest::fromUrl('http://example.com//'), 'default_sa'], |
25
|
|
|
[SimplifiedRequest::fromUrl('https://example.com//'), 'default_sa'], |
26
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:8080/'), 'default_sa'], |
27
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_siteaccess/'), 'default_sa'], |
28
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/?first_siteaccess'), 'default_sa'], |
29
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/?first_sa'), 'default_sa'], |
30
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_salt'), 'default_sa'], |
31
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa.foo'), 'default_sa'], |
32
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test'), 'default_sa'], |
33
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/'), 'default_sa'], |
34
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/'), 'default_sa'], |
35
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/first_sa'), 'default_sa'], |
36
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/default_sa'), 'default_sa'], |
37
|
|
|
|
38
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa'), 'first_sa'], |
39
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/'), 'first_sa'], |
40
|
|
|
// Double slashes shouldn't be considered as one |
41
|
|
|
[SimplifiedRequest::fromUrl('http://example.com//first_sa//'), 'default_sa'], |
42
|
|
|
[SimplifiedRequest::fromUrl('http://example.com///first_sa///test'), 'default_sa'], |
43
|
|
|
[SimplifiedRequest::fromUrl('http://example.com//first_sa//foo/bar'), 'default_sa'], |
44
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/first_sa/foo'), 'first_sa'], |
45
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/first_sa/'), 'first_sa'], |
46
|
|
|
[SimplifiedRequest::fromUrl('http://third_siteaccess/first_sa/'), 'first_sa'], |
47
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa/'), 'first_sa'], |
48
|
|
|
[SimplifiedRequest::fromUrl('https://first_sa/'), 'first_sa'], |
49
|
|
|
[SimplifiedRequest::fromUrl('http://first_sa:81/'), 'first_sa'], |
50
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/'), 'first_sa'], |
51
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/'), 'first_sa'], |
52
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/'), 'first_sa'], |
53
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/foo/'), 'first_sa'], |
54
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/foo/'), 'first_sa'], |
55
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/foo/'), 'first_sa'], |
56
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/foobar/'), 'first_sa'], |
57
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess//foobar/'), 'first_sa'], |
58
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess//footestbar/'), 'first_sa'], |
59
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/footestbar/'), 'test'], |
60
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess/footestbar/foobazbar/'), 'test'], |
61
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/footestbar/'), 'test'], |
62
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/footestbar/'), 'test'], |
63
|
|
|
|
64
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa'), 'second_sa'], |
65
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa/'), 'second_sa'], |
66
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa?param1=foo'), 'second_sa'], |
67
|
|
|
[SimplifiedRequest::fromUrl('http://example.com/second_sa/foo/'), 'second_sa'], |
68
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:82/second_sa/'), 'second_sa'], |
69
|
|
|
[SimplifiedRequest::fromUrl('http://example.com:83/second_sa/'), 'second_sa'], |
70
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:82/second_sa/'), 'second_sa'], |
71
|
|
|
[SimplifiedRequest::fromUrl('http://first_siteaccess:83/second_sa/'), 'second_sa'], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetName() |
76
|
|
|
{ |
77
|
|
|
$matcher = new URITextMatcher([], []); |
78
|
|
|
$this->assertSame('uri:text', $matcher->getName()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function testAnalyseURI() |
82
|
|
|
{ |
83
|
|
|
$siteAccessURI = '/footestbar'; |
84
|
|
|
$semanticURI = '/something/hoho'; |
85
|
|
|
$matcher = new URITextMatcher( |
86
|
|
|
[ |
87
|
|
|
'prefix' => 'foo', |
88
|
|
|
'suffix' => 'bar', |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
$matcher->setRequest(SimplifiedRequest::fromUrl('http://phoenix-rises.fm/footestbar/blabla')); |
92
|
|
|
|
93
|
|
|
$this->assertSame($semanticURI, $matcher->analyseURI($siteAccessURI . $semanticURI)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
View Code Duplication |
public function testAnalyseLink() |
97
|
|
|
{ |
98
|
|
|
$siteAccessURI = '/footestbar'; |
99
|
|
|
$semanticURI = '/something/hoho'; |
100
|
|
|
$matcher = new URITextMatcher( |
101
|
|
|
[ |
102
|
|
|
'prefix' => 'foo', |
103
|
|
|
'suffix' => 'bar', |
104
|
|
|
] |
105
|
|
|
); |
106
|
|
|
$matcher->setRequest(SimplifiedRequest::fromUrl('http://phoenix-rises.fm/footestbar/blabla')); |
107
|
|
|
|
108
|
|
|
$this->assertSame($siteAccessURI . $semanticURI, $matcher->analyseLink($semanticURI)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testReverseMatch() |
112
|
|
|
{ |
113
|
|
|
$semanticURI = '/hihi/hoho'; |
114
|
|
|
$matcher = new URITextMatcher( |
115
|
|
|
[ |
116
|
|
|
'prefix' => 'foo', |
117
|
|
|
'suffix' => 'bar', |
118
|
|
|
] |
119
|
|
|
); |
120
|
|
|
$matcher->setRequest(new SimplifiedRequest(['pathinfo' => $semanticURI])); |
121
|
|
|
|
122
|
|
|
$result = $matcher->reverseMatch('something'); |
123
|
|
|
$this->assertInstanceOf(URIText::class, $result); |
124
|
|
|
$request = $result->getRequest(); |
125
|
|
|
$this->assertInstanceOf(SimplifiedRequest::class, $request); |
126
|
|
|
$this->assertSame("/foosomethingbar{$semanticURI}", $request->pathinfo); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
View Code Duplication |
protected function createRouter(): Router |
130
|
|
|
{ |
131
|
|
|
return new Router( |
132
|
|
|
$this->matcherBuilder, |
133
|
|
|
$this->createMock(LoggerInterface::class), |
134
|
|
|
'default_sa', |
135
|
|
|
[ |
136
|
|
|
'URIText' => [ |
137
|
|
|
'prefix' => 'foo', |
138
|
|
|
'suffix' => 'bar', |
139
|
|
|
], |
140
|
|
|
'Map\\URI' => [ |
141
|
|
|
'first_sa' => 'first_sa', |
142
|
|
|
'second_sa' => 'second_sa', |
143
|
|
|
], |
144
|
|
|
'Map\\Host' => [ |
145
|
|
|
'first_sa' => 'first_sa', |
146
|
|
|
'first_siteaccess' => 'first_sa', |
147
|
|
|
], |
148
|
|
|
], |
149
|
|
|
$this->siteAccessProvider |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return \eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\SiteAccessSetting[] |
155
|
|
|
*/ |
156
|
|
View Code Duplication |
public function getSiteAccessProviderSettings(): array |
157
|
|
|
{ |
158
|
|
|
return [ |
159
|
|
|
new SiteAccessSetting('first_sa', true), |
160
|
|
|
new SiteAccessSetting('second_sa', true), |
161
|
|
|
new SiteAccessSetting('third_sa', true), |
162
|
|
|
new SiteAccessSetting('fourth_sa', true), |
163
|
|
|
new SiteAccessSetting('fifth_sa', true), |
164
|
|
|
new SiteAccessSetting('test', true), |
165
|
|
|
]; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|