ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HrefTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV\Xml\Property;
4 
5 use Sabre\DAV;
8 
9 class HrefTest extends XmlTest {
10 
11  function testConstruct() {
12 
13  $href = new Href('path');
14  $this->assertEquals('path', $href->getHref());
15 
16  }
17 
18  function testSerialize() {
19 
20  $href = new Href('path');
21  $this->assertEquals('path', $href->getHref());
22 
23  $this->contextUri = '/bla/';
24 
25  $xml = $this->write(['{DAV:}anything' => $href]);
26 
27  $this->assertXmlStringEqualsXmlString(
28 '<?xml version="1.0"?>
29 <d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
30 ', $xml);
31 
32  }
33 
34  function testUnserialize() {
35 
36  $xml = '<?xml version="1.0"?>
37 <d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything>
38 ';
39 
40  $result = $this->parse($xml, ['{DAV:}anything' => 'Sabre\\DAV\\Xml\\Property\\Href']);
41 
42  $href = $result['value'];
43 
44  $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $href);
45 
46  $this->assertEquals('/bla/path', $href->getHref());
47 
48  }
49 
51 
52  $xml = '<?xml version="1.0"?>
53 <d:anything xmlns:d="DAV:"><d:href2>/bla/path</d:href2></d:anything>
54 ';
55  $result = $this->parse($xml, ['{DAV:}anything' => 'Sabre\\DAV\\Xml\\Property\\Href']);
56  $href = $result['value'];
57  $this->assertNull($href);
58 
59  }
60  function testUnserializeEmpty() {
61 
62  $xml = '<?xml version="1.0"?>
63 <d:anything xmlns:d="DAV:"></d:anything>
64 ';
65  $result = $this->parse($xml, ['{DAV:}anything' => 'Sabre\\DAV\\Xml\\Property\\Href']);
66  $href = $result['value'];
67  $this->assertNull($href);
68 
69  }
70 
74  function testSerializeEntity() {
75 
76  $href = new Href('http://example.org/?a&b', false);
77  $this->assertEquals('http://example.org/?a&b', $href->getHref());
78 
79  $xml = $this->write(['{DAV:}anything' => $href]);
80 
81  $this->assertXmlStringEqualsXmlString(
82 '<?xml version="1.0"?>
83 <d:anything xmlns:d="DAV:"><d:href>http://example.org/?a&amp;b</d:href></d:anything>
84 ', $xml);
85 
86  }
87 
88  function testToHtml() {
89 
90  $href = new Href([
91  '/foo/bar',
92  'foo/bar',
93  'http://example.org/bar'
94  ]);
95 
96  $html = new HtmlOutputHelper(
97  '/base/',
98  []
99  );
100 
101  $expected =
102  '<a href="/foo/bar">/foo/bar</a><br />' .
103  '<a href="/base/foo/bar">/base/foo/bar</a><br />' .
104  '<a href="http://example.org/bar">http://example.org/bar</a>';
105  $this->assertEquals($expected, $href->toHtml($html));
106 
107  }
108 
109 }
$result
Href property.
Definition: Href.php:26
parse($xml, array $elementMap=[])
Definition: XmlTest.php:26
testSerializeEntity()
This method tests if hrefs containing & are correctly encoded.
Definition: HrefTest.php:74
$html
Definition: example_001.php:87
This class provides a few utility functions for easily generating HTML for the browser plugin...