Annotation of embedaddon/php/ext/dom/tests/DOMNode_cloneNode_basic.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: DOM cloneNode : Basic Functionality
        !             3: --SKIPIF--
        !             4: <?php
        !             5: require_once('skipif.inc');
        !             6: ?>
        !             7: --CREDITS--
        !             8: Simon Hughes <odbc3@hotmail.com>
        !             9: --FILE--
        !            10: <?php
        !            11: 
        !            12: $xml = <<< EOXML
        !            13: <?xml version="1.0" encoding="ISO-8859-1"?>
        !            14: <courses>
        !            15:        <course title="one">
        !            16:                <notes>
        !            17:                        <note>c1n1</note>
        !            18:                        <note>c1n2</note>
        !            19:                </notes>
        !            20:        </course>
        !            21:        <course title="two">
        !            22:                <notes>
        !            23:                        <note>c2n1</note>
        !            24:                        <note>c2n2</note>
        !            25:                </notes>
        !            26:        </course>
        !            27: </courses>
        !            28: EOXML;
        !            29: 
        !            30: function dumpcourse($current) {
        !            31:        $title = ($current->nodeType != XML_TEXT_NODE && $current->hasAttribute('title')) ? $current->getAttribute('title'):"no title"; 
        !            32:        echo "Course: $title:";var_dump($current);
        !            33:        echo "~";var_dump($current->textContent);
        !            34: }
        !            35: 
        !            36: $dom = new DOMDocument();
        !            37: $dom->loadXML($xml);
        !            38: $root = $dom->documentElement;
        !            39: 
        !            40: // strip all text nodes from this tree
        !            41: $children = $root->childNodes;
        !            42: $len = $children->length;
        !            43: for ($index = $children->length - 1; $index >=0; $index--) {
        !            44:        $current = $children->item($index);
        !            45:        if ($current->nodeType == XML_TEXT_NODE) {
        !            46:                $noderemoved = $root->removeChild($current);
        !            47:        }
        !            48: }
        !            49: 
        !            50: echo "Start cloneNode test\n";
        !            51: $first_course = $children->item(0);
        !            52: $cloned_first_course_default = $first_course->cloneNode();
        !            53: $first_course->setAttribute('title', 'new title1');
        !            54: 
        !            55: $cloned_first_course_true = $first_course->cloneNode(true);
        !            56: $first_course->setAttribute('title', 'new title2');
        !            57: 
        !            58: $cloned_first_course_false = $first_course->cloneNode(false);
        !            59: $first_course->setAttribute('title', 'new title3');
        !            60: 
        !            61: $cloned_first_course_default->setAttribute('title', 'new title default');
        !            62: $cloned_first_course_true->setAttribute('title', 'new title true');
        !            63: $cloned_first_course_false->setAttribute('title', 'new title false');
        !            64: 
        !            65: $root->appendChild($cloned_first_course_default);
        !            66: $root->appendChild($cloned_first_course_true);
        !            67: $root->appendChild($cloned_first_course_false);
        !            68: 
        !            69: $children = $root->childNodes;
        !            70: for ($index = 0; $index < $children->length; $index++) {
        !            71:        echo "node $index\n";
        !            72:        dumpcourse($children->item($index));
        !            73: }
        !            74: 
        !            75: --EXPECTF--
        !            76: Start cloneNode test
        !            77: node 0
        !            78: Course: new title3:object(DOMElement)#6 (0) {
        !            79: }
        !            80: ~string(24) "
        !            81:                
        !            82:                        c1n1
        !            83:                        c1n2
        !            84:                
        !            85:        "
        !            86: node 1
        !            87: Course: two:object(DOMElement)#3 (0) {
        !            88: }
        !            89: ~string(24) "
        !            90:                
        !            91:                        c2n1
        !            92:                        c2n2
        !            93:                
        !            94:        "
        !            95: node 2
        !            96: Course: new title default:object(DOMElement)#4 (0) {
        !            97: }
        !            98: ~string(0) ""
        !            99: node 3
        !           100: Course: new title true:object(DOMElement)#7 (0) {
        !           101: }
        !           102: ~string(24) "
        !           103:                
        !           104:                        c1n1
        !           105:                        c1n2
        !           106:                
        !           107:        "
        !           108: node 4
        !           109: Course: new title false:object(DOMElement)#8 (0) {
        !           110: }
        !           111: ~string(0) ""

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>