/
UrlTest.php
69 lines (53 loc) · 1.9 KB
/
UrlTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class UrlTest extends \BaseTestCase
{
public function caseSetUp()
{
}
public function testUrl()
{
$url = new \Exedra\Url\Url('http://localhost/test');
$this->assertEquals('http://localhost/test', $url);
}
public function testFactory()
{
$app = new \Exedra\Application(__DIR__);
$app->map['foo']->get('/bar')->execute(function(){});
$factory = new \Exedra\Url\UrlFactory($app->map, null, 'http://localhost');
$this->assertEquals((string) $factory->to('hello'), 'http://localhost/hello');
$this->assertEquals((string) $factory->to('hello')->setHost('192.168.1.100'), 'http://192.168.1.100/hello');
$this->assertEquals($factory->route('foo')->addQueryParam('baz', 'bat')->addQueryParams(array('baft' => 'jazt', 'taz' => 'tux')), 'http://localhost/bar?baz=bat&baft=jazt&taz=tux');
$url = $factory->to('foo-bar');
$url->setQueryParams(array(
'foo' => 'bar',
'baz' => array('bad')
));
$url->addQueryParam('qux', array(
'tux' => 'new',
'eqa' => array(
'opa' => array(
'gan' => 'nam'
)
)
));
$this->assertEquals(array(
'foo' => 'bar',
'baz' => array('bad'),
'qux' => array(
'tux' => 'new',
'eqa' => array(
'opa' => array(
'gan' => 'nam'
)
)
)
), $url->getQueryParams());
}
public function testGenerator()
{
$app = new \Exedra\Application(__DIR__);
$app->map['foo']->get('/fox')->execute(function(){});
$generator = new \Exedra\Url\UrlGenerator($app->map, null, 'http://localhost');
$this->assertEquals($generator->to('foobar'), 'http://localhost/foobar');
}
}