Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
feefa8d9
Commit
feefa8d9
authored
Jul 13, 2012
by
Franz Liedke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix PHP errors in test cases related to now using Symfony's HttpFoundation component.
parent
86013f1b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
42 deletions
+92
-42
laravel/tests/cases/controller.test.php
+1
-1
laravel/tests/cases/redirect.test.php
+10
-10
laravel/tests/cases/request.test.php
+54
-24
laravel/tests/cases/response.test.php
+7
-5
laravel/tests/cases/uri.test.php
+20
-2
No files found.
laravel/tests/cases/controller.test.php
View file @
feefa8d9
...
...
@@ -189,7 +189,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase {
$_SERVER
[
'REQUEST_METHOD'
]
=
'PUT'
;
$this
->
assertEquals
(
404
,
Controller
::
call
(
'restful@index'
)
->
status
);
$this
->
assertEquals
(
404
,
Controller
::
call
(
'restful@index'
)
->
status
()
);
$_SERVER
[
'REQUEST_METHOD'
]
=
'POST'
;
...
...
laravel/tests/cases/redirect.test.php
View file @
feefa8d9
...
...
@@ -39,18 +39,18 @@ class RedirectTest extends PHPUnit_Framework_TestCase {
{
$redirect
=
Redirect
::
to
(
'user/profile'
);
$this
->
assertEquals
(
302
,
$redirect
->
status
);
$this
->
assertEquals
(
'http://localhost/user/profile'
,
$redirect
->
headers
[
'location'
]
);
$this
->
assertEquals
(
302
,
$redirect
->
status
()
);
$this
->
assertEquals
(
'http://localhost/user/profile'
,
$redirect
->
headers
()
->
get
(
'location'
)
);
$redirect
=
Redirect
::
to
(
'user/profile'
,
301
,
true
);
$this
->
assertEquals
(
301
,
$redirect
->
status
);
$this
->
assertEquals
(
'https://localhost/user/profile'
,
$redirect
->
headers
[
'location'
]
);
$this
->
assertEquals
(
301
,
$redirect
->
status
()
);
$this
->
assertEquals
(
'https://localhost/user/profile'
,
$redirect
->
headers
()
->
get
(
'location'
)
);
$redirect
=
Redirect
::
to_secure
(
'user/profile'
,
301
);
$this
->
assertEquals
(
301
,
$redirect
->
status
);
$this
->
assertEquals
(
'https://localhost/user/profile'
,
$redirect
->
headers
[
'location'
]
);
$this
->
assertEquals
(
301
,
$redirect
->
status
()
);
$this
->
assertEquals
(
'https://localhost/user/profile'
,
$redirect
->
headers
()
->
get
(
'location'
)
);
}
/**
...
...
@@ -64,10 +64,10 @@ class RedirectTest extends PHPUnit_Framework_TestCase {
Route
::
get
(
'redirect/(:any)/(:any)'
,
array
(
'as'
=>
'redirect-2'
));
Route
::
get
(
'secure/redirect'
,
array
(
'https'
=>
true
,
'as'
=>
'redirect-3'
));
$this
->
assertEquals
(
301
,
Redirect
::
to_route
(
'redirect'
,
array
(),
301
,
true
)
->
status
);
$this
->
assertEquals
(
'http://localhost/redirect'
,
Redirect
::
to_route
(
'redirect'
)
->
headers
[
'location'
]
);
$this
->
assertEquals
(
'https://localhost/secure/redirect'
,
Redirect
::
to_route
(
'redirect-3'
,
array
(),
302
)
->
headers
[
'location'
]
);
$this
->
assertEquals
(
'http://localhost/redirect/1/2'
,
Redirect
::
to_route
(
'redirect-2'
,
array
(
'1'
,
'2'
))
->
headers
[
'location'
]
);
$this
->
assertEquals
(
301
,
Redirect
::
to_route
(
'redirect'
,
array
(),
301
,
true
)
->
status
()
);
$this
->
assertEquals
(
'http://localhost/redirect'
,
Redirect
::
to_route
(
'redirect'
)
->
headers
()
->
get
(
'location'
)
);
$this
->
assertEquals
(
'https://localhost/secure/redirect'
,
Redirect
::
to_route
(
'redirect-3'
,
array
(),
302
)
->
headers
()
->
get
(
'location'
)
);
$this
->
assertEquals
(
'http://localhost/redirect/1/2'
,
Redirect
::
to_route
(
'redirect-2'
,
array
(
'1'
,
'2'
))
->
headers
()
->
get
(
'location'
)
);
}
/**
...
...
laravel/tests/cases/request.test.php
View file @
feefa8d9
<?php
use
Symfony\Component\HttpFoundation\LaravelRequest
as
RequestFoundation
;
class
SessionPayloadTokenStub
{
public
function
token
()
{
return
'Taylor'
;
}
...
...
@@ -20,17 +22,57 @@ class RequestTest extends PHPUnit_Framework_TestCase {
}
/**
* Set one of the $_SERVER variables.
*
* @param string $key
* @param string $value
*/
protected
function
setServerVar
(
$key
,
$value
)
{
$_SERVER
[
$key
]
=
$value
;
$this
->
restartRequest
();
}
/**
* Set one of the $_POST variables.
*
* @param string $key
* @param string $value
*/
protected
function
setPostVar
(
$key
,
$value
)
{
$_POST
[
$key
]
=
$value
;
$this
->
restartRequest
();
}
/**
* Reinitialize the global request.
*
* @return void
*/
protected
function
restartRequest
()
{
// FIXME: Ugly hack, but old contents from previous requests seem to
// trip up the Foundation class.
$_FILES
=
array
();
Request
::
$foundation
=
RequestFoundation
::
createFromGlobals
();
}
/**
* Test the Request::method method.
*
* @group laravel
*/
public
function
testMethodReturnsTheHTTPRequestMethod
()
{
$
_SERVER
[
'REQUEST_METHOD'
]
=
'POST'
;
$
this
->
setServerVar
(
'REQUEST_METHOD'
,
'POST'
)
;
$this
->
assertEquals
(
'POST'
,
Request
::
method
());
$
_POST
[
Request
::
spoofer
]
=
'PUT'
;
$
this
->
setPostVar
(
Request
::
spoofer
,
'PUT'
)
;
$this
->
assertEquals
(
'PUT'
,
Request
::
method
());
}
...
...
@@ -42,7 +84,8 @@ class RequestTest extends PHPUnit_Framework_TestCase {
*/
public
function
testServerMethodReturnsFromServerArray
()
{
$_SERVER
=
array
(
'TEST'
=>
'something'
,
'USER'
=>
array
(
'NAME'
=>
'taylor'
));
$this
->
setServerVar
(
'TEST'
,
'something'
);
$this
->
setServerVar
(
'USER'
,
array
(
'NAME'
=>
'taylor'
));
$this
->
assertEquals
(
'something'
,
Request
::
server
(
'test'
));
$this
->
assertEquals
(
'taylor'
,
Request
::
server
(
'user.name'
));
...
...
@@ -55,45 +98,32 @@ class RequestTest extends PHPUnit_Framework_TestCase {
*/
public
function
testIPMethodReturnsClientIPAddress
()
{
$
_SERVER
[
'REMOTE_ADDR'
]
=
'something'
;
$
this
->
setServerVar
(
'REMOTE_ADDR'
,
'something'
)
;
$this
->
assertEquals
(
'something'
,
Request
::
ip
());
$
_SERVER
[
'HTTP_CLIENT_IP'
]
=
'something'
;
$
this
->
setServerVar
(
'HTTP_CLIENT_IP'
,
'something'
)
;
$this
->
assertEquals
(
'something'
,
Request
::
ip
());
$
_SERVER
[
'HTTP_X_FORWARDED_FOR'
]
=
'something'
;
$
this
->
setServerVar
(
'HTTP_CLIENT_IP'
,
'something'
)
;
$this
->
assertEquals
(
'something'
,
Request
::
ip
());
$_SERVER
=
array
();
$this
->
restartRequest
();
$this
->
assertEquals
(
'0.0.0.0'
,
Request
::
ip
());
}
/**
* Test the Request::protocol method.
*
* @group laravel
*/
public
function
testProtocolMethodReturnsProtocol
()
{
$_SERVER
[
'SERVER_PROTOCOL'
]
=
'taylor'
;
$this
->
assertEquals
(
'taylor'
,
Request
::
protocol
());
unset
(
$_SERVER
[
'SERVER_PROTOCOL'
]);
$this
->
assertEquals
(
'HTTP/1.1'
,
Request
::
protocol
());
}
/**
* Test the Request::secure method.
*
* @group laravel
*/
public
function
testSecureMethodsIndicatesIfHTTPS
()
{
$
_SERVER
[
'HTTPS'
]
=
'on'
;
$
this
->
setServerVar
(
'HTTPS'
,
'on'
)
;
$this
->
assertTrue
(
Request
::
secure
());
$
_SERVER
[
'HTTPS'
]
=
'off'
;
$
this
->
setServerVar
(
'HTTPS'
,
'off'
)
;
$this
->
assertFalse
(
Request
::
secure
());
}
...
...
@@ -107,7 +137,7 @@ class RequestTest extends PHPUnit_Framework_TestCase {
{
$this
->
assertFalse
(
Request
::
ajax
());
$
_SERVER
[
'HTTP_X_REQUESTED_WITH'
]
=
'xmlhttprequest'
;
$
this
->
setServerVar
(
'HTTP_X_REQUESTED_WITH'
,
'XMLHttpRequest'
)
;
$this
->
assertTrue
(
Request
::
ajax
());
}
...
...
laravel/tests/cases/response.test.php
View file @
feefa8d9
...
...
@@ -12,8 +12,9 @@ class ResponseTest extends PHPUnit_Framework_TestCase {
$response
=
Response
::
make
(
'foo'
,
201
,
array
(
'bar'
=>
'baz'
));
$this
->
assertEquals
(
'foo'
,
$response
->
content
);
$this
->
assertEquals
(
201
,
$response
->
status
);
$this
->
assertEquals
(
array
(
'bar'
=>
'baz'
),
$response
->
headers
);
$this
->
assertEquals
(
201
,
$response
->
status
());
$this
->
assertArrayHasKey
(
'bar'
,
$response
->
headers
()
->
all
());
$this
->
assertEquals
(
'baz'
,
$response
->
headers
()
->
get
(
'bar'
));
}
/**
...
...
@@ -38,7 +39,7 @@ class ResponseTest extends PHPUnit_Framework_TestCase {
{
$response
=
Response
::
error
(
'404'
,
array
(
'name'
=>
'Taylor'
));
$this
->
assertEquals
(
404
,
$response
->
status
);
$this
->
assertEquals
(
404
,
$response
->
status
()
);
$this
->
assertEquals
(
'error.404'
,
$response
->
content
->
view
);
$this
->
assertEquals
(
'Taylor'
,
$response
->
content
->
data
[
'name'
]);
}
...
...
@@ -70,7 +71,7 @@ class ResponseTest extends PHPUnit_Framework_TestCase {
{
$response
=
Response
::
make
(
''
)
->
header
(
'foo'
,
'bar'
);
$this
->
assertEquals
(
'bar'
,
$response
->
headers
[
'foo'
]
);
$this
->
assertEquals
(
'bar'
,
$response
->
headers
()
->
get
(
'foo'
)
);
}
/**
...
...
@@ -82,7 +83,7 @@ class ResponseTest extends PHPUnit_Framework_TestCase {
{
$response
=
Response
::
make
(
''
)
->
status
(
404
);
$this
->
assertEquals
(
404
,
$response
->
status
);
$this
->
assertEquals
(
404
,
$response
->
status
()
);
}
}
\ No newline at end of file
laravel/tests/cases/uri.test.php
View file @
feefa8d9
<?php
use
Symfony\Component\HttpFoundation\LaravelRequest
as
RequestFoundation
;
class
URITest
extends
PHPUnit_Framework_TestCase
{
/**
...
...
@@ -13,6 +15,21 @@ class URITest extends PHPUnit_Framework_TestCase {
}
/**
* Set this request's URI to the given string
*
* @param string $uri
*/
protected
function
setRequestUri
(
$uri
)
{
// FIXME: Ugly hack, but old contents from previous requests seem to
// trip up the Foundation class.
$_FILES
=
array
();
$_SERVER
[
'REQUEST_URI'
]
=
$uri
;
Request
::
$foundation
=
RequestFoundation
::
createFromGlobals
();
}
/**
* Test the URI::current method.
*
* @group laravel
...
...
@@ -20,7 +37,8 @@ class URITest extends PHPUnit_Framework_TestCase {
*/
public
function
testCorrectURIIsReturnedByCurrentMethod
(
$uri
,
$expectation
)
{
$_SERVER
[
'REQUEST_URI'
]
=
$uri
;
$this
->
setRequestUri
(
$uri
);
$this
->
assertEquals
(
$expectation
,
URI
::
current
());
}
...
...
@@ -31,7 +49,7 @@ class URITest extends PHPUnit_Framework_TestCase {
*/
public
function
testSegmentMethodReturnsAURISegment
()
{
$
_SERVER
[
'REQUEST_URI'
]
=
'http://localhost/index.php/user/profile'
;
$
this
->
setRequestUri
(
'http://localhost/index.php/user/profile'
)
;
$this
->
assertEquals
(
'user'
,
URI
::
segment
(
1
));
$this
->
assertEquals
(
'profile'
,
URI
::
segment
(
2
));
...
...
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