forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiteralTest.php
133 lines (119 loc) · 3.58 KB
/
LiteralTest.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mvc
*/
namespace ZendTest\Mvc\Router\Http;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Http\Request as Request;
use Zend\Stdlib\Request as BaseRequest;
use Zend\Mvc\Router\Http\Literal;
use ZendTest\Mvc\Router\FactoryTester;
class LiteralTest extends TestCase
{
public static function routeProvider()
{
return array(
'simple-match' => array(
new Literal('/foo'),
'/foo',
null,
true
),
'no-match-without-leading-slash' => array(
new Literal('foo'),
'/foo',
null,
false
),
'no-match-with-trailing-slash' => array(
new Literal('/foo'),
'/foo/',
null,
false
),
'offset-skips-beginning' => array(
new Literal('foo'),
'/foo',
1,
true
),
'offset-enables-partial-matching' => array(
new Literal('/foo'),
'/foo/bar',
0,
true
),
);
}
/**
* @dataProvider routeProvider
* @param Literal $route
* @param string $path
* @param integer $offset
* @param boolean $shouldMatch
*/
public function testMatching(Literal $route, $path, $offset, $shouldMatch)
{
$request = new Request();
$request->setUri('http://example.com' . $path);
$match = $route->match($request, $offset);
if (!$shouldMatch) {
$this->assertNull($match);
} else {
$this->assertInstanceOf('Zend\Mvc\Router\Http\RouteMatch', $match);
if ($offset === null) {
$this->assertEquals(strlen($path), $match->getLength());
}
}
}
/**
* @dataProvider routeProvider
* @param Literal $route
* @param string $path
* @param integer $offset
* @param boolean $shouldMatch
*/
public function testAssembling(Literal $route, $path, $offset, $shouldMatch)
{
if (!$shouldMatch) {
// Data which will not match are not tested for assembling.
return;
}
$result = $route->assemble();
if ($offset !== null) {
$this->assertEquals($offset, strpos($path, $result, $offset));
} else {
$this->assertEquals($path, $result);
}
}
public function testNoMatchWithoutUriMethod()
{
$route = new Literal('/foo');
$request = new BaseRequest();
$this->assertNull($route->match($request));
}
public function testGetAssembledParams()
{
$route = new Literal('/foo');
$route->assemble(array('foo' => 'bar'));
$this->assertEquals(array(), $route->getAssembledParams());
}
public function testFactory()
{
$tester = new FactoryTester($this);
$tester->testFactory(
'Zend\Mvc\Router\Http\Literal',
array(
'route' => 'Missing "route" in options array'
),
array(
'route' => '/foo'
)
);
}
}