1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the RouterMapURITest 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\Matcher\Map\URI as URIMapMatcher; |
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest; |
15
|
|
|
use PHPUnit_Framework_TestCase; |
16
|
|
|
|
17
|
|
|
class RouterMapURITest extends PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param array $config |
21
|
|
|
* @param string $pathinfo |
22
|
|
|
* @param string $expectedMapKey |
23
|
|
|
* |
24
|
|
|
* @dataProvider setRequestProvider |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
public function testSetGetRequest($config, $pathinfo, $expectedMapKey) |
27
|
|
|
{ |
28
|
|
|
$request = new SimplifiedRequest(array('pathinfo' => $pathinfo)); |
29
|
|
|
$matcher = new URIMapMatcher($config); |
30
|
|
|
$matcher->setRequest($request); |
31
|
|
|
$this->assertSame($request, $matcher->getRequest()); |
32
|
|
|
$this->assertSame($expectedMapKey, $matcher->getMapKey()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $uri |
37
|
|
|
* @param string $expectedFixedUpURI |
38
|
|
|
* |
39
|
|
|
* @dataProvider fixupURIProvider |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
public function testAnalyseURI($uri, $expectedFixedUpURI) |
42
|
|
|
{ |
43
|
|
|
$matcher = new URIMapMatcher(array()); |
44
|
|
|
$matcher->setRequest( |
45
|
|
|
new SimplifiedRequest(array('pathinfo' => $uri)) |
46
|
|
|
); |
47
|
|
|
$this->assertSame($expectedFixedUpURI, $matcher->analyseURI($uri)); |
48
|
|
|
// Unserialized matcher should have the same behavior |
49
|
|
|
$unserializedMatcher = unserialize(serialize($matcher)); |
50
|
|
|
$this->assertSame($expectedFixedUpURI, $unserializedMatcher->analyseURI($uri)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $fullUri |
55
|
|
|
* @param string $linkUri |
56
|
|
|
* |
57
|
|
|
* @dataProvider fixupURIProvider |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function testAnalyseLink($fullUri, $linkUri) |
60
|
|
|
{ |
61
|
|
|
$matcher = new URIMapMatcher(array()); |
62
|
|
|
$matcher->setRequest( |
63
|
|
|
new SimplifiedRequest(array('pathinfo' => $fullUri)) |
64
|
|
|
); |
65
|
|
|
$this->assertSame($fullUri, $matcher->analyseLink($linkUri)); |
66
|
|
|
// Unserialized matcher should have the same behavior |
67
|
|
|
$unserializedMatcher = unserialize(serialize($matcher)); |
68
|
|
|
$this->assertSame($fullUri, $unserializedMatcher->analyseLink($linkUri)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function setRequestProvider() |
72
|
|
|
{ |
73
|
|
|
return array( |
74
|
|
|
array(array('foo' => 'bar'), '/bar/baz', 'bar'), |
75
|
|
|
array(array('foo' => 'Äpfel'), '/%C3%84pfel/foo', 'Äpfel'), |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function fixupURIProvider() |
80
|
|
|
{ |
81
|
|
|
return array( |
82
|
|
|
array('/foo', '/'), |
83
|
|
|
array('/Äpfel', '/'), |
84
|
|
|
array('/my_siteaccess/foo/bar', '/foo/bar'), |
85
|
|
|
array('/foo/foo/bar', '/foo/bar'), |
86
|
|
|
array('/foo/foo/bar?something=foo&bar=toto', '/foo/bar?something=foo&bar=toto'), |
87
|
|
|
array('/vive/le/sucre', '/le/sucre'), |
88
|
|
|
array('/ezdemo_site/some/thing?foo=ezdemo_site&bar=toto', '/some/thing?foo=ezdemo_site&bar=toto'), |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testReverseMatchFail() |
93
|
|
|
{ |
94
|
|
|
$config = array('foo' => 'bar'); |
95
|
|
|
$matcher = new URIMapMatcher($config); |
96
|
|
|
$this->assertNull($matcher->reverseMatch('non_existent')); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
public function testReverseMatch() |
100
|
|
|
{ |
101
|
|
|
$config = array( |
102
|
|
|
'some_uri' => 'some_siteaccess', |
103
|
|
|
'something_else' => 'another_siteaccess', |
104
|
|
|
'toutouyoutou' => 'ezdemo_site', |
105
|
|
|
); |
106
|
|
|
$request = new SimplifiedRequest(array('pathinfo' => '/foo')); |
107
|
|
|
$matcher = new URIMapMatcher($config); |
108
|
|
|
$matcher->setRequest($request); |
109
|
|
|
|
110
|
|
|
$result = $matcher->reverseMatch('ezdemo_site'); |
111
|
|
|
$this->assertInstanceOf('eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\Map\URI', $result); |
112
|
|
|
$this->assertSame($request, $matcher->getRequest()); |
113
|
|
|
$this->assertSame('toutouyoutou', $result->getMapKey()); |
114
|
|
|
$this->assertSame('/toutouyoutou/foo', $result->getRequest()->pathinfo); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|