1<?php
2
3namespace Sabre\Xml\Element;
4
5use Sabre\Xml\Reader;
6use Sabre\Xml\Writer;
7
8class UriTest extends \PHPUnit_Framework_TestCase {
9
10    function testDeserialize() {
11
12        $input = <<<BLA
13<?xml version="1.0"?>
14<root xmlns="http://sabredav.org/ns">
15  <uri>/foo/bar</uri>
16</root>
17BLA;
18
19        $reader = new Reader();
20        $reader->contextUri = 'http://example.org/';
21        $reader->elementMap = [
22            '{http://sabredav.org/ns}uri' => 'Sabre\\Xml\\Element\\Uri',
23        ];
24        $reader->xml($input);
25
26        $output = $reader->parse();
27
28        $this->assertEquals(
29            [
30                'name'  => '{http://sabredav.org/ns}root',
31                'value' => [
32                    [
33                        'name'       => '{http://sabredav.org/ns}uri',
34                        'value'      => new Uri('http://example.org/foo/bar'),
35                        'attributes' => [],
36                    ]
37                ],
38                'attributes' => [],
39            ],
40            $output
41        );
42
43    }
44
45    function testSerialize() {
46
47        $writer = new Writer();
48        $writer->namespaceMap = [
49            'http://sabredav.org/ns' => null
50        ];
51        $writer->openMemory();
52        $writer->startDocument('1.0');
53        $writer->setIndent(true);
54        $writer->contextUri = 'http://example.org/';
55        $writer->write([
56            '{http://sabredav.org/ns}root' => [
57                '{http://sabredav.org/ns}uri' => new Uri('/foo/bar'),
58            ]
59        ]);
60
61        $output = $writer->outputMemory();
62
63        $expected = <<<XML
64<?xml version="1.0"?>
65<root xmlns="http://sabredav.org/ns">
66 <uri>http://example.org/foo/bar</uri>
67</root>
68
69XML;
70
71        $this->assertEquals($expected, $output);
72
73
74    }
75
76}
77