Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60251047
AphrontHTTPHeaderParserTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Apr 28, 15:46
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Apr 30, 15:46 (2 d)
Engine
blob
Format
Raw Data
Handle
17325354
Attached To
rPHU libphutil
AphrontHTTPHeaderParserTestCase.php
View Options
<?php
final
class
AphrontHTTPHeaderParserTestCase
extends
PhutilTestCase
{
public
function
testHeaderParser
()
{
$cases
=
array
(
array
(
'Key: x; y; z'
,
'Key'
,
'x; y; z'
,
array
(
array
(
'x'
,
null
),
array
(
'y'
,
null
),
array
(
'z'
,
null
),
),
),
array
(
'Content-Disposition: form-data; name="label"'
,
'Content-Disposition'
,
'form-data; name="label"'
,
array
(
array
(
'form-data'
,
null
),
array
(
'name'
,
'label'
),
),
),
array
(
'Content-Type: multipart/form-data; charset=utf-8'
,
'Content-Type'
,
'multipart/form-data; charset=utf-8'
,
array
(
array
(
'multipart/form-data'
,
null
),
array
(
'charset'
,
'utf-8'
),
),
),
array
(
'Content-Type: application/octet-stream; charset="ut'
,
'Content-Type'
,
'application/octet-stream; charset="ut'
,
false
,
),
array
(
'Content-Type: multipart/form-data; boundary=ABCDEFG'
,
'Content-Type'
,
'multipart/form-data; boundary=ABCDEFG'
,
array
(
array
(
'multipart/form-data'
,
null
),
array
(
'boundary'
,
'ABCDEFG'
),
),
),
array
(
'Content-Type: multipart/form-data; boundary="ABCDEFG"'
,
'Content-Type'
,
'multipart/form-data; boundary="ABCDEFG"'
,
array
(
array
(
'multipart/form-data'
,
null
),
array
(
'boundary'
,
'ABCDEFG'
),
),
),
);
foreach
(
$cases
as
$case
)
{
$input
=
$case
[
0
];
$expect_name
=
$case
[
1
];
$expect_content
=
$case
[
2
];
$parser
=
id
(
new
AphrontHTTPHeaderParser
())
->
parseRawHeader
(
$input
);
$actual_name
=
$parser
->
getHeaderName
();
$actual_content
=
$parser
->
getHeaderContent
();
$this
->
assertEqual
(
$expect_name
,
$actual_name
,
pht
(
'Header name for: %s'
,
$input
));
$this
->
assertEqual
(
$expect_content
,
$actual_content
,
pht
(
'Header content for: %s'
,
$input
));
if
(
isset
(
$case
[
3
]))
{
$expect_pairs
=
$case
[
3
];
$caught
=
null
;
try
{
$actual_pairs
=
$parser
->
getHeaderContentAsPairs
();
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
if
(
$expect_pairs
===
false
)
{
$this
->
assertEqual
(
true
,
(
$caught
instanceof
Exception
),
pht
(
'Expect exception for header pairs of: %s'
,
$input
));
}
else
{
$this
->
assertEqual
(
$expect_pairs
,
$actual_pairs
,
pht
(
'Header pairs for: %s'
,
$input
));
}
}
}
}
}
Event Timeline
Log In to Comment