/** @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 staticHelperTest() { $dom = new DOMDocument(); $elementParent = $dom->createElement('data'); $elementChild = $dom->createElement('foo', 'bar'); $elementParent->appendChild($elementChild); $this->assertEquals(['foo' => 'bar'], Parser::getPhpValue($elementParent)); $this->assertNull(Parser::getPhpValue('')); $this->assertSame(10, Parser::getPhpValue('10')); $this->assertSame(1.2, Parser::getPhpValue('1.2')); $this->assertTrue(Parser::getPhpValue('true')); $this->assertFalse(Parser::getPhpValue('false')); $this->assertSame(3840, Parser::getPhpValue('0xF00')); $this->assertSame('0xNaN', Parser::getPhpValue('0xNaN')); }