/** @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); }
/** * Write the input data to a DOMDocument * * @param mixed $data * @param string $rootName the xml root element name * * @return DOMDocument */ public function writeToDom($data, $rootName = 'root') { $this->buildXML($dom = new DOMDocument('1.0', $this->getEncoding()), $root = $dom->createElement($rootName), $data); $dom->appendChild($root); return $dom; }
/** @test */ public function itShouldHandleRegularDomDocuments() { $parser = new Parser(); $dom = new \DOMDocument(); $dataNode = $dom->createElement('data'); $dom->appendChild($dataNode); $data = $parser->parseDom($dom); $this->assertEquals(['data' => null], $data); }