Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60064123
PhutilMarkupTestCase.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
Sat, Apr 27, 05:11
Size
3 KB
Mime Type
text/x-php
Expires
Mon, Apr 29, 05:11 (2 d)
Engine
blob
Format
Raw Data
Handle
17294702
Attached To
rPHU libphutil
PhutilMarkupTestCase.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group testcase
*/
final
class
PhutilMarkupTestCase
extends
ArcanistPhutilTestCase
{
public
function
testTagDefaults
()
{
$this
->
assertEqual
(
phutil_render_tag
(
'x'
),
phutil_render_tag
(
'x'
,
array
()));
$this
->
assertEqual
(
phutil_render_tag
(
'x'
,
array
()),
phutil_render_tag
(
'x'
,
array
(),
null
));
}
public
function
testTagEmpty
()
{
$this
->
assertEqual
(
'<x />'
,
phutil_render_tag
(
'x'
,
array
(),
null
));
$this
->
assertEqual
(
'<x></x>'
,
phutil_render_tag
(
'x'
,
array
(),
''
));
}
public
function
testTagBasics
()
{
$this
->
assertEqual
(
'<x />'
,
phutil_render_tag
(
'x'
));
$this
->
assertEqual
(
'<x>y</x>'
,
phutil_render_tag
(
'x'
,
array
(),
'y'
));
}
public
function
testTagAttributes
()
{
$this
->
assertEqual
(
'<x u="v">y</x>'
,
phutil_render_tag
(
'x'
,
array
(
'u'
=>
'v'
),
'y'
));
$this
->
assertEqual
(
'<x u="v" />'
,
phutil_render_tag
(
'x'
,
array
(
'u'
=>
'v'
)));
}
public
function
testTagEscapes
()
{
$this
->
assertEqual
(
'<x u="<" />'
,
phutil_render_tag
(
'x'
,
array
(
'u'
=>
'<'
)));
$this
->
assertEqual
(
'<x><y /></x>'
,
phutil_render_tag
(
'x'
,
array
(),
phutil_render_tag
(
'y'
)));
}
public
function
testTagNullAttribute
()
{
$this
->
assertEqual
(
'<x />'
,
phutil_render_tag
(
'x'
,
array
(
'y'
=>
null
)));
}
public
function
testTagJavascriptProtocolRejection
()
{
$hrefs
=
array
(
'javascript:alert(1)'
=>
true
,
'JAVASCRIPT:alert(1)'
=>
true
,
' javascript:alert(1)'
=>
true
,
'/'
=>
false
,
'/path/to/stuff/'
=>
false
,
''
=>
false
,
'http://example.com/'
=>
false
,
'#'
=>
false
,
);
foreach
(
array
(
true
,
false
)
as
$use_uri
)
{
foreach
(
$hrefs
as
$href
=>
$expect
)
{
if
(
$use_uri
)
{
$href
=
new
PhutilURI
(
$href
);
}
$caught
=
null
;
try
{
phutil_render_tag
(
'a'
,
array
(
'href'
=>
$href
),
'click for candy'
);
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertEqual
(
$expect
,
$caught
instanceof
Exception
,
"Rejected href: {$href}"
);
}
}
}
public
function
testURIEscape
()
{
$this
->
assertEqual
(
'%2B/%20%3F%23%26%3A%21xyz%25'
,
phutil_escape_uri
(
'+/ ?#&:!xyz%'
));
}
public
function
testURIPathComponentEscape
()
{
$this
->
assertEqual
(
'a%252Fb'
,
phutil_escape_uri_path_component
(
'a/b'
));
$str
=
''
;
for
(
$ii
=
0
;
$ii
<=
255
;
$ii
++)
{
$str
.=
chr
(
$ii
);
}
$this
->
assertEqual
(
$str
,
phutil_unescape_uri_path_component
(
rawurldecode
(
// Simulates webserver.
phutil_escape_uri_path_component
(
$str
))));
}
public
function
testHsprintf
()
{
$this
->
assertEqual
(
'<div><3</div>'
,
hsprintf
(
'<div>%s</div>'
,
'<3'
));
}
}
Event Timeline
Log In to Comment