|
1
|
|
|
<?php |
|
2
|
|
|
namespace Wonnova\SDK\Test\Http; |
|
3
|
|
|
|
|
4
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
5
|
|
|
use Wonnova\SDK\Http\Route; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class RouteTest |
|
9
|
|
|
* @author Wonnova |
|
10
|
|
|
* @link http://www.wonnova.com |
|
11
|
|
|
*/ |
|
12
|
|
|
class RouteTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testSimpleRoute() |
|
15
|
|
|
{ |
|
16
|
|
|
$routePattern = '/foo/bar'; |
|
17
|
|
|
$route = new Route($routePattern); |
|
18
|
|
|
$this->assertEquals($routePattern, $route->__toString()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testRouteWithRouteParams() |
|
22
|
|
|
{ |
|
23
|
|
|
$routePattern = '/foo/%userId%/bar/%anotherParam%'; |
|
24
|
|
|
$route = new Route($routePattern, [ |
|
25
|
|
|
'userId' => '12345', |
|
26
|
|
|
'anotherParam' => 'value' |
|
27
|
|
|
]); |
|
28
|
|
|
$this->assertEquals('/foo/12345/bar/value', $route->__toString()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testRouteWithQueryParams() |
|
32
|
|
|
{ |
|
33
|
|
|
$routePattern = '/foo/bar'; |
|
34
|
|
|
$route = new Route($routePattern, [], [ |
|
35
|
|
|
'foo' => 1, |
|
36
|
|
|
'bar' => 2, |
|
37
|
|
|
'name' => 'wonnova' |
|
38
|
|
|
]); |
|
39
|
|
|
$this->assertEquals('/foo/bar?foo=1&bar=2&name=wonnova', $route->__toString()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testRouteWithAllParams() |
|
43
|
|
|
{ |
|
44
|
|
|
$routePattern = '/foo/%userId%/bar/%anotherParam%'; |
|
45
|
|
|
$route = new Route($routePattern, [ |
|
46
|
|
|
'userId' => '12345', |
|
47
|
|
|
'anotherParam' => 'value' |
|
48
|
|
|
], [ |
|
49
|
|
|
'foo' => 1, |
|
50
|
|
|
'bar' => 2 |
|
51
|
|
|
]); |
|
52
|
|
|
$this->assertEquals('/foo/12345/bar/value?foo=1&bar=2', $route->__toString()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testEmptyQueryParamsAreIgnored() |
|
56
|
|
|
{ |
|
57
|
|
|
$routePattern = '/foo/bar'; |
|
58
|
|
|
$route = new Route($routePattern, [], [ |
|
59
|
|
|
'foo' => null, |
|
60
|
|
|
'bar' => 'hello', |
|
61
|
|
|
'baz' => '' |
|
62
|
|
|
]); |
|
63
|
|
|
$this->assertEquals('/foo/bar?bar=hello', $route->__toString()); |
|
64
|
|
|
|
|
65
|
|
|
$route = new Route($routePattern, [], [ |
|
66
|
|
|
'foo' => null, |
|
67
|
|
|
'bar' => '' |
|
68
|
|
|
]); |
|
69
|
|
|
$this->assertEquals($routePattern, $route->__toString()); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|