From 84b418b5c6bd201d7d90867e0986a542ef23bd5c Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 19 Feb 2016 09:41:13 +0100 Subject: [PATCH] Assert we have a feature id --- src/ol/format/wfsformat.js | 6 ++++-- test/spec/ol/format/wfsformat.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 0985637b74..6c6e16303d 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -411,6 +411,7 @@ ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) { ol.format.WFS.writeDelete_ = function(node, feature, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context), 'context should be an Object'); + goog.asserts.assert(feature.getId() !== undefined, 'feature should have an id'); var featureType = context['featureType']; var featurePrefix = context['featurePrefix']; featurePrefix = featurePrefix ? featurePrefix : @@ -420,7 +421,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) { ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix, featureNS); var fid = feature.getId(); - if (fid) { + if (fid !== undefined) { ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack); } }; @@ -435,6 +436,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) { ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context), 'context should be an Object'); + goog.asserts.assert(feature.getId() !== undefined, 'feature should have an id'); var featureType = context['featureType']; var featurePrefix = context['featurePrefix']; featurePrefix = featurePrefix ? featurePrefix : @@ -444,7 +446,7 @@ ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) { ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix, featureNS); var fid = feature.getId(); - if (fid) { + if (fid !== undefined) { var keys = feature.getKeys(); var values = []; for (var i = 0, ii = keys.length; i < ii; i++) { diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 150a575a60..3c26d26ebc 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -328,6 +328,33 @@ describe('ol.format.WFS', function() { }); }); + describe('when writing out a Transaction request', function() { + + it('does not create an update if no fid', function() { + var format = new ol.format.WFS(); + var updateFeature = new ol.Feature(); + updateFeature.setGeometryName('the_geom'); + updateFeature.setGeometry(new ol.geom.MultiLineString([[ + [-12279454, 6741885], + [-12064207, 6732101], + [-11941908, 6595126], + [-12240318, 6507071], + [-12416429, 6604910] + ]])); + var error = false; + try { + format.writeTransaction(null, [updateFeature], null, { + featureNS: 'http://foo', + featureType: 'FAULTS', + featurePrefix: 'foo', + gmlOptions: {srsName: 'EPSG:900913'} + }); + } catch (e) { + error = true; + } + expect(error).to.be(true); + }); + }); describe('when writing out a Transaction request', function() { var text, filename = 'spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml';