Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1815880
HrefTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
2 KB
Subscribers
None
HrefTest.php
View Options
<?php
namespace
Sabre\DAV\Xml\Property
;
use
Sabre\DAV
;
use
Sabre\DAV\Browser\HtmlOutputHelper
;
use
Sabre\DAV\Xml\XmlTest
;
class
HrefTest
extends
XmlTest
{
function
testConstruct
()
{
$href
=
new
Href
(
'path'
);
$this
->
assertEquals
(
'path'
,
$href
->
getHref
());
}
function
testSerialize
()
{
$href
=
new
Href
(
'path'
);
$this
->
assertEquals
(
'path'
,
$href
->
getHref
());
$this
->
contextUri
=
'/bla/'
;
$xml
=
$this
->
write
([
'{DAV:}anything'
=>
$href
]);
$this
->
assertXmlStringEqualsXmlString
(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
'
,
$xml
);
}
function
testSerializeNoPrefix
()
{
$href
=
new
Href
(
'path'
,
false
);
$this
->
assertEquals
(
'path'
,
$href
->
getHref
());
$xml
=
$this
->
write
([
'{DAV:}anything'
=>
$href
]);
$this
->
assertXmlStringEqualsXmlString
(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>path</d:href></d:anything>
'
,
$xml
);
}
function
testUnserialize
()
{
$xml
=
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
'
;
$result
=
$this
->
parse
(
$xml
,
[
'{DAV:}anything'
=>
'Sabre
\\
DAV
\\
Xml
\\
Property
\\
Href'
]);
$href
=
$result
[
'value'
];
$this
->
assertInstanceOf
(
'Sabre
\\
DAV
\\
Xml
\\
Property
\\
Href'
,
$href
);
$this
->
assertEquals
(
'/bla/path'
,
$href
->
getHref
());
}
function
testUnserializeIncompatible
()
{
$xml
=
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href2>/bla/path</d:href2></d:anything>
'
;
$result
=
$this
->
parse
(
$xml
,
[
'{DAV:}anything'
=>
'Sabre
\\
DAV
\\
Xml
\\
Property
\\
Href'
]);
$href
=
$result
[
'value'
];
$this
->
assertNull
(
$href
);
}
function
testUnserializeEmpty
()
{
$xml
=
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"></d:anything>
'
;
$result
=
$this
->
parse
(
$xml
,
[
'{DAV:}anything'
=>
'Sabre
\\
DAV
\\
Xml
\\
Property
\\
Href'
]);
$href
=
$result
[
'value'
];
$this
->
assertNull
(
$href
);
}
/**
* This method tests if hrefs containing & are correctly encoded.
*/
function
testSerializeEntity
()
{
$href
=
new
Href
(
'http://example.org/?a&b'
,
false
);
$this
->
assertEquals
(
'http://example.org/?a&b'
,
$href
->
getHref
());
$xml
=
$this
->
write
([
'{DAV:}anything'
=>
$href
]);
$this
->
assertXmlStringEqualsXmlString
(
'<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:href>http://example.org/?a&b</d:href></d:anything>
'
,
$xml
);
}
function
testToHtml
()
{
$href
=
new
Href
([
'/foo/bar'
,
'foo/bar'
,
'http://example.org/bar'
]);
$html
=
new
HtmlOutputHelper
(
'/base/'
,
[]
);
$expected
=
'<a href="/foo/bar">/foo/bar</a><br />'
.
'<a href="/base/foo/bar">/base/foo/bar</a><br />'
.
'<a href="http://example.org/bar">http://example.org/bar</a>'
;
$this
->
assertEquals
(
$expected
,
$href
->
toHtml
(
$html
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Dec 20, 2:44 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
914085
Default Alt Text
HrefTest.php (2 KB)
Attached To
rDAVCAL DokuWiki DAVCal PlugIn
Event Timeline
Log In to Comment