Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ef5afef7
Commit
ef5afef7
authored
Jun 09, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed test break.
parent
ec8de608
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
51 deletions
+28
-51
Response.php
framework/yii/web/Response.php
+15
-4
ResponseTest.php
tests/unit/framework/web/ResponseTest.php
+13
-47
No files found.
framework/yii/web/Response.php
View file @
ef5afef7
...
@@ -118,7 +118,7 @@ class Response extends \yii\base\Response
...
@@ -118,7 +118,7 @@ class Response extends \yii\base\Response
511
=>
'Network Authentication Required'
,
511
=>
'Network Authentication Required'
,
);
);
private
$_statusCode
=
200
;
private
$_statusCode
;
/**
/**
* @var HeaderCollection
* @var HeaderCollection
*/
*/
...
@@ -199,6 +199,14 @@ class Response extends \yii\base\Response
...
@@ -199,6 +199,14 @@ class Response extends \yii\base\Response
$this
->
sendContent
();
$this
->
sendContent
();
}
}
public
function
reset
()
{
$this
->
_headers
=
null
;
$this
->
_statusCode
=
null
;
$this
->
statusText
=
null
;
$this
->
content
=
null
;
}
/**
/**
* Sends the response headers to the client
* Sends the response headers to the client
*/
*/
...
@@ -207,7 +215,10 @@ class Response extends \yii\base\Response
...
@@ -207,7 +215,10 @@ class Response extends \yii\base\Response
if
(
headers_sent
())
{
if
(
headers_sent
())
{
return
;
return
;
}
}
header
(
"HTTP/
{
$this
->
version
}
"
.
$this
->
getStatusCode
()
.
"
{
$this
->
statusText
}
"
);
$statusCode
=
$this
->
getStatusCode
();
if
(
$statusCode
!==
null
)
{
header
(
"HTTP/
{
$this
->
version
}
$statusCode
{
$this
->
statusText
}
"
);
}
if
(
$this
->
_headers
)
{
if
(
$this
->
_headers
)
{
$headers
=
$this
->
getHeaders
();
$headers
=
$this
->
getHeaders
();
foreach
(
$headers
as
$name
=>
$values
)
{
foreach
(
$headers
as
$name
=>
$values
)
{
...
@@ -334,10 +345,10 @@ class Response extends \yii\base\Response
...
@@ -334,10 +345,10 @@ class Response extends \yii\base\Response
ob_start
();
ob_start
();
Yii
::
$app
->
end
(
0
,
false
);
Yii
::
$app
->
end
(
0
,
false
);
ob_end_clean
();
ob_end_clean
();
echo
$content
;
$this
->
content
=
$content
;
exit
(
0
);
exit
(
0
);
}
else
{
}
else
{
echo
$content
;
$this
->
content
=
$content
;
}
}
}
}
...
...
tests/unit/framework/web/ResponseTest.php
View file @
ef5afef7
<?php
<?php
namespace
yii\web
;
use
yiiunit\framework\web\ResponseTest
;
/**
* Mock PHP header function to check for sent headers
* @param string $string
* @param bool $replace
* @param int $httpResponseCode
*/
function
header
(
$string
,
$replace
=
true
,
$httpResponseCode
=
null
)
{
ResponseTest
::
$headers
[]
=
$string
;
// TODO implement replace
if
(
$httpResponseCode
!==
null
)
{
ResponseTest
::
$httpResponseCode
=
$httpResponseCode
;
}
}
namespace
yiiunit\framework\web
;
namespace
yiiunit\framework\web
;
use
Yii
;
use
yii\helpers\StringHelper
;
use
yii\helpers\StringHelper
;
use
yii\web\Response
;
use
yii\web\Response
;
class
ResponseTest
extends
\yiiunit\TestCase
class
ResponseTest
extends
\yiiunit\TestCase
{
{
public
static
$headers
=
array
();
public
$response
;
public
static
$httpResponseCode
=
200
;
protected
function
setUp
()
protected
function
setUp
()
{
{
parent
::
setUp
();
parent
::
setUp
();
$this
->
mockApplication
();
$this
->
mockApplication
();
$this
->
reset
();
$this
->
response
=
new
Response
;
}
protected
function
reset
()
{
static
::
$headers
=
array
();
static
::
$httpResponseCode
=
200
;
}
}
public
function
rightRanges
()
public
function
rightRanges
()
...
@@ -60,14 +35,15 @@ class ResponseTest extends \yiiunit\TestCase
...
@@ -60,14 +35,15 @@ class ResponseTest extends \yiiunit\TestCase
{
{
$content
=
$this
->
generateTestFileContent
();
$content
=
$this
->
generateTestFileContent
();
$_SERVER
[
'HTTP_RANGE'
]
=
'bytes='
.
$rangeHeader
;
$_SERVER
[
'HTTP_RANGE'
]
=
'bytes='
.
$rangeHeader
;
$sent
=
$this
->
runSendFile
(
'testFile.txt'
,
$content
,
null
);
$this
->
response
->
sendFile
(
'testFile.txt'
,
$content
,
null
,
false
);
$this
->
assertEquals
(
$expectedFile
,
$sent
);
$this
->
assertEquals
(
$expectedFile
,
$this
->
response
->
content
);
$this
->
assertTrue
(
in_array
(
'HTTP/1.1 206 Partial Content'
,
static
::
$headers
));
$this
->
assertEquals
(
206
,
$this
->
response
->
statusCode
);
$this
->
assertTrue
(
in_array
(
'Accept-Ranges: bytes'
,
static
::
$headers
));
$headers
=
$this
->
response
->
headers
;
$this
->
assertArrayHasKey
(
'Content-Range: bytes '
.
$expectedHeader
.
'/'
.
StringHelper
::
strlen
(
$content
),
array_flip
(
static
::
$headers
));
$this
->
assertEquals
(
"bytes"
,
$headers
->
get
(
'Accept-Ranges'
));
$this
->
assertTrue
(
in_array
(
'Content-Type: text/plain'
,
static
::
$headers
));
$this
->
assertEquals
(
"bytes "
.
$expectedHeader
.
'/'
.
StringHelper
::
strlen
(
$content
),
$headers
->
get
(
'Content-Range'
));
$this
->
assertTrue
(
in_array
(
'Content-Length: '
.
$length
,
static
::
$headers
));
$this
->
assertEquals
(
'text/plain'
,
$headers
->
get
(
'Content-Type'
));
$this
->
assertEquals
(
"
$length
"
,
$headers
->
get
(
'Content-Length'
));
}
}
public
function
wrongRanges
()
public
function
wrongRanges
()
...
@@ -91,21 +67,11 @@ class ResponseTest extends \yiiunit\TestCase
...
@@ -91,21 +67,11 @@ class ResponseTest extends \yiiunit\TestCase
$content
=
$this
->
generateTestFileContent
();
$content
=
$this
->
generateTestFileContent
();
$_SERVER
[
'HTTP_RANGE'
]
=
'bytes='
.
$rangeHeader
;
$_SERVER
[
'HTTP_RANGE'
]
=
'bytes='
.
$rangeHeader
;
$this
->
r
unSendFile
(
'testFile.txt'
,
$content
,
null
);
$this
->
r
esponse
->
sendFile
(
'testFile.txt'
,
$content
,
null
,
false
);
}
}
protected
function
generateTestFileContent
()
protected
function
generateTestFileContent
()
{
{
return
'12ёжик3456798áèabcdefghijklmnopqrstuvwxyz!"§$%&/(ёжик)=?'
;
return
'12ёжик3456798áèabcdefghijklmnopqrstuvwxyz!"§$%&/(ёжик)=?'
;
}
}
protected
function
runSendFile
(
$fileName
,
$content
,
$mimeType
)
{
ob_start
();
ob_implicit_flush
(
false
);
$response
=
new
Response
();
$response
->
sendFile
(
$fileName
,
$content
,
$mimeType
,
false
);
$file
=
ob_get_clean
();
return
$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