From 865404a0d38560a45326d0ada0453377f29a91ec Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 25 Apr 2013 20:56:22 +0200 Subject: [PATCH] Add Assertion.prototype.xmleql This is based on the xml_eq function we had in the OL2 test framework but adapted to expect.js. --- test/expect-0.2.0-ol3/expect.js | 110 ++++++++++++++++++++++++++++++++ test/spec/ol/expect.test.js | 17 +++++ 2 files changed, 127 insertions(+) diff --git a/test/expect-0.2.0-ol3/expect.js b/test/expect-0.2.0-ol3/expect.js index 562b781aee..1f4f14c7c4 100644 --- a/test/expect-0.2.0-ol3/expect.js +++ b/test/expect-0.2.0-ol3/expect.js @@ -204,6 +204,116 @@ return this; }; + function getChildNodes(node, options) { + // check whitespace + if (options && options.includeWhiteSpace) { + return node.childNodes; + } else { + var nodes = []; + for (var i = 0, ii=node.childNodes.length; i < ii; i++ ) { + var child = node.childNodes[i]; + if (child.nodeType == 1) { + // element node, add it + nodes.push(child); + } else if (child.nodeType == 3) { + // text node, add if non empty + if (child.nodeValue && + child.nodeValue.replace(/^\s*(.*?)\s*$/, '$1') != '') { + nodes.push(child); + } + } + } + return nodes; + } + }; + + function assertElementNodesEqual(node1, node2, options) { + var testPrefix = (options && options.prefix === true); + expect(node1.nodeType).to.eql(node2.nodeType); + if (testPrefix) { + expect(node1.nodeName).to.eql(node2.nodeName); + } else { + expect(node1.nodeName.split(':').pop()).to.eql(node2.nodeName.split(':').pop()); + } + // for text nodes compare value + if (node1.nodeType === 3) { + expect(node1.nodeValue).to.eql(node2.nodeValue); + } + // for element type nodes compare namespace, attributes, and children + else if (node1.nodeType === 1) { + // test namespace alias and uri + if (node1.prefix || node2.prefix) { + if (testPrefix) { + expect(node1.prefix).to.eql(node2.prefix); + } + } + if (node1.namespaceURI || node2.namespaceURI) { + expect(node1.namespaceURI).to.eql(node2.namespaceURI); + } + // compare attributes - disregard xmlns given namespace handling above + var node1AttrLen = 0; + var node1Attr = {}; + var node2AttrLen = 0; + var node2Attr = {}; + var ga, ea, gn, en; + var i, ii; + for (i=0, ii=node1.attributes.length; i