|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests\RouterURIElement2Test 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
|
|
|
* @version //autogentag// |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\SiteAccess\Tests; |
|
12
|
|
|
|
|
13
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess; |
|
14
|
|
|
use PHPUnit_Framework_TestCase; |
|
15
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Router; |
|
16
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIElement as URIElementMatcher; |
|
17
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest; |
|
18
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\MatcherBuilder; |
|
19
|
|
|
|
|
20
|
|
|
class RouterURIElement2Test extends PHPUnit_Framework_TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\MatcherBuilder |
|
24
|
|
|
*/ |
|
25
|
|
|
private $matcherBuilder; |
|
26
|
|
|
|
|
27
|
|
|
protected function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
parent::setUp(); |
|
30
|
|
|
$this->matcherBuilder = new MatcherBuilder(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
public function testConstruct() |
|
34
|
|
|
{ |
|
35
|
|
|
return new Router( |
|
36
|
|
|
$this->matcherBuilder, |
|
37
|
|
|
$this->getMock('Psr\\Log\\LoggerInterface'), |
|
38
|
|
|
'default_sa', |
|
39
|
|
|
array( |
|
40
|
|
|
'URIElement' => array( |
|
41
|
|
|
'value' => 2, |
|
42
|
|
|
), |
|
43
|
|
|
'Map\\URI' => array( |
|
44
|
|
|
'first_sa' => 'first_sa', |
|
45
|
|
|
'second_sa' => 'second_sa', |
|
46
|
|
|
), |
|
47
|
|
|
'Map\\Host' => array( |
|
48
|
|
|
'first_sa' => 'first_sa', |
|
49
|
|
|
'first_siteaccess' => 'first_sa', |
|
50
|
|
|
), |
|
51
|
|
|
), |
|
52
|
|
|
array('first_sa', 'second_sa', 'third_sa', 'fourth_sa', 'fifth_sa', 'foo_baz', 'test_foo', 'first_sa_foo', 'second_sa_foo') |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @depends testConstruct |
|
58
|
|
|
* @dataProvider matchProvider |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testMatch(SimplifiedRequest $request, $siteAccess, Router $router) |
|
61
|
|
|
{ |
|
62
|
|
|
$sa = $router->match($request); |
|
63
|
|
|
$this->assertInstanceOf('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess', $sa); |
|
64
|
|
|
$this->assertSame($siteAccess, $sa->name); |
|
65
|
|
|
$router->setSiteAccess(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
public function matchProvider() |
|
69
|
|
|
{ |
|
70
|
|
|
return array( |
|
71
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com'), 'default_sa'), |
|
72
|
|
|
array(SimplifiedRequest::fromUrl('https://example.com'), 'default_sa'), |
|
73
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/'), 'default_sa'), |
|
74
|
|
|
array(SimplifiedRequest::fromUrl('https://example.com/'), 'default_sa'), |
|
75
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com//'), 'default_sa'), |
|
76
|
|
|
array(SimplifiedRequest::fromUrl('https://example.com//'), 'default_sa'), |
|
77
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com:8080/'), 'default_sa'), |
|
78
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/first_siteaccess/'), 'default_sa'), |
|
79
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/?first_siteaccess'), 'default_sa'), |
|
80
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/?first_sa'), 'default_sa'), |
|
81
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/first_salt'), 'default_sa'), |
|
82
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/first_sa.foo'), 'default_sa'), |
|
83
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/test'), 'default_sa'), |
|
84
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/test/foo/'), 'test_foo'), |
|
85
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/'), 'test_foo'), |
|
86
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/test/foo/bar/first_sa'), 'test_foo'), |
|
87
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/default_sa'), 'default_sa'), |
|
88
|
|
|
|
|
89
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/first_sa'), 'first_sa'), |
|
90
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/first_sa/'), 'first_sa'), |
|
91
|
|
|
// Double slashes shouldn't be considered as one |
|
92
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com//first_sa//'), 'default_sa'), |
|
93
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com///first_sa///test'), 'default_sa'), |
|
94
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com//first_sa//foo/bar'), 'default_sa'), |
|
95
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess:82/foo//bar/'), 'first_sa'), |
|
96
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/first_sa/foo'), 'first_sa_foo'), |
|
97
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com:82/first_sa/'), 'first_sa'), |
|
98
|
|
|
array(SimplifiedRequest::fromUrl('http://third_siteaccess/first_sa/'), 'first_sa'), |
|
99
|
|
|
array(SimplifiedRequest::fromUrl('http://first_sa/'), 'first_sa'), |
|
100
|
|
|
array(SimplifiedRequest::fromUrl('https://first_sa/'), 'first_sa'), |
|
101
|
|
|
array(SimplifiedRequest::fromUrl('http://first_sa:81/'), 'first_sa'), |
|
102
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess/'), 'first_sa'), |
|
103
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess:82/'), 'first_sa'), |
|
104
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess:83/'), 'first_sa'), |
|
105
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess/foo/'), 'first_sa'), |
|
106
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess:83/foo/baz/'), 'foo_baz'), |
|
107
|
|
|
|
|
108
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/second_sa'), 'second_sa'), |
|
109
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/second_sa/'), 'second_sa'), |
|
110
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/second_sa?param1=foo'), 'second_sa'), |
|
111
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com/second_sa/foo/'), 'second_sa_foo'), |
|
112
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com:82/second_sa/'), 'second_sa'), |
|
113
|
|
|
array(SimplifiedRequest::fromUrl('http://example.com:83/second_sa/'), 'second_sa'), |
|
114
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess:82/second_sa/'), 'second_sa'), |
|
115
|
|
|
array(SimplifiedRequest::fromUrl('http://first_siteaccess:83/second_sa/'), 'second_sa'), |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param int $level |
|
121
|
|
|
* @param string $uri |
|
122
|
|
|
* @param string $expectedFixedUpURI |
|
123
|
|
|
* |
|
124
|
|
|
* @dataProvider analyseProvider |
|
125
|
|
|
*/ |
|
126
|
|
View Code Duplication |
public function testAnalyseURI($level, $uri, $expectedFixedUpURI) |
|
127
|
|
|
{ |
|
128
|
|
|
$matcher = new URIElementMatcher(array($level)); |
|
129
|
|
|
$matcher->setRequest( |
|
130
|
|
|
new SimplifiedRequest(array('pathinfo' => $uri)) |
|
131
|
|
|
); |
|
132
|
|
|
$this->assertSame($expectedFixedUpURI, $matcher->analyseURI($uri)); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param int $level |
|
137
|
|
|
* @param string $uri |
|
138
|
|
|
* @param string $expectedFixedUpURI |
|
139
|
|
|
* |
|
140
|
|
|
* @dataProvider analyseProvider |
|
141
|
|
|
*/ |
|
142
|
|
View Code Duplication |
public function testAnalyseURILevelAsInt($level, $uri, $expectedFixedUpURI) |
|
143
|
|
|
{ |
|
144
|
|
|
$matcher = new URIElementMatcher($level); |
|
145
|
|
|
$matcher->setRequest( |
|
146
|
|
|
new SimplifiedRequest(array('pathinfo' => $uri)) |
|
147
|
|
|
); |
|
148
|
|
|
$this->assertSame($expectedFixedUpURI, $matcher->analyseURI($uri)); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param int $level |
|
153
|
|
|
* @param string $fullUri |
|
154
|
|
|
* @param string $linkUri |
|
155
|
|
|
* |
|
156
|
|
|
* @dataProvider analyseProvider |
|
157
|
|
|
*/ |
|
158
|
|
View Code Duplication |
public function testAnalyseLink($level, $fullUri, $linkUri) |
|
159
|
|
|
{ |
|
160
|
|
|
$matcher = new URIElementMatcher(array($level)); |
|
161
|
|
|
$matcher->setRequest( |
|
162
|
|
|
new SimplifiedRequest(array('pathinfo' => $fullUri)) |
|
163
|
|
|
); |
|
164
|
|
|
$this->assertSame($fullUri, $matcher->analyseLink($linkUri)); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function analyseProvider() |
|
168
|
|
|
{ |
|
169
|
|
|
return array( |
|
170
|
|
|
array(2, '/my/siteaccess/foo/bar', '/foo/bar'), |
|
171
|
|
|
array(2, '/vive/le/sucre/en-poudre', '/sucre/en-poudre'), |
|
172
|
|
|
// Issue https://jira.ez.no/browse/EZP-20125 |
|
173
|
|
|
array(1, '/fre/content/edit/104/1/fre-FR', '/content/edit/104/1/fre-FR'), |
|
174
|
|
|
array(1, '/fre/utf8-with-accent/é/fre/à/à/fre/é', '/utf8-with-accent/é/fre/à/à/fre/é'), |
|
175
|
|
|
array(2, '/é/fre/utf8-with-accent/é/fre/à/à/fre/é', '/utf8-with-accent/é/fre/à/à/fre/é'), |
|
176
|
|
|
array(2, '/prefix/fre/url/alias/prefix/fre/prefix/fre/url', '/url/alias/prefix/fre/prefix/fre/url'), |
|
177
|
|
|
// regression after the first fix of EZP-20125 |
|
178
|
|
|
array(1, '/sitaccess', ''), |
|
179
|
|
|
array(1, '/sitaccess/', '/'), |
|
180
|
|
|
array(2, '/prefix/siteaccess', ''), |
|
181
|
|
|
array(2, '/prefix/siteaccess/', '/'), |
|
182
|
|
|
); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @dataProvider reverseMatchProvider |
|
187
|
|
|
*/ |
|
188
|
|
|
public function testReverseMatch($siteAccessName, $originalPathinfo) |
|
189
|
|
|
{ |
|
190
|
|
|
$expectedSiteAccessPath = implode('/', explode('_', $siteAccessName)); |
|
191
|
|
|
$matcher = new URIElementMatcher(array(2)); |
|
192
|
|
|
$matcher->setRequest(new SimplifiedRequest(array('pathinfo' => $originalPathinfo))); |
|
193
|
|
|
|
|
194
|
|
|
$result = $matcher->reverseMatch($siteAccessName); |
|
195
|
|
|
$this->assertInstanceOf('eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIElement', $result); |
|
196
|
|
|
$this->assertSame("/{$expectedSiteAccessPath}{$originalPathinfo}", $result->getRequest()->pathinfo); |
|
197
|
|
|
$this->assertSame("/$expectedSiteAccessPath/some/linked/uri", $result->analyseLink('/some/linked/uri')); |
|
198
|
|
|
$this->assertSame('/foo/bar/baz', $result->analyseURI("/$expectedSiteAccessPath/foo/bar/baz")); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function reverseMatchProvider() |
|
202
|
|
|
{ |
|
203
|
|
|
return array( |
|
204
|
|
|
array('some_thing', '/foo/bar'), |
|
205
|
|
|
array('another_siteaccess', '/foo/bar'), |
|
206
|
|
|
); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function testReverseMatchFail() |
|
210
|
|
|
{ |
|
211
|
|
|
$matcher = new URIElementMatcher(array(2)); |
|
212
|
|
|
$matcher->setRequest(new SimplifiedRequest(array('pathinfo' => '/my/siteaccess/foo/bar'))); |
|
213
|
|
|
$this->assertNull($matcher->reverseMatch('another_siteaccess_again_dont_tell_me')); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
View Code Duplication |
public function testSerialize() |
|
217
|
|
|
{ |
|
218
|
|
|
$matcher = new URIElementMatcher(array(2)); |
|
219
|
|
|
$matcher->setRequest(new SimplifiedRequest(array('pathinfo' => '/foo/bar'))); |
|
220
|
|
|
$sa = new SiteAccess('test', 'test', $matcher); |
|
221
|
|
|
$serializedSA1 = serialize($sa); |
|
222
|
|
|
|
|
223
|
|
|
$matcher->setRequest(new SimplifiedRequest(array('pathinfo' => '/foo/bar/baz'))); |
|
224
|
|
|
$serializedSA2 = serialize($sa); |
|
225
|
|
|
|
|
226
|
|
|
$this->assertSame($serializedSA1, $serializedSA2); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|