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
537139a2
Commit
537139a2
authored
Jul 14, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring test structure.
parent
d3398db5
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
181 additions
and
134 deletions
+181
-134
bootstrap.php
tests/bootstrap.php
+5
-0
InputTest.php
tests/suite/InputTest.php
+27
-0
RequestTest.php
tests/suite/RequestTest.php
+37
-0
RouteFilterTest.php
tests/suite/RouteFilterTest.php
+5
-5
RouteIsTest.php
tests/suite/RouteIsTest.php
+0
-41
RouteLoaderTest.php
tests/suite/RouteLoaderTest.php
+0
-63
RouteParserTest.php
tests/suite/RouteParserTest.php
+0
-19
RouteTest.php
tests/suite/RouteTest.php
+1
-0
RouterTest.php
tests/suite/RouterTest.php
+76
-6
utils.php
tests/utils.php
+30
-0
No files found.
tests/bootstrap.php
View file @
537139a2
...
...
@@ -20,6 +20,11 @@ define('EXT', '.php');
require
SYS_PATH
.
'config'
.
EXT
;
require
SYS_PATH
.
'arr'
.
EXT
;
// --------------------------------------------------------------
// Load the test utilities.
// --------------------------------------------------------------
require
'utils'
.
EXT
;
// --------------------------------------------------------------
// Register the auto-loader.
// --------------------------------------------------------------
...
...
tests/suite/InputTest.php
View file @
537139a2
...
...
@@ -75,6 +75,12 @@ class InputTest extends PHPUnit_Framework_TestCase {
$this
->
assertFalse
(
System\Input
::
has
(
'name'
));
}
public
function
testHasMethodReturnsFalseIfItemIsInInputButIsEmptyString
()
{
System\Input
::
$input
=
array
(
'name'
=>
''
);
$this
->
assertFalse
(
System\Input
::
has
(
'name'
));
}
public
function
testGetMethodReturnsItemByInputKey
()
{
System\Input
::
$input
=
array
(
'name'
=>
'taylor'
);
...
...
@@ -87,6 +93,7 @@ class InputTest extends PHPUnit_Framework_TestCase {
$this
->
assertNull
(
System\Input
::
get
(
'name'
));
$this
->
assertEquals
(
System\Input
::
get
(
'name'
,
'test'
),
'test'
);
$this
->
assertEquals
(
System\Input
::
get
(
'name'
,
function
()
{
return
'test'
;}),
'test'
);
$this
->
assertTrue
(
is_array
(
System\Input
::
get
())
and
count
(
System\Input
::
get
())
==
0
);
}
...
...
@@ -108,6 +115,15 @@ class InputTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
System\Input
::
file
(
'test.size'
),
500
);
}
public
function
testAllMethodReturnsBothGetAndFileArrays
()
{
$_GET
[
'name'
]
=
'test'
;
$_FILES
[
'picture'
]
=
array
();
$this
->
assertArrayHasKey
(
'name'
,
System\Input
::
all
());
$this
->
assertArrayHasKey
(
'picture'
,
System\Input
::
all
());
}
/**
* @expectedException Exception
*/
...
...
@@ -132,6 +148,17 @@ class InputTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
System\Input
::
old
(
'name'
),
'taylor'
);
}
public
function
testOldMethodReturnsDefaultValueWhenItemDoesntExist
()
{
System\Config
::
set
(
'session.driver'
,
'test'
);
System\Session
::
$session
[
'data'
][
'laravel_old_input'
]
=
array
();
$this
->
assertNull
(
System\Input
::
old
(
'name'
));
$this
->
assertEquals
(
System\Input
::
old
(
'name'
,
'test'
),
'test'
);
$this
->
assertEquals
(
System\Input
::
old
(
'name'
,
function
()
{
return
'test'
;}),
'test'
);
$this
->
assertTrue
(
is_array
(
System\Input
::
old
())
and
count
(
System\Input
::
old
())
==
0
);
}
public
function
testHadMethodReturnsTrueIfItemIsPresentInOldInputData
()
{
System\Config
::
set
(
'session.driver'
,
'test'
);
...
...
tests/suite/RequestTest.php
View file @
537139a2
...
...
@@ -5,6 +5,16 @@ class RequestTest extends PHPUnit_Framework_TestCase {
public
function
setUp
()
{
unset
(
$_SERVER
[
'PATH_INFO'
],
$_SERVER
[
'REQUEST_METHOD'
]);
$route
=
new
System\Route
(
null
,
null
);
$route
->
callback
=
array
(
'name'
=>
'test'
,
'do'
=>
function
()
{});
System\Request
::
$route
=
$route
;
}
public
function
tearDown
()
{
System\Request
::
$route
=
null
;
}
/**
...
...
@@ -128,8 +138,35 @@ class RequestTest extends PHPUnit_Framework_TestCase {
public
function
testMethodForSpoofedRequests
()
{
$_SERVER
[
'REQUEST_METHOD'
]
=
'GET'
;
$_POST
[
'REQUEST_METHOD'
]
=
'PUT'
;
$this
->
assertEquals
(
System\Request
::
method
(),
'PUT'
);
$_POST
[
'REQUEST_METHOD'
]
=
'DELETE'
;
$this
->
assertEquals
(
System\Request
::
method
(),
'DELETE'
);
}
public
function
testRouteIsReturnsFalseWhenNoSuchNamedRouteExists
()
{
$route
=
new
System\Route
(
null
,
null
);
$route
->
callback
=
function
()
{};
System\Request
::
$route
=
$route
;
$this
->
assertFalse
(
System\Request
::
route_is
(
'test'
));
$this
->
assertFalse
(
System\Request
::
route_is_test
());
}
public
function
testRouteIsReturnsFalseWhenWrongRouteNameIsGiven
()
{
$this
->
assertFalse
(
System\Request
::
route_is
(
'something'
));
$this
->
assertFalse
(
System\Request
::
route_is_something
());
}
public
function
testRouteIsReturnsTrueWhenNamedRouteExists
()
{
$this
->
assertTrue
(
System\Request
::
route_is
(
'test'
));
$this
->
assertTrue
(
System\Request
::
route_is_test
());
}
}
\ No newline at end of file
tests/suite/RouteFilterTest.php
View file @
537139a2
...
...
@@ -13,6 +13,11 @@ class RouteFilerTest extends PHPUnit_Framework_TestCase {
System\Route\Filter
::
$filters
=
$filters
;
}
public
static
function
tearDownAfterClass
()
{
System\Route\Filter
::
$filters
=
require
APP_PATH
.
'filters'
.
EXT
;
}
/**
* @expectedException Exception
*/
...
...
@@ -37,9 +42,4 @@ class RouteFilerTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
System\Route\Filter
::
call
(
'vars2'
,
array
(
'test1'
,
'test2'
),
true
),
'test1test2'
);
}
public
static
function
tearDownAfterClass
()
{
System\Route\Filter
::
$filters
=
require
APP_PATH
.
'filters'
.
EXT
;
}
}
\ No newline at end of file
tests/suite/RouteIsTest.php
deleted
100644 → 0
View file @
d3398db5
<?php
class
RouteIsTest
extends
PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
$route
=
new
System\Route
(
null
,
null
);
$route
->
callback
=
array
(
'name'
=>
'test'
,
'do'
=>
function
()
{});
System\Request
::
$route
=
$route
;
}
public
function
tearDown
()
{
System\Request
::
$route
=
null
;
}
public
function
testRouteIsReturnsFalseWhenNoName
()
{
$route
=
new
System\Route
(
null
,
null
);
$route
->
callback
=
function
()
{};
System\Request
::
$route
=
$route
;
$this
->
assertFalse
(
System\Request
::
route_is
(
'test'
));
$this
->
assertFalse
(
System\Request
::
route_is_test
());
}
public
function
testRouteIsReturnsFalseWhenWrongName
()
{
$this
->
assertFalse
(
System\Request
::
route_is
(
'something'
));
$this
->
assertFalse
(
System\Request
::
route_is_something
());
}
public
function
testRouteIsReturnsTrueWhenMatch
()
{
$this
->
assertTrue
(
System\Request
::
route_is
(
'test'
));
$this
->
assertTrue
(
System\Request
::
route_is_test
());
}
}
\ No newline at end of file
tests/suite/RouteLoaderTest.php
deleted
100644 → 0
View file @
d3398db5
<?php
class
RouteLoaderTest
extends
PHPUnit_Framework_TestCase
{
public
function
tearDown
()
{
$this
->
rrmdir
(
APP_PATH
.
'routes'
);
}
public
function
testRouteArrayShouldBeReturnedWhenUsingSingleRoutesFile
()
{
$routes
=
System\Router
::
load
(
'test'
);
$this
->
assertEquals
(
count
(
$routes
),
1
);
$this
->
assertArrayHasKey
(
'GET /'
,
$routes
);
$this
->
assertTrue
(
is_callable
(
$routes
[
'GET /'
]));
}
public
function
testRouteLoaderReturnsHomeRoutesWhenItIsOnlyFileInRoutesDirectory
()
{
mkdir
(
APP_PATH
.
'routes'
,
0777
);
file_put_contents
(
APP_PATH
.
'routes/home.php'
,
"<?php return array('GET /' => function() {return '/';}); ?>"
,
LOCK_EX
);
$this
->
assertEquals
(
count
(
System\Router
::
load
(
''
)),
1
);
}
public
function
testRouteLoaderWithRoutesDirectory
()
{
mkdir
(
APP_PATH
.
'routes'
,
0777
);
file_put_contents
(
APP_PATH
.
'routes/user.php'
,
"<?php return array('GET /user' => function() {return '/user';}); ?>"
,
LOCK_EX
);
$routes
=
System\Router
::
load
(
'user/home'
);
$this
->
assertEquals
(
count
(
$routes
),
2
);
$this
->
assertArrayHasKey
(
'GET /'
,
$routes
);
$this
->
assertArrayHasKey
(
'GET /user'
,
$routes
);
$this
->
assertTrue
(
is_callable
(
$routes
[
'GET /'
]));
$this
->
assertTrue
(
is_callable
(
$routes
[
'GET /user'
]));
}
/**
* Recursively Remove A Directory.
*/
public
function
rrmdir
(
$dir
)
{
if
(
is_dir
(
$dir
))
{
$objects
=
scandir
(
$dir
);
foreach
(
$objects
as
$object
)
{
if
(
$object
!=
"."
&&
$object
!=
".."
)
{
if
(
filetype
(
$dir
.
"/"
.
$object
)
==
"dir"
)
rrmdir
(
$dir
.
"/"
.
$object
);
else
unlink
(
$dir
.
"/"
.
$object
);
}
}
reset
(
$objects
);
rmdir
(
$dir
);
}
}
}
\ No newline at end of file
tests/suite/RouteParserTest.php
deleted
100644 → 0
View file @
d3398db5
<?php
class
RouteParserTest
extends
PHPUnit_Framework_TestCase
{
public
function
testParserReturnsNoParametersWhenNoneArePresent
()
{
$this
->
assertEmpty
(
System\Router
::
parameters
(
'/test/route'
,
'/test/route'
));
$this
->
assertEmpty
(
System\Router
::
parameters
(
'/'
,
'/'
));
}
public
function
testParserReturnsParametersWhenTheyArePresent
()
{
$this
->
assertEquals
(
System\Router
::
parameters
(
'/user/1'
,
'/user/(:num)'
),
array
(
1
));
$this
->
assertEquals
(
System\Router
::
parameters
(
'/user/1/2'
,
'/user/(:num)/(:num)'
),
array
(
1
,
2
));
$this
->
assertEquals
(
System\Router
::
parameters
(
'/user/1/test'
,
'/user/(:num)/(:any)'
),
array
(
1
,
'test'
));
$this
->
assertEquals
(
System\Router
::
parameters
(
'/user/1/test/again'
,
'/user/(:num)/test/(:any)'
),
array
(
1
,
'again'
));
}
}
\ No newline at end of file
tests/suite/RouteTest.php
View file @
537139a2
...
...
@@ -39,6 +39,7 @@ class RouteTest extends PHPUnit_Framework_TestCase {
{
$route
=
new
System\Route
(
'GET /'
,
array
(
'after'
=>
'test'
,
'do'
=>
function
()
{
return
'route'
;}));
System\Route\Filter
::
$filters
=
array
(
'test'
=>
function
()
{
define
(
'LARAVEL_TEST_AFTER_FILTER'
,
'ran'
);});
$route
->
call
();
$this
->
assertTrue
(
defined
(
'LARAVEL_TEST_AFTER_FILTER'
));
...
...
tests/suite/RouterTest.php
View file @
537139a2
...
...
@@ -6,39 +6,109 @@ class RoutingTest extends PHPUnit_Framework_TestCase {
{
$routes
=
array
();
$routes
[
'GET /'
]
=
function
()
{
return
'root'
;}
;
$routes
[
'GET /'
]
=
array
(
'name'
=>
'root'
,
'do'
=>
function
()
{})
;
$routes
[
'GET /home'
]
=
array
(
'name'
=>
'home'
,
'do'
=>
function
()
{});
$routes
[
'POST /home'
]
=
array
(
'name'
=>
'post-home'
,
'do'
=>
function
()
{});
$routes
[
'GET /user/(:num)'
]
=
array
(
'name'
=>
'user'
,
'do'
=>
function
()
{});
$routes
[
'GET /user/(:any)/(:num)/edit'
]
=
array
(
'name'
=>
'edit'
,
'do'
=>
function
()
{});
$routes
[
'GET /cart/(:num?)'
]
=
array
(
'name'
=>
'cart'
,
'do'
=>
function
()
{});
$routes
[
'GET /download/(:num?)/(:any?)'
]
=
array
(
'name'
=>
'download'
,
'do'
=>
function
()
{});
System\Router
::
$routes
=
$routes
;
}
public
static
function
tearDownAfterClass
()
{
System\Router
::
$routes
=
null
;
}
public
function
tearDown
()
{
Utils
::
rrmdir
(
APP_PATH
.
'routes'
);
}
public
function
testRouterReturnsNullWhenNotFound
()
{
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'not-found'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'doesnt-exist'
));
}
public
function
testRouterRoutesToRootWhenItIsRequest
()
{
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'/'
)
->
callback
[
'name'
],
'root'
);
}
public
function
testRouterRoutesToProperRouteWhenSegmentsArePresent
()
{
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'home'
)
->
callback
[
'name'
],
'home'
);
$this
->
assertEquals
(
System\Router
::
route
(
'POST'
,
'home'
)
->
callback
[
'name'
],
'post-home'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'user/1'
)
->
callback
[
'name'
],
'user'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'user/taylor/25/edit'
)
->
callback
[
'name'
],
'edit'
);
$this
->
assertEquals
(
System\Router
::
route
(
'POST'
,
'home'
)
->
callback
[
'name'
],
'post-home'
);
}
public
function
testRouterRoutesToProperRouteWhenUsingOptionalSegments
()
{
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'cart'
)
->
callback
[
'name'
],
'cart'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'cart/1'
)
->
callback
[
'name'
],
'cart'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download'
)
->
callback
[
'name'
],
'download'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download/1'
)
->
callback
[
'name'
],
'download'
);
$this
->
assertEquals
(
System\Router
::
route
(
'GET'
,
'download/1/a'
)
->
callback
[
'name'
],
'download'
);
}
public
function
testRouterReturnsNullWhenRouteNotFound
()
{
$this
->
assertNull
(
System\Router
::
route
(
'POST'
,
'user/taylor/25/edit'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'user/taylor/taylor/edit'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'user/taylor'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'user/12-3'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'cart/a'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'cart/12-3'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'download/a'
));
$this
->
assertNull
(
System\Router
::
route
(
'GET'
,
'download/1a'
));
$this
->
assertNull
(
System\Router
::
route
(
'POST'
,
'user/taylor/25/edit'
));
}
public
static
function
tearDownAfterClass
()
public
function
testRouteArrayShouldBeReturnedWhenUsingSingleRoutesFile
()
{
System\Router
::
$routes
=
null
;
$routes
=
System\Router
::
load
(
'test'
);
// Only the Laravel default route should be returned.
$this
->
assertArrayHasKey
(
'GET /'
,
$routes
);
}
public
function
testRouteLoaderLoadsRouteFilesInRouteDirectoryByURI
()
{
$this
->
setupRoutesDirectory
();
$this
->
assertArrayHasKey
(
'GET /user'
,
System\Router
::
load
(
'user'
));
$this
->
assertArrayHasKey
(
'GET /cart/edit'
,
System\Router
::
load
(
'cart'
));
$this
->
assertArrayHasKey
(
'GET /cart/edit'
,
System\Router
::
load
(
'cart/edit'
));
}
public
function
testRouteLoaderLoadsBaseRoutesFileForEveryRequest
()
{
$this
->
setupRoutesDirectory
();
$this
->
assertArrayHasKey
(
'GET /'
,
System\Router
::
load
(
'user'
));
}
private
function
setupRoutesDirectory
()
{
mkdir
(
APP_PATH
.
'routes'
,
0777
);
file_put_contents
(
APP_PATH
.
'routes/user.php'
,
"<?php return array('GET /user' => function() {return '/user';}); ?>"
,
LOCK_EX
);
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
tests/utils.php
0 → 100644
View file @
537139a2
<?php
class
Utils
{
/**
* Recursively remove a directory.
*
* @param string $directory
* @return void
*/
public
static
function
rrmdir
(
$directory
)
{
if
(
is_dir
(
$directory
))
{
$objects
=
scandir
(
$directory
);
foreach
(
$objects
as
$object
)
{
if
(
$object
!=
"."
&&
$object
!=
".."
)
{
if
(
filetype
(
$directory
.
"/"
.
$object
)
==
"dir"
)
static
::
rrmdir
(
$directory
.
"/"
.
$object
);
else
unlink
(
$directory
.
"/"
.
$object
);
}
}
reset
(
$objects
);
rmdir
(
$directory
);
}
}
}
\ 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