Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
    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());
    }
Exemplo n.º 4
0
 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>');
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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));
 }
Exemplo n.º 9
0
 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));
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 12
0
    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());
    }
Exemplo n.º 13
0
 public function testTextNode()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $root->insertXML('my text node');
     $this->assertXmlStringEqualsXmlString('<root><child />my text node</root>', $root->asXML());
 }
Exemplo n.º 14
0
    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());
    }
Exemplo n.º 15
0
 public function testFileContentMatchesXML()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $filepath = $this->tempfile();
     $success = $root->asPrettyXML($filepath);
     $this->assertXmlStringEqualsXmlFile($filepath, $root->asXML());
 }
Exemplo n.º 16
0
 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());
 }
Exemplo n.º 17
0
 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());
 }
Exemplo n.º 18
0
 public function test()
 {
     $node = new SimpleDOM('<node />');
     $node->setAttribute('a', 'aval');
     $this->assertXmlStringEqualsXmlString('<node a="aval" />', $node->asXML());
 }
Exemplo n.º 19
0
    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());
    }
Exemplo n.º 20
0
 public function testRoodNodeIsNeverDeleted()
 {
     $node = new SimpleDOM('<node><node /></node>');
     $node->deleteNodes('//node');
     $this->assertXmlStringEqualsXmlString('<node />', $node->asXML());
 }
Exemplo n.º 21
0
 public function testDeleteGrandchild()
 {
     $root = new SimpleDOM('<root><child><grandchild /></child></root>');
     $root->child->grandchild->deleteSelf();
     $this->assertXmlStringEqualsXmlString('<root><child /></root>', $root->asXML());
 }