public function testCDATACannotBeTricked() { $root = new SimpleDOM('<root />'); $expected = '<root><![CDATA[<![CDATA[some data]]]]><![CDATA[>]]></root>'; $root->insertCDATA('<![CDATA[some data]]>', 'append'); $this->assertXmlStringEqualsXmlString($expected, $root->asXML()); }
public function testAfterWithoutNextSibling() { $root = new SimpleDOM('<root><child1 /><child2 /><child3 /></root>'); $expected = '<root><child1 /><child2 /><child3/></root><!--TEST-->'; $root->insertComment('TEST', 'after'); $this->assertEqualsWithComments($expected, $root->asXML()); }
public function testPointersToNodesAreNotLost() { $node = new SimpleDOM('<node> <child letter="c" /> <child letter="d" /> <child letter="e" /> <child letter="a" /> <child letter="b" /> </node>'); $c = $node->child[0]; $d = $node->child[1]; $e = $node->child[2]; $a = $node->child[3]; $b = $node->child[4]; $node->sortChildren('@letter'); $a['old_letter'] = 'a'; $b['old_letter'] = 'b'; $c['old_letter'] = 'c'; $d['old_letter'] = 'd'; $e['old_letter'] = 'e'; $expected = '<node> <child letter="a" old_letter="a" /> <child letter="b" old_letter="b" /> <child letter="c" old_letter="c" /> <child letter="d" old_letter="d" /> <child letter="e" old_letter="e" /> </node>'; $this->assertXmlStringEqualsXmlString($expected, $node->asXML()); }
public function testGrandchild() { $root = new SimpleDOM('<root><child /></root>'); $new = new SimpleDOM('<new />'); $root->child->appendChild($new); $this->assertXmlStringEqualsXmlString($root->asXML(), '<root><child><new /></child></root>'); }
public function testMultiple() { $root = new SimpleDOM('<root />'); $expected_xml = '<?xml-stylesheet type="text/xsl" href="foo.xsl"?><?xml-stylesheet type="text/xsl" href="bar.xsl"?><root />'; $root->insertPI('xml-stylesheet', 'type="text/xsl" href="foo.xsl"', 'before'); $root->insertPI('xml-stylesheet', 'type="text/xsl" href="bar.xsl"', 'before'); $this->assertXmlStringEqualsXmlString($root->asXML(), $expected_xml); }
public function testRemoveDeep() { $root = new SimpleDOM('<root><child><grandchild /></child></root>'); $expected_return = clone $root->child; $return = $root->removeChild($root->child); $this->assertXmlStringEqualsXmlString('<root />', $root->asXML()); $this->assertEquals($expected_return, $return); }
public function testChild() { $root = new SimpleDOM('<root><foo /></root>'); $foo = $root->foo; $return = $foo->insertText('bar')->insertText('baz'); $this->assertXmlStringEqualsXmlString('<root><foo>barbaz</foo></root>', $root->asXML()); $this->assertSame($foo, $return); }
public function testNoRef() { $root = new SimpleDOM('<root><child /></root>'); $new = new SimpleDOM('<new />'); $return = $root->insertBefore($new); $this->assertXmlStringEqualsXmlString('<root><child /><new /></root>', $root->asXML()); $this->assertSame(dom_import_simplexml($root->new), dom_import_simplexml($return)); }
public function testBeforeLastChild() { $root = new SimpleDOM('<root><child1 /><child2 /><child3 /></root>'); $new = new SimpleDOM('<new />'); $return = $root->child3->insertBeforeSelf($new); $this->assertXmlStringEqualsXmlString($root->asXML(), '<root><child1 /><child2 /><new /><child3 /></root>'); $this->assertSame(dom_import_simplexml($root->new), dom_import_simplexml($return)); }
public function testRemoveGrandchild() { $root = new SimpleDOM('<root><child><grandchild /></child></root>'); $expected_return = clone $root->child->grandchild; $return = $root->child->grandchild->removeSelf(); $this->assertXmlStringEqualsXmlString('<root><child /></root>', $root->asXML()); $this->assertTrue($return instanceof SimpleDOM); $this->assertEquals($expected_return, $return); }
public function testReplaceLastChild() { $root = new SimpleDOM('<root><child1 /><child2 /><child3 /></root>'); $new = new SimpleDOM('<new />'); $expected_return = clone $root->child3; $return = $root->replaceChild($new, $root->child3); $this->assertXmlStringEqualsXmlString('<root><child1 /><child2 /><new /></root>', $root->asXML()); $this->assertEquals($expected_return, $return); $this->assertNotSame(dom_import_simplexml($return), dom_import_simplexml($new)); }
public function testNS() { $root = new SimpleDOM('<root> <ns:child1 xmlns:ns="urn:ns"> <ns:grandchild1 /> </ns:child1> <child2 /> <child3 /> </root>', LIBXML_NOBLANKS); $expected = '<root> <ns:child1 xmlns:ns="urn:ns" /> <child2> <ns:grandchild1 xmlns:ns="urn:ns" moved="1" /> </child2> <child3 /> </root>'; $nodes = $root->children('urn:ns'); $node = $nodes[0]->grandchild1; $return = $node->moveTo($root->child2); $return['moved'] = 1; $this->assertXmlStringEqualsXmlString($expected, $root->asXML()); }
public function testTextNode() { $root = new SimpleDOM('<root><child /></root>'); $root->insertXML('my text node'); $this->assertXmlStringEqualsXmlString('<root><child />my text node</root>', $root->asXML()); }
public function testNSDeclarationsAreNotAttributesAndAreNotCopiedUnlessNeeded() { $root = new SimpleDOM('<root> <child1 /> <child2 a="aval" b="bval" xmlns:foo="urn:foo" /> </root>'); $root->child1->copyAttributesFrom($root->child2); $this->assertXmlStringEqualsXmlString('<root> <child1 a="aval" b="bval" /> <child2 a="aval" b="bval" xmlns:foo="urn:foo" /> </root>', $root->asXML()); }
public function testFileContentMatchesXML() { $root = new SimpleDOM('<root><child /></root>'); $filepath = $this->tempfile(); $success = $root->asPrettyXML($filepath); $this->assertXmlStringEqualsXmlFile($filepath, $root->asXML()); }
public function testNS() { $node = new SimpleDOM('<node xmlns:ns="urn:ns" />'); $node->setAttributeNS('urn:ns', 'a', 'aval'); $this->assertXmlStringEqualsXmlString('<node xmlns:ns="urn:ns" ns:a="aval" />', $node->asXML()); }
public function testExistentAttributesAreOverwritten() { $node = new SimpleDOM('<node a="old" />'); $node->setAttributes(array('a' => 'aval', 'b' => 'bval')); $this->assertXmlStringEqualsXmlString('<node a="aval" b="bval" />', $node->asXML()); }
public function test() { $node = new SimpleDOM('<node />'); $node->setAttribute('a', 'aval'); $this->assertXmlStringEqualsXmlString('<node a="aval" />', $node->asXML()); }
public function testCloningFromDescendantNode() { $node = new SimpleDOM('<node> <child1><granchild1 /></child1> <child2 /> <child3><granchild3 /></child3> </node>'); $node->cloneChildrenFrom($node->child1, true); $this->assertXmlStringEqualsXmlString('<node> <child1><granchild1 /></child1> <child2 /> <child3><granchild3 /></child3> <granchild1 /> </node>', $node->asXML()); }
public function testRoodNodeIsNeverDeleted() { $node = new SimpleDOM('<node><node /></node>'); $node->deleteNodes('//node'); $this->assertXmlStringEqualsXmlString('<node />', $node->asXML()); }
public function testDeleteGrandchild() { $root = new SimpleDOM('<root><child><grandchild /></child></root>'); $root->child->grandchild->deleteSelf(); $this->assertXmlStringEqualsXmlString('<root><child /></root>', $root->asXML()); }