1<?php
2
3namespace Sabre\Xml\Element;
4
5use Sabre\Xml\Reader;
6use Sabre\Xml\Writer;
7
8class CDataTest extends \PHPUnit_Framework_TestCase {
9
10    /**
11     * @expectedException \LogicException
12     */
13    function testDeserialize() {
14
15        $input = <<<BLA
16<?xml version="1.0"?>
17<root xmlns="http://sabredav.org/ns">
18 <blabla />
19</root>
20BLA;
21
22        $reader = new Reader();
23        $reader->elementMap = [
24            '{http://sabredav.org/ns}blabla' => 'Sabre\\Xml\\Element\\Cdata',
25        ];
26        $reader->xml($input);
27
28        $output = $reader->parse();
29
30    }
31
32    function testSerialize() {
33
34        $writer = new Writer();
35        $writer->namespaceMap = [
36            'http://sabredav.org/ns' => null
37        ];
38        $writer->openMemory();
39        $writer->startDocument('1.0');
40        $writer->setIndent(true);
41        $writer->write([
42            '{http://sabredav.org/ns}root' => new Cdata('<foo&bar>'),
43        ]);
44
45        $output = $writer->outputMemory();
46
47        $expected = <<<XML
48<?xml version="1.0"?>
49<root xmlns="http://sabredav.org/ns"><![CDATA[<foo&bar>]]></root>
50
51XML;
52
53        $this->assertEquals($expected, $output);
54
55
56    }
57
58}
59