Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
121a15bb
Commit
121a15bb
authored
Jul 14, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored route parameter parsing tests.
parent
537139a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
router.php
system/router.php
+1
-1
RouterTest.php
tests/suite/RouterTest.php
+25
-14
No files found.
system/router.php
View file @
121a15bb
...
...
@@ -107,7 +107,7 @@ class Router {
* @param string $route
* @return array
*/
p
ublic
static
function
parameters
(
$uri
,
$route
)
p
rivate
static
function
parameters
(
$uri
,
$route
)
{
return
array_values
(
array_intersect_key
(
explode
(
'/'
,
$uri
),
preg_grep
(
'/\(.+\)/'
,
explode
(
'/'
,
$route
))));
}
...
...
tests/suite/RouterTest.php
View file @
121a15bb
...
...
@@ -45,6 +45,16 @@ class RoutingTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
System\Router
::
route
(
'POST'
,
'home'
)
->
callback
[
'name'
],
'post-home'
);
}
public
function
testRouterGivesRouteProperSegmentsWhenTheyArePresent
()
{
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'user/1'
)
->
parameters
[
0
],
1
);
$this
->
assertEquals
(
count
(
System\Router
::
route
(
'GET'
,
'user/1'
)
->
parameters
),
1
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'user/taylor/25/edit'
)
->
parameters
[
0
],
'taylor'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'user/taylor/25/edit'
)
->
parameters
[
1
],
25
);
$this
->
assertEquals
(
count
(
System\Router
::
route
(
'GET'
,
'user/taylor/25/edit'
)
->
parameters
),
2
);
}
public
function
testRouterRoutesToProperRouteWhenUsingOptionalSegments
()
{
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'cart'
)
->
callback
[
'name'
],
'cart'
);
...
...
@@ -54,6 +64,21 @@ class RoutingTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download/1/a'
)
->
callback
[
'name'
],
'download'
);
}
public
function
testRouterGivesRouteProperOptionalSegmentsWhenTheyArePresent
()
{
$this
->
assertTrue
(
is_array
(
System\Router
::
route
(
'GET'
,
'cart'
)
->
parameters
));
$this
->
assertEquals
(
count
(
System\Router
::
route
(
'GET'
,
'cart'
)
->
parameters
),
0
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'cart/1'
)
->
parameters
[
0
],
1
);
$this
->
assertEquals
(
count
(
System\Router
::
route
(
'GET'
,
'download'
)
->
parameters
),
0
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download/1'
)
->
parameters
[
0
],
1
);
$this
->
assertEquals
(
count
(
System\Router
::
route
(
'GET'
,
'download/1'
)
->
parameters
),
1
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download/1/a'
)
->
parameters
[
0
],
1
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download/1/a'
)
->
parameters
[
1
],
'a'
);
$this
->
assertEquals
(
count
(
System\Router
::
route
(
'GET'
,
'download/1/a'
)
->
parameters
),
2
);
}
public
function
testRouterReturnsNullWhenRouteNotFound
()
{
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'user/taylor/taylor/edit'
));
...
...
@@ -97,18 +122,4 @@ class RoutingTest extends PHPUnit_Framework_TestCase {
file_put_contents
(
APP_PATH
.
'routes/cart.php'
,
"<?php return array('GET /cart/edit' => function() {return '/cart/edit';}); ?>"
,
LOCK_EX
);
}
public
function
testParameterMethodReturnsNoParametersWhenNoneArePresent
()
{
$this
->
assertEmpty
(
System\Router
::
parameters
(
'GET /test/route'
,
'GET /test/route'
));
$this
->
assertEmpty
(
System\Router
::
parameters
(
'GET /'
,
'GET /'
));
}
public
function
testParameterMethodReturnsParametersWhenTheyArePresent
()
{
$this
->
assertEquals
(
System\Router
::
parameters
(
'GET /user/1'
,
'GET /user/(:num)'
),
array
(
1
));
$this
->
assertEquals
(
System\Router
::
parameters
(
'GET /user/1/2'
,
'GET /user/(:num)/(:num)'
),
array
(
1
,
2
));
$this
->
assertEquals
(
System\Router
::
parameters
(
'GET /user/1/test'
,
'GET /user/(:num)/(:any)'
),
array
(
1
,
'test'
));
$this
->
assertEquals
(
System\Router
::
parameters
(
'GET /user/1/test/again'
,
'GET /user/(:num)/test/(:any)'
),
array
(
1
,
'again'
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment