Example #1
0
 public function testGrandchild()
 {
     $root = new SXE('<root><child /></root>');
     $new = new SXE('<new />');
     $root->child->appendChild($new);
     $this->assertXmlStringEqualsXmlString($root->asXML(), '<root><child><new /></child></root>');
 }
Example #2
0
 public function testTextNode()
 {
     $root = new SXE('<root><child /></root>');
     $return = $root->appendXML('my text node');
     $this->assertXmlStringEqualsXmlString('<root><child />my text node</root>', $root->asXML());
     $this->assertSame(dom_import_simplexml($root), dom_import_simplexml($return));
 }
Example #3
0
 public function testBeforeLastChild()
 {
     $root = new SXE('<root><child1 /><child2 /><child3 /></root>');
     $new = new SXE('<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));
 }
Example #4
0
 public function testNoRef()
 {
     $root = new SXE('<root><child /></root>');
     $new = new SXE('<new />');
     $return = $root->insertBefore($new);
     $this->assertXmlStringEqualsXmlString('<root><child /><new /></root>', $root->asXML());
     $this->assertSame(dom_import_simplexml($root->new), dom_import_simplexml($return));
 }
Example #5
0
 public function testRemoveDeep()
 {
     $root = new SXE('<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);
 }
Example #6
0
 public function testRemoveGrandchild()
 {
     $root = new SXE('<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 SXE);
     $this->assertEquals($expected_return, $return);
 }
Example #7
0
 public function testMultiple()
 {
     $root = new SXE('<root />');
     $expected_xml = '<?xml-stylesheet type="text/xsl" href="foo.xsl"?><?xml-stylesheet type="text/xsl" href="bar.xsl"?><root />';
     $return = $root->addProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="foo.xsl"');
     $this->assertTrue($return);
     $return = $root->addProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="bar.xsl"');
     $this->assertTrue($return);
     $this->assertXmlStringEqualsXmlString($root->asXML(), $expected_xml);
 }
Example #8
0
 public function testReplaceLastChild()
 {
     $root = new SXE('<root><child1 /><child2 /><child3 /></root>');
     $new = new SXE('<new />');
     $expected_return = clone $root->child3;
     $return = $root->child3->replaceSelf($new);
     $this->assertXmlStringEqualsXmlString('<root><child1 /><child2 /><new /></root>', $root->asXML());
     $this->assertEquals($expected_return, $return);
     $this->assertNotSame(dom_import_simplexml($return), dom_import_simplexml($new));
 }
Example #9
0
    public function testChildContextNoMatches()
    {
        $xpath = './*[@remove="1"]';
        $root = new SXE('<root>
				<child1 remove="1" />
				<child2 remove="0" />
				<child3>
					<grandchild>
						<grandgrandchild remove="1" />
					</grandchild>
				</child3>
			</root>', LIBXML_NOBLANKS);
        $expected_result = clone $root;
        $expected_return = 0;
        $return = $root->child3->deleteNodes($xpath);
        $this->assertXmlStringEqualsXmlString($expected_result->asXML(), $root->asXML());
        $this->assertSame($expected_return, $return);
    }
Example #10
0
 public function testDeleteGrandchild()
 {
     $root = new SXE('<root><child><grandchild /></child></root>');
     $root->child->grandchild->deleteSelf();
     $this->assertXmlStringEqualsXmlString('<root><child /></root>', $root->asXML());
 }