/** @test */ public function itShouldAppendCdataSections() { $xml = new SimpleXMLElement('<node></node>'); $xml->addCDATASection('string'); $this->assertXmlStringEqualsXmlString('<node><![CDATA[string]]></node>', $xml->asXML()); if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.7', '<')) { $this->markTestIncomplete('HHVM segmentation fault.'); } $xml = new SimpleXMLElement('<node></node>'); $xml->addCDATASection(new SimpleXML('<data>string</data>')); $this->assertXmlStringEqualsXmlString('<node><![CDATA[<data>string</data>]]></node>', $xml->asXML()); $xml = new SimpleXMLElement('<node></node>'); $dom = new DOM(); $dom->loadXML('<data>string</data>'); $xml->addCDATASection($dom); $this->assertXmlStringEqualsXmlString('<node><![CDATA[<data>string</data>]]></node>', $xml->asXML()); $xml = new SimpleXMLElement('<node></node>'); $dom = new DOMDocument(); $dom->loadXML('<root><data>string</data></root>'); $xml->addCDATASection($dom->xpath('data')->item(0)); $this->assertXmlStringEqualsXmlString('<node><![CDATA[<data>string</data>]]></node>', $xml->asXML()); $xml = new SimpleXMLElement('<node></node>'); try { $xml->addCDATASection([]); } catch (\InvalidArgumentException $e) { return $this->assertTrue(true); } }
/** @test */ public function itShouldAppendElementToItsFirstChildIfNoReferenceIsGiven() { $dom = new DOMDocument(); $firstChild = $dom->createElement('data'); $nextChild = $dom->createElement('foo', 'bar'); $dom->appendChild($firstChild); $dom->appendDomElement($nextChild); $list = $dom->xpath('foo'); $this->assertSame($list->item(0), $nextChild); }