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
ca19b5e7
Commit
ca19b5e7
authored
Sep 24, 2011
by
Eric Faerber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test cases for routes
parent
71d300f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
240 additions
and
0 deletions
+240
-0
RoutesTest.php
tests/Routes/RoutesTest.php
+131
-0
filters.php
tests/Routes/filters.php
+22
-0
routes.php
tests/Routes/routes.php
+87
-0
No files found.
tests/Routes/RoutesTest.php
0 → 100644
View file @
ca19b5e7
<?php
define
(
'TEST_BASE_PATH'
,
dirname
(
realpath
(
__FILE__
))
.
'/'
);
class
RoutesTest
extends
PHPUnit_Framework_TestCase
{
public
static
function
setUpBeforeClass
()
{
// changing paths
IoC
::
container
()
->
register
(
'laravel.routing.caller'
,
function
(
$c
)
{
return
new
\Laravel\Routing\Caller
(
$c
,
require
TEST_BASE_PATH
.
'filters'
.
EXT
,
CONTROLLER_PATH
);
});
IoC
::
container
()
->
register
(
'laravel.routing.loader'
,
function
(
$c
)
{
return
new
\Laravel\Routing\Loader
(
TEST_BASE_PATH
,
TEST_BASE_PATH
.
'routes/'
);
},
true
);
}
protected
function
setUp
()
{
$_POST
=
array
();
unset
(
$_SERVER
[
'REQUEST_URI'
],
$_SERVER
[
'REQUEST_METHOD'
]);
}
/**
* tests
* GET /test/wildcard/(:num)/(:any)
* GET /test/optwildcard/(:any+)
*/
public
function
testWildCards
()
{
$response
=
$this
->
processRoute
(
'/test/wildcard/123456/joe'
);
$this
->
assertEquals
(
$response
->
content
,
'123456/joe'
);
$response
=
$this
->
processRoute
(
'/test/wildcard/123456'
);
$this
->
assertEquals
(
$response
->
content
->
view
,
'error/404'
);
$response
=
$this
->
processRoute
(
'/test/wildcard/abc123'
);
$this
->
assertEquals
(
$response
->
content
,
'abc123'
);
$response
=
$this
->
processRoute
(
'/test/optwildcard/foo'
);
$this
->
assertEquals
(
$response
->
content
,
'foo'
);
$response
=
$this
->
processRoute
(
'/test/optwildcard'
);
$this
->
assertEquals
(
$response
->
content
,
''
);
}
/**
* tests GET /test/direct
*/
public
function
testDirect
()
{
$response
=
$this
->
processRoute
(
'/test/direct'
);
$this
->
assertEquals
(
$response
->
content
,
'direct'
);
$response
=
$this
->
processRoute
(
'/test/doesnt/exist'
);
$this
->
assertEquals
(
$response
->
content
->
view
,
'error/404'
);
}
/**
* tests GET /test/multi and GET /test/altmulti
* both routes are the same
*/
public
function
testMultiRoutes
()
{
$response
=
$this
->
processRoute
(
'/test/multi'
);
$this
->
assertEquals
(
$response
->
content
,
'multi test'
);
$response
=
$this
->
processRoute
(
'/test/altmulti'
);
$this
->
assertEquals
(
$response
->
content
,
'multi test'
);
}
/**
* tests post
*/
public
function
testPost
()
{
$response
=
$this
->
processRoute
(
'/test/postrequest'
,
'POST'
);
$this
->
assertEquals
(
$response
->
content
,
'POST request'
);
}
/**
* tests route spoofing
*/
public
function
testSpoofing
()
{
$_POST
[
'__spoofer'
]
=
'PUT'
;
$response
=
$this
->
processRoute
(
'/test/putrequest'
);
$this
->
assertEquals
(
$response
->
content
,
'PUT request'
);
}
/**
* tests filters
*/
public
function
testFilters
()
{
$response
=
$this
->
processRoute
(
'/test/filter/before'
);
$this
->
assertEquals
(
$response
->
content
,
'filtered before'
);
$response
=
$this
->
processRoute
(
'/test/filter/after'
);
$this
->
assertEquals
(
$response
->
content
,
'filtered after'
);
$response
=
$this
->
processRoute
(
'/test/filter/multi'
);
$this
->
assertEquals
(
$response
->
content
,
'filtered after filtered after2'
);
}
private
function
processRoute
(
$uri
,
$method
=
'GET'
)
{
$_SERVER
[
'REQUEST_URI'
]
=
$uri
;
$_SERVER
[
'REQUEST_METHOD'
]
=
$method
;
// not using container resolve because it is a singleton and that makes it so we can't change $_SERVER
$request
=
new
\Laravel\Request
(
new
\Laravel\URI
(
$_SERVER
),
$_SERVER
,
$_POST
);
$router
=
IoC
::
container
()
->
resolve
(
'laravel.routing.router'
);
list
(
$method
,
$uri
)
=
array
(
$request
->
method
(),
$request
->
uri
());
$route
=
$router
->
route
(
$request
,
$method
,
$uri
);
if
(
!
is_null
(
$route
))
{
$response
=
IoC
::
container
()
->
resolve
(
'laravel.routing.caller'
)
->
call
(
$route
);
}
else
{
$response
=
Response
::
error
(
'404'
);
}
return
$response
;
}
}
\ No newline at end of file
tests/Routes/filters.php
0 → 100644
View file @
ca19b5e7
<?php
return
array
(
'before_filter'
=>
function
()
{
return
'filtered before'
;
},
'after_filter'
=>
function
(
$response
)
{
$response
->
content
=
'filtered after'
;
return
$response
;
},
'after_filter2'
=>
function
(
$response
)
{
$response
->
content
.=
' filtered after2'
;
return
$response
;
},
);
\ No newline at end of file
tests/Routes/routes.php
0 → 100644
View file @
ca19b5e7
<?php
/**
* routes for test units
*/
return
array
(
/**
* wildcard test
*/
'GET /test/wildcard/(:num)/(:any)'
=>
function
(
$id
,
$name
)
{
return
$id
.
'/'
.
$name
;
},
/**
* regex wildcard
*/
'GET /test/wildcard/([a-z]{3}[0-9]{3})'
=>
function
(
$id
)
{
return
$id
;
},
/**
* wildcard with optional parameter
*/
'GET /test/optwildcard/(:any?)'
=>
function
(
$value
=
''
)
{
return
$value
;
},
/**
* direct path test
*/
'GET /test/direct'
=>
function
()
{
return
'direct'
;
},
/**
* multiple routes in one
*/
'GET /test/multi, GET /test/altmulti'
=>
function
()
{
return
'multi test'
;
},
/**
* post request
*/
'POST /test/postrequest'
=>
function
()
{
return
'POST request'
;
},
/**
* PUT request
*/
'PUT /test/putrequest'
=>
function
()
{
return
'PUT request'
;
},
/**
* before filter
*/
'GET /test/filter/before'
=>
array
(
'before'
=>
'before_filter'
,
function
()
{
return
'not filtered'
;
}),
/**
* after filter
*/
'GET /test/filter/after'
=>
array
(
'after'
=>
'after_filter'
,
function
()
{
return
'not filtered'
;
}),
/**
* multiple filters
*/
'GET /test/filter/multi'
=>
array
(
'after'
=>
'after_filter, after_filter2'
,
function
()
{
return
'not filtered'
;
}),
);
\ 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