Ejemplo n.º 1
0
 public function testTextNodes()
 {
     $root = new SimpleDOM('<root>Some <b>bold</b> text</root>');
     $expected_return = array('Some ', new SimpleDOM('<b>bold</b>'), ' text');
     $return = $root->childNodes();
     $this->assertEquals($expected_return, $return);
 }
Ejemplo n.º 2
0
 public function testIsChainable()
 {
     $node = new SimpleDOM('<node />');
     $return = $node->setAttributes(array());
     $this->assertEquals($node, $return);
     $this->assertTrue(dom_import_simplexml($node)->isSameNode(dom_import_simplexml($return)));
 }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
0
 public function testWrongDocument()
 {
     $root = new SimpleDOM('<root />');
     $new = new SimpleDOM('<new />');
     $node = new SimpleDOM('<node />');
     $this->assertFalse($root->replaceChild($new, $node));
 }
Ejemplo n.º 5
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>');
 }
Ejemplo n.º 6
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());
 }
Ejemplo n.º 7
0
 public function testNotFound()
 {
     $root = new SimpleDOM('<root />');
     $expected_return = array();
     $return = $root->getElementsByTagName('inexistent');
     $this->assertEquals($expected_return, $return);
 }
Ejemplo n.º 8
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());
    }
Ejemplo n.º 9
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));
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
0
 public function testXSLCache()
 {
     if (!extension_loaded('xslcache')) {
         $this->markTestSkipped('The XSL Cache extension is not available');
         return;
     }
     $xml = new SimpleDOM('<xml><child>CHILD</child></xml>');
     $this->assertXmlStringEqualsXmlString('<output><child>Content: CHILD</child></output>', $xml->XSLT($this->filepath, true));
 }
Ejemplo n.º 12
0
 /**
  * @expectedException DOMException
  */
 public function testInvalidTarget()
 {
     $root = new SimpleDOM('<root />');
     try {
         $root->insertPI('$$$', 'type="text/xsl" href="foo.xsl"');
     } catch (DOMException $e) {
         $this->assertSame($e->code, DOM_INVALID_CHARACTER_ERR);
         throw $e;
     }
 }
Ejemplo n.º 13
0
 public function testRoot()
 {
     $root = new SimpleDOM('<root />');
     $new = new SimpleDOM('<new />');
     $expected_result = clone $new;
     $expected_return = clone $root;
     $return = $root->replaceSelf($new);
     $this->assertEquals($expected_result, $root);
     $this->assertEquals($expected_return, $return);
 }
Ejemplo n.º 14
0
 public function testRoot()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $parent = $root->parentNode();
     /**
      * When asked for the root node's parent, DOM returns the root node itself
      */
     $this->assertTrue($parent instanceof SimpleDOM);
     $this->assertSame(dom_import_simplexml($root), dom_import_simplexml($parent));
 }
Ejemplo n.º 15
0
 /**
  * @expectedException DOMException
  */
 public function testWrongDocument()
 {
     $root = new SimpleDOM('<root />');
     $node = new SimpleDOM('<node />');
     try {
         $root->removeChild($node);
     } catch (DOMException $e) {
         $this->assertSame(DOM_NOT_FOUND_ERR, $e->code);
         throw $e;
     }
 }
Ejemplo n.º 16
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());
    }
Ejemplo n.º 17
0
 public function testPointersToNodesAreNotLost()
 {
     $actual = array(new SimpleDOM('<child letter="c" />'), new SimpleDOM('<child letter="d" />'), new SimpleDOM('<child letter="e" />'), new SimpleDOM('<child letter="a" />'), new SimpleDOM('<child letter="b" />'));
     $c = $actual[0];
     $d = $actual[1];
     $e = $actual[2];
     $a = $actual[3];
     $b = $actual[4];
     SimpleDOM::sort($actual, '@letter');
     $a['old_letter'] = 'a';
     $b['old_letter'] = 'b';
     $c['old_letter'] = 'c';
     $d['old_letter'] = 'd';
     $e['old_letter'] = 'e';
     $expected = array(new SimpleDOM('<child letter="a" old_letter="a" />'), new SimpleDOM('<child letter="b" old_letter="b" />'), new SimpleDOM('<child letter="c" old_letter="c" />'), new SimpleDOM('<child letter="d" old_letter="d" />'), new SimpleDOM('<child letter="e" old_letter="e" />'));
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 18
0
 public function testNoProlog()
 {
     $div = new SimpleDOM('<div>This is a text</div>');
     $this->assertSame('<div>This is a text</div>', $div->outerXML());
 }
Ejemplo n.º 19
0
 public function testFileContentMatchesXML()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $filepath = $this->tempfile();
     $success = $root->asPrettyXML($filepath);
     $this->assertXmlStringEqualsXmlFile($filepath, $root->asXML());
 }
Ejemplo n.º 20
0
    public function testDoubleQuotesReturnNothing()
    {
        $node = new SimpleDOM('<node>
				<div class="quux" />
				<div class="foo bar baz" />
				<div />
			</node>');
        $actual = $node->getElementsByClassName('"foo');
        $expected = array();
        $this->assertEquals($expected, $actual);
    }
Ejemplo n.º 21
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testInvalidXPath()
 {
     $root = new SimpleDOM('<root />');
     $root->removeNodes('????');
 }
Ejemplo n.º 22
0
 public function testRoot()
 {
     $root = new SimpleDOM('<root><child1 /><child2 /><child3 /></root>');
     $this->assertNull($root->previousSibling());
 }
Ejemplo n.º 23
0
    public function testBySelf()
    {
        $node = new SimpleDOM('<node>
				<child><letter>e</letter></child>
				<child><letter>b</letter></child>
				<child><letter>c</letter></child>
				<child><letter>d</letter></child>
				<child><letter>a</letter></child>
			</node>');
        $expected = array(new SimpleDOM('<child><letter>a</letter></child>'), new SimpleDOM('<child><letter>b</letter></child>'), new SimpleDOM('<child><letter>c</letter></child>'), new SimpleDOM('<child><letter>d</letter></child>'), new SimpleDOM('<child><letter>e</letter></child>'));
        $actual = $node->sortedXPath('//child', '.');
        $this->assertEquals($expected, $actual);
    }
Ejemplo n.º 24
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testInvalidXML()
 {
     $root = new SimpleDOM('<root><child /></root>');
     $root->insertXML('<bad><xml>');
 }
Ejemplo n.º 25
0
 public function testTextNodesAreReturnedAsText()
 {
     $xml = new SimpleDOM('<xml>This <is /> a text</xml>');
     $this->assertSame(' a text', $xml->lastChild());
 }
Ejemplo n.º 26
0
	/**
	 * @throws Exception
	 * @param SimpleDOM $root
	 * @param  $node
	 * @return Shopware_Components_Xml_SimpleXml
	 */
	public function set(SimpleDOM $root,$node){

		if (!is_array($node)){
			throw new Exception("\$node is not an array");
		}

		if (!empty($node["@attributes"])){
			$attributes = $node["@attributes"];
			unset($node["@attributes"]);
		}else {
			$attributes = array();
		}
		foreach ($node as $key => $value){

			if (!empty($value["@attributes"])){
				$attributes = $value["@attributes"];
			}else {
				$attributes = array();
			}

			if (is_string($value)){
				$root->addChild($key,$value);
			}elseif (is_array($value)){
				$childNode = $root->addChild($key);
				if (isset($attributes)){
					foreach ($attributes as $attrKey => $attrValue){
						$childNode->addAttribute($attrKey,$attrValue);
					}
					unset($attributes);
				}
				$this->set($childNode,$value);
			}

		}
		return $this;
	}
Ejemplo n.º 27
0
 /**
  * @expectedException BadMethodCallException
  */
 public function testRoot()
 {
     $root = new SimpleDOM('<root />');
     $new = new SimpleDOM('<new />');
     $root->insertBeforeSelf($new);
 }
Ejemplo n.º 28
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());
 }
Ejemplo n.º 29
0
 public function testNoChild()
 {
     $root = new SimpleDOM('<root />');
     $this->assertNull($root->firstChild());
 }
Ejemplo n.º 30
0
 public function testRoodNodeIsNeverDeleted()
 {
     $node = new SimpleDOM('<node><node /></node>');
     $node->deleteNodes('//node');
     $this->assertXmlStringEqualsXmlString('<node />', $node->asXML());
 }