1<?php 2 3declare(strict_types=1); 4 5namespace Sabre\Xml\Element; 6 7use Sabre\Xml\Reader; 8use Sabre\Xml\Writer; 9 10class CDataTest extends \PHPUnit\Framework\TestCase 11{ 12 public function testDeserialize() 13 { 14 $this->expectException(\LogicException::class); 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 public function testSerialize() 32 { 33 $writer = new Writer(); 34 $writer->namespaceMap = [ 35 'http://sabredav.org/ns' => null, 36 ]; 37 $writer->openMemory(); 38 $writer->startDocument('1.0'); 39 $writer->setIndent(true); 40 $writer->write([ 41 '{http://sabredav.org/ns}root' => new Cdata('<foo&bar>'), 42 ]); 43 44 $output = $writer->outputMemory(); 45 46 $expected = <<<XML 47<?xml version="1.0"?> 48<root xmlns="http://sabredav.org/ns"><![CDATA[<foo&bar>]]></root> 49 50XML; 51 52 $this->assertEquals($expected, $output); 53 } 54} 55