OpenLayers OpenLayers

Changeset 7987

Show
Ignore:
Timestamp:
09/09/08 13:50:41 (2 years ago)
Author:
tschaub
Message:

Making the xml_eq test method ignore whitespace only nodes by default. This can be configured by setting the ignoreWhiteSpace option. (see #1639)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/tests/xml_eq.js

    r7321 r7987  
    9898     * got - {DOMElement} 
    9999     * expected - {DOMElement} 
    100      * options - {Object} Optional object for configuring test options.  Set 
    101      *     'prefix' property to true in order to compare element and attribute 
    102      *     prefixes (namespace uri always tested).  By default, prefixes 
    103      *     are not tested. 
     100     * options - {Object} Optional object for configuring test options. 
     101     * 
     102     * Valid options: 
     103     * prefix - {Boolean} Compare element and attribute 
     104     *     prefixes (namespace uri always tested).  Default is false. 
     105     * includeWhiteSpace - {Boolean} Include whitespace only nodes when 
     106     *     comparing child nodes.  Default is false. 
    104107     */ 
    105108    function assertElementNodesEqual(got, expected, options) { 
     
    191194             
    192195            // compare children 
     196            var gotChildNodes = getChildNodes(got, options); 
     197            var expChildNodes = getChildNodes(expected, options); 
     198 
    193199            assertEqual( 
    194                 got.childNodes.length, expected.childNodes.length, 
     200                gotChildNodes.length, expChildNodes.length, 
    195201                "Children length mismatch for " + got.nodeName 
    196202            ); 
    197             for(var j=0; j<got.childNodes.length; ++j) { 
     203            for(var j=0; j<gotChildNodes.length; ++j) { 
    198204                try { 
    199205                    assertElementNodesEqual( 
    200                         got.childNodes[j], expected.childNodes[j] 
     206                        gotChildNodes[j], expChildNodes[j], options 
    201207                    ); 
    202208                } catch(err) { 
     
    207213        return true; 
    208214    } 
     215 
     216    /** 
     217     * Function getChildNodes 
     218     * Returns the child nodes of the specified nodes. By default this method 
     219     *     will ignore child text nodes which are made up of whitespace content. 
     220     *     The 'includeWhiteSpace' option is used to control this behaviour. 
     221     *  
     222     * Parameters: 
     223     * node - {DOMElement} 
     224     * options - {Object} Optional object for test configuration. 
     225     *  
     226     * Valid options: 
     227     * includeWhiteSpace - {Boolean} Include whitespace only nodes when 
     228     *     comparing child nodes.  Default is false. 
     229     *  
     230     * Returns: 
     231     * {Array} of {DOMElement} 
     232     */ 
     233    function getChildNodes(node, options) { 
     234        //check whitespace 
     235        if (options && options.includeWhiteSpace) { 
     236            return node.childNodes; 
     237        } 
     238        else { 
     239           nodes = []; 
     240           for (var i = 0; i < node.childNodes.length; i++ ) { 
     241              var child = node.childNodes[i]; 
     242              if (child.nodeType == 1) { 
     243                 //element node, add it  
     244                 nodes.push(child); 
     245              } 
     246              else if (child.nodeType == 3) { 
     247                 //text node, add if non empty 
     248                 if (child.nodeValue &&  
     249                       child.nodeValue.replace(/^\s*(.*?)\s*$/, "$1") != "" ) {  
     250 
     251                    nodes.push(child); 
     252                 } 
     253              } 
     254           } 
     255   
     256           return nodes; 
     257        } 
     258    }  
    209259     
    210260    /** 
     
    222272     * expected - {DOMElement | String} The expected DOM node or XML string. 
    223273     * msg - {String} A message to print with test output. 
    224      * options - {Object} Optional object for configuring test options.  Set 
    225      *     'prefix' property to true in order to compare element and attribute 
    226      *     prefixes (namespace uri always tested).  By default, prefixes 
    227      *     are not tested. 
     274     * options - {Object} Optional object for configuring test. 
     275     * 
     276     * Valid options: 
     277     * prefix - {Boolean} Compare element and attribute 
     278     *     prefixes (namespace uri always tested).  Default is false. 
     279     * includeWhiteSpace - {Boolean} Include whitespace only nodes when 
     280     *     comparing child nodes.  Default is false. 
    228281     */ 
    229282    var proto = Test.AnotherWay._test_object_t.prototype;