Permalink
Browse files

Port over more test cases

  • Loading branch information...
1 parent dd8d69f commit 7145179c3094b449734545561fe7be7c35d42a55 @bartvde bartvde committed Feb 24, 2014
@@ -5,6 +5,7 @@ goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.dom.TagName');
+goog.require('goog.string');
goog.require('ol.Feature');
goog.require('ol.extent');
goog.require('ol.format.XML');
@@ -145,7 +146,11 @@ ol.format.GML.prototype.readFeature_ = function(node, objectStack) {
if (n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
n.firstChild.nodeType === 3)) {
- values[ol.xml.getLocalName(n)] = ol.xml.getAllTextContent(n, false);
+ var value = ol.xml.getAllTextContent(n, false);
+ if (goog.string.isEmpty(value)) {
+ value = undefined;
+ }
+ values[ol.xml.getLocalName(n)] = value;
} else {
geometryName = ol.xml.getLocalName(n);
values[geometryName] = this.readGeometryFromNode(n);
@@ -543,6 +543,35 @@ describe('ol.format.GML', function() {
});
+ describe('when parsing empty attribute', function() {
+ it('generates undefined value', function() {
+ var text =
+ '<gml:featureMembers xmlns:gml="http://www.opengis.net/gml">' +
+ ' <topp:gnis_pop gml:id="gnis_pop.148604" xmlns:topp="' +
+ 'http://www.openplans.org/topp">' +
+ ' <gml:name>Aflu</gml:name>' +
+ ' <topp:the_geom>' +
+ ' <gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">' +
+ ' <gml:pos>34.12 2.09</gml:pos>' +
+ ' </gml:Point>' +
+ ' </topp:the_geom>' +
+ ' <topp:population>84683</topp:population>' +
+ ' <topp:country>Algeria</topp:country>' +
+ ' <topp:type>place</topp:type>' +
+ ' <topp:name>Aflu</topp:name>' +
+ ' <topp:empty></topp:empty>' +
+ ' </topp:gnis_pop>' +
+ '</gml:featureMembers>';
+ var config = {
+ 'featureNS': 'http://www.openplans.org/topp',
+ 'featureType': 'gnis_pop'
+ };
+ var features = new ol.format.GML(config).readFeatures(text);
+ var feature = features[0];
+ expect(feature.get('empty')).to.be(undefined);
+ });
+ });
+
describe('when parsing TOPP states GML', function() {
var features;
@@ -597,6 +626,57 @@ describe('ol.format.GML', function() {
});
+ describe('when parsing more than one geometry', function() {
+
+ var features, feature;
+ before(function(done) {
+ afterLoadText('spec/ol/format/gml/more-geoms.xml', function(xml) {
+ try {
+ var config = {
+ 'featureNS': 'http://opengeo.org/#medford',
+ 'featureType': 'zoning'
+ };
+ features = new ol.format.GML(config).readFeatures(xml);
+ } catch (e) {
+ done(e);
+ }
+ done();
+ });
+ });
+
+ it('creates 2 geometries', function() {
+ var feature = features[0];
+ expect(feature.get('center')).to.be.a(ol.geom.Point);
+ expect(feature.get('the_geom')).to.be.a(ol.geom.MultiPolygon);
+ });
+
+ });
+
+ describe('when parsing an attribute name equal to featureType', function() {
+
+ var features, feature;
+ before(function(done) {
+ afterLoadText('spec/ol/format/gml/repeated-name.xml', function(xml) {
+ try {
+ var config = {
+ 'featureNS': 'http://opengeo.org/#medford',
+ 'featureType': 'zoning'
+ };
+ features = new ol.format.GML(config).readFeatures(xml);
+ } catch (e) {
+ done(e);
+ }
+ done();
+ });
+ });
+
+ it('creates the correct attribute value', function() {
+ var feature = features[0];
+ expect(feature.get('zoning')).to.equal('I-L');
+ });
+
+ });
+
});

0 comments on commit 7145179

Please sign in to comment.