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
d0771493
Commit
d0771493
authored
Oct 11, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished tests for request class.
parent
0cb81d85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
2 deletions
+86
-2
request.php
laravel/request.php
+1
-1
RequestTest.php
tests/Cases/RequestTest.php
+85
-1
No files found.
laravel/request.php
View file @
d0771493
...
...
@@ -165,7 +165,7 @@ class Request {
*/
public
static
function
protocol
()
{
return
(
isset
(
$_SERVER
[
'HTTPS'
])
and
$_SERVER
[
'HTTPS'
]
!==
'off'
)
?
'https'
:
'http'
;
return
(
isset
(
$_SERVER
[
'HTTPS'
])
and
strtolower
(
$_SERVER
[
'HTTPS'
])
!==
'off'
)
?
'https'
:
'http'
;
}
/**
...
...
tests/Cases/RequestTest.php
View file @
d0771493
...
...
@@ -4,7 +4,9 @@ class RequestTest extends PHPUnit_Framework_TestCase {
public
function
setUp
()
{
$_POST
=
array
();
$_SERVER
=
array
();
Laravel\Request
::
$uri
=
null
;
}
...
...
@@ -28,10 +30,92 @@ class RequestTest extends PHPUnit_Framework_TestCase {
public
function
test_correct_uri_is_returned_when_request_uri_is_used
(
$uri
,
$expectation
)
{
$_SERVER
[
'REQUEST_URI'
]
=
$uri
;
$this
->
assertEquals
(
$expectation
,
Laravel\Request
::
uri
());
}
public
function
test_format_returns_the_extension_of_the_request_uri
()
{
$_SERVER
[
'PATH_INFO'
]
=
'profile.json'
;
$this
->
assertEquals
(
'json'
,
Laravel\Request
::
format
());
}
public
function
test_format_returns_html_if_no_format_is_available
()
{
$_SERVER
[
'PATH_INFO'
]
=
'profile'
;
$this
->
assertEquals
(
'html'
,
Laravel\Request
::
format
());
}
public
function
test_request_method_returns_spoofed_method_if_uri_is_spoofed
()
{
$_POST
=
array
(
Laravel\Request
::
spoofer
=>
'something'
);
$this
->
assertEquals
(
'something'
,
Laravel\Request
::
method
());
}
public
function
test_request_method_returns_request_method_from_server_array
()
{
$_SERVER
[
'REQUEST_METHOD'
]
=
'PUT'
;
$this
->
assertEquals
(
'PUT'
,
Laravel\Request
::
method
());
}
public
function
test_server_method_returns_from_the_server_array
()
{
$_SERVER
=
array
(
'TEST'
=>
'something'
,
'USER'
=>
array
(
'NAME'
=>
'taylor'
));
$this
->
assertEquals
(
'something'
,
Laravel\Request
::
server
(
'test'
));
$this
->
assertEquals
(
'taylor'
,
Laravel\Request
::
server
(
'user.name'
));
}
public
function
test_spoofed_returns_true_when_request_is_spoofed
()
{
$_POST
[
Laravel\Request
::
spoofer
]
=
'something'
;
$this
->
assertTrue
(
Laravel\Request
::
spoofed
());
}
public
function
test_spoofed_returns_false_when_request_isnt_spoofed
()
{
$this
->
assertFalse
(
Laravel\Request
::
spoofed
());
}
public
function
test_ip_method_returns_client_ip_address
()
{
$_SERVER
[
'REMOTE_ADDR'
]
=
'something'
;
$this
->
assertEquals
(
'something'
,
Laravel\Request
::
ip
());
$_SERVER
[
'HTTP_CLIENT_IP'
]
=
'something'
;
$this
->
assertEquals
(
'something'
,
Laravel\Request
::
ip
());
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
]
=
'something'
;
$this
->
assertEquals
(
'something'
,
Laravel\Request
::
ip
());
$_SERVER
=
array
();
$this
->
assertEquals
(
'0.0.0.0'
,
Laravel\Request
::
ip
());
}
public
function
test_protocol_returns_http_when_not_https
()
{
$this
->
assertEquals
(
'http'
,
Laravel\Request
::
protocol
());
$_SERVER
[
'HTTPS'
]
=
'off'
;
$this
->
assertEquals
(
'http'
,
Laravel\Request
::
protocol
());
}
public
function
test_protocol_returns_https_when_https
()
{
$_SERVER
[
'HTTPS'
]
=
'on'
;
$this
->
assertEquals
(
'https'
,
Laravel\Request
::
protocol
());
}
public
function
test_ajax_method_returns_false_when_not_ajax
()
{
$this
->
assertFalse
(
Laravel\Request
::
ajax
());
}
public
function
test_ajax_method_returns_true_when_ajax
()
{
$_SERVER
[
'HTTP_X_REQUESTED_WITH'
]
=
'xmlhttprequest'
;
$this
->
assertTrue
(
Laravel\Request
::
ajax
());
}
public
function
requestUriProvider
()
{
return
array
(
...
...
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