コード例 #1
0
ファイル: insertCDATA.php プロジェクト: laiello/simpledom
 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());
 }
コード例 #2
0
ファイル: insertComment.php プロジェクト: laiello/simpledom
 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());
 }
コード例 #3
0
ファイル: sortChildren.php プロジェクト: laiello/simpledom
    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());
    }
コード例 #4
0
ファイル: appendChild.php プロジェクト: laiello/simpledom
 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>');
 }
コード例 #5
0
ファイル: insertPI.php プロジェクト: laiello/simpledom
 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);
 }
コード例 #6
0
ファイル: removeChild.php プロジェクト: laiello/simpledom
 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);
 }
コード例 #7
0
ファイル: insertText.php プロジェクト: laiello/simpledom
 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);
 }
コード例 #8
0
ファイル: insertBefore.php プロジェクト: laiello/simpledom
 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));
 }
コード例 #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));
 }
コード例 #10
0
ファイル: removeSelf.php プロジェクト: laiello/simpledom
 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);
 }
コード例 #11
0
ファイル: replaceChild.php プロジェクト: laiello/simpledom
 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));
 }
コード例 #12
0
ファイル: moveTo.php プロジェクト: laiello/simpledom
    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());
    }
コード例 #13
0
ファイル: insertXML.php プロジェクト: laiello/simpledom
 public function testTextNode()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $root->insertXML('my text node');
     $this->assertXmlStringEqualsXmlString('<root><child />my text node</root>', $root->asXML());
 }
コード例 #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());
    }
コード例 #15
0
ファイル: asPrettyXML.php プロジェクト: laiello/simpledom
 public function testFileContentMatchesXML()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $filepath = $this->tempfile();
     $success = $root->asPrettyXML($filepath);
     $this->assertXmlStringEqualsXmlFile($filepath, $root->asXML());
 }
コード例 #16
0
ファイル: setAttributeNS.php プロジェクト: laiello/simpledom
 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());
 }
コード例 #17
0
ファイル: setAttributes.php プロジェクト: laiello/simpledom
 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());
 }
コード例 #18
0
ファイル: setAttribute.php プロジェクト: laiello/simpledom
 public function test()
 {
     $node = new SimpleDOM('<node />');
     $node->setAttribute('a', 'aval');
     $this->assertXmlStringEqualsXmlString('<node a="aval" />', $node->asXML());
 }
コード例 #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());
    }
コード例 #20
0
ファイル: deleteNodes.php プロジェクト: laiello/simpledom
 public function testRoodNodeIsNeverDeleted()
 {
     $node = new SimpleDOM('<node><node /></node>');
     $node->deleteNodes('//node');
     $this->assertXmlStringEqualsXmlString('<node />', $node->asXML());
 }
コード例 #21
0
ファイル: deleteSelf.php プロジェクト: laiello/simpledom
 public function testDeleteGrandchild()
 {
     $root = new SimpleDOM('<root><child><grandchild /></child></root>');
     $root->child->grandchild->deleteSelf();
     $this->assertXmlStringEqualsXmlString('<root><child /></root>', $root->asXML());
 }