import _ol_Feature_ from '../../../../src/ol/Feature.js'; import _ol_format_GML2_ from '../../../../src/ol/format/GML2.js'; import _ol_format_WFS_ from '../../../../src/ol/format/WFS.js'; import _ol_format_filter_ from '../../../../src/ol/format/filter.js'; import _ol_geom_LineString_ from '../../../../src/ol/geom/LineString.js'; import _ol_geom_MultiLineString_ from '../../../../src/ol/geom/MultiLineString.js'; import MultiPoint from '../../../../src/ol/geom/MultiPoint.js'; import _ol_geom_MultiPolygon_ from '../../../../src/ol/geom/MultiPolygon.js'; import _ol_geom_Polygon_ from '../../../../src/ol/geom/Polygon.js'; import {transform} from '../../../../src/ol/proj.js'; import _ol_xml_ from '../../../../src/ol/xml.js'; describe('ol.format.WFS', function() { describe('featureType', function() { it('#getFeatureType #setFeatureType', function() { var format = new _ol_format_WFS_({ featureNS: 'http://www.openplans.org/topp', featureType: ['foo', 'bar'] }); expect(format.getFeatureType()).to.eql(['foo', 'bar']); format.setFeatureType('baz'); expect(format.getFeatureType()).to.eql('baz'); }); }); describe('when parsing TOPP states GML from WFS', function() { var features, feature, xml; var config = { 'featureNS': 'http://www.openplans.org/topp', 'featureType': 'states' }; before(function(done) { proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(data) { try { xml = data; features = new _ol_format_WFS_(config).readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('creates 3 features', function() { expect(features).to.have.length(3); }); it('creates a polygon for Illinois', function() { feature = features[0]; expect(feature.getId()).to.equal('states.1'); expect(feature.get('STATE_NAME')).to.equal('Illinois'); expect(feature.getGeometry()).to.be.an(_ol_geom_MultiPolygon_); }); it('transforms and creates a polygon for Illinois', function() { features = new _ol_format_WFS_(config).readFeatures(xml, { featureProjection: 'EPSG:3857' }); feature = features[0]; expect(feature.getId()).to.equal('states.1'); expect(feature.get('STATE_NAME')).to.equal('Illinois'); var geom = feature.getGeometry(); expect(geom).to.be.an(_ol_geom_MultiPolygon_); var p = transform([-88.071, 37.511], 'EPSG:4326', 'EPSG:3857'); p.push(0); expect(geom.getFirstCoordinate()).to.eql(p); }); }); describe('when parsing mapserver GML2 polygon', function() { var features, feature, xml; var config = { 'featureNS': 'http://mapserver.gis.umn.edu/mapserver', 'featureType': 'polygon', 'gmlFormat': new _ol_format_GML2_() }; before(function(done) { proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); afterLoadText('spec/ol/format/wfs/polygonv2.xml', function(data) { try { xml = data; features = new _ol_format_WFS_(config).readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('creates 3 features', function() { expect(features).to.have.length(3); }); it('creates a polygon for My Polygon with hole', function() { feature = features[0]; expect(feature.getId()).to.equal('1'); expect(feature.get('name')).to.equal('My Polygon with hole'); expect(feature.get('boundedBy')).to.eql( [47.003018, -0.768746, 47.925567, 0.532597]); expect(feature.getGeometry()).to.be.an(_ol_geom_MultiPolygon_); expect(feature.getGeometry().getFlatCoordinates()). to.have.length(60); }); }); describe('when parsing FeatureCollection', function() { var xml; before(function(done) { afterLoadText('spec/ol/format/wfs/EmptyFeatureCollection.xml', function(_xml) { xml = _xml; done(); }); }); it('returns an empty array of features when none exist', function() { var result = new _ol_format_WFS_().readFeatures(xml); expect(result).to.have.length(0); }); }); describe('when parsing FeatureCollection', function() { var response; before(function(done) { afterLoadText('spec/ol/format/wfs/NumberOfFeatures.xml', function(xml) { try { response = new _ol_format_WFS_().readFeatureCollectionMetadata(xml); } catch (e) { done(e); } done(); }); }); it('returns the correct number of features', function() { expect(response.numberOfFeatures).to.equal(625); }); }); describe('when parsing FeatureCollection', function() { var response; before(function(done) { proj4.defs('EPSG:28992', '+proj=sterea +lat_0=52.15616055555555 ' + '+lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 ' + '+ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,' + '-1.8774,4.0725 +units=m +no_defs'); afterLoadText('spec/ol/format/wfs/boundedBy.xml', function(xml) { try { response = new _ol_format_WFS_().readFeatureCollectionMetadata(xml); } catch (e) { done(e); } done(); }); }); it('returns the correct bounds', function() { expect(response.bounds).to.eql([3197.88, 306457.313, 280339.156, 613850.438]); }); }); describe('when parsing TransactionResponse', function() { var response; before(function(done) { afterLoadText('spec/ol/format/wfs/TransactionResponse.xml', function(xml) { try { response = new _ol_format_WFS_().readTransactionResponse(xml); } catch (e) { done(e); } done(); }); }); it('returns the correct TransactionResponse object', function() { expect(response.transactionSummary.totalDeleted).to.equal(0); expect(response.transactionSummary.totalInserted).to.equal(0); expect(response.transactionSummary.totalUpdated).to.equal(1); expect(response.insertIds).to.have.length(2); expect(response.insertIds[0]).to.equal('parcelle.40'); }); }); describe('when writing out a GetFeature request', function() { it('creates the expected output', function() { var text = '' + ' ' + ' STATE_NAME' + ' STATE_FIPS' + ' STATE_ABBR' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ resultType: 'hits', featureTypes: ['states'], featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', srsName: 'urn:ogc:def:crs:EPSG::4326', propertyNames: ['STATE_NAME', 'STATE_FIPS', 'STATE_ABBR'] }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); it('creates paging headers', function() { var text = '' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ count: 10, startIndex: 20, srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'] }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); it('creates a BBOX filter', function() { var text = '' + ' ' + ' ' + ' the_geom' + ' ' + ' 1 2' + ' 3 4' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], geometryName: 'the_geom', bbox: [1, 2, 3, 4] }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates a property filter', function() { var text = '' + ' ' + ' ' + ' name' + ' New York' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.equalTo('name', 'New York', false) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates two property filters', function() { var text = '' + ' ' + ' ' + ' ' + ' name' + ' New York' + ' ' + ' ' + ' area' + ' 1234' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.or( _ol_format_filter_.equalTo('name', 'New York'), _ol_format_filter_.equalTo('area', 1234)) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates greater/less than property filters', function() { var text = '' + ' ' + ' ' + ' ' + ' ' + ' area' + ' 100' + ' ' + ' ' + ' pop' + ' 20000' + ' ' + ' ' + ' ' + ' ' + ' area' + ' 100' + ' ' + ' ' + ' pop' + ' 20000' + ' ' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.or( _ol_format_filter_.and( _ol_format_filter_.greaterThan('area', 100), _ol_format_filter_.greaterThanOrEqualTo('pop', 20000) ), _ol_format_filter_.and( _ol_format_filter_.lessThan('area', 100), _ol_format_filter_.lessThanOrEqualTo('pop', 20000) ) ) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates isBetween property filter', function() { var text = '' + ' ' + ' ' + ' area' + ' 100' + ' 1000' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.between('area', 100, 1000) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates isNull property filter', function() { var text = '' + ' ' + ' ' + ' area' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.isNull('area') }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates isLike property filter', function() { var text = '' + ' ' + ' ' + ' name' + ' New*' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.like('name', 'New*') }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates isLike property filter with arguments', function() { var text = '' + ' ' + ' ' + ' name' + ' New*' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.like('name', 'New*', '*', '.', '!', false) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates a Not filter', function() { var text = '' + ' ' + ' ' + ' ' + ' name' + ' New York' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.not(_ol_format_filter_.equalTo('name', 'New York')) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates an AND filter', function() { var text = '' + ' ' + ' ' + ' ' + ' name' + ' New York' + ' ' + ' ' + ' the_geom' + ' ' + ' 1 2' + ' 3 4' + ' ' + ' ' + ' ' + ' population' + ' 2000000' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], filter: _ol_format_filter_.and( _ol_format_filter_.equalTo('name', 'New York'), _ol_format_filter_.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'), _ol_format_filter_.greaterThan('population', 2000000) ) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates a contains filter', function() { var text = '' + ' ' + ' ' + ' the_geom' + ' ' + ' ' + ' ' + ' ' + ' 10 20 10 25 15 25 15 20 10 20' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], filter: _ol_format_filter_.contains( 'the_geom', new _ol_geom_Polygon_([[ [10, 20], [10, 25], [15, 25], [15, 20], [10, 20] ]]) ) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates a intersects filter', function() { var text = '' + ' ' + ' ' + ' the_geom' + ' ' + ' ' + ' ' + ' ' + ' 10 20 10 25 15 25 15 20 10 20' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], filter: _ol_format_filter_.intersects( 'the_geom', new _ol_geom_Polygon_([[ [10, 20], [10, 25], [15, 25], [15, 20], [10, 20] ]]) ) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates a within filter', function() { var text = '' + ' ' + ' ' + ' the_geom' + ' ' + ' ' + ' ' + ' ' + ' 10 20 10 25 15 25 15 20 10 20' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], filter: _ol_format_filter_.within( 'the_geom', new _ol_geom_Polygon_([[ [10, 20], [10, 25], [15, 25], [15, 20], [10, 20] ]]) ) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); it('creates During property filter', function() { var text = '' + ' ' + ' ' + ' date_prop' + ' ' + ' ' + ' ' + ' 2010-01-20T00:00:00Z' + ' ' + ' ' + ' ' + ' ' + ' 2012-12-31T00:00:00Z' + ' ' + ' ' + ' ' + ' ' + ' ' + ''; var serialized = new _ol_format_WFS_().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['states'], filter: _ol_format_filter_.during('date_prop', '2010-01-20T00:00:00Z', '2012-12-31T00:00:00Z') }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { it('creates a handle', function() { var text = ''; var serialized = new _ol_format_WFS_().writeTransaction(null, null, null, {handle: 'handle_t'}); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/TransactionSrs.xml', function(xml) { text = xml; done(); }); }); it('creates the correct srsName', function() { var format = new _ol_format_WFS_(); var insertFeature = new _ol_Feature_({ the_geom: new _ol_geom_MultiLineString_([[ [-5178372.1885436, 1992365.7775042], [-4434792.7774889, 1601008.1927386], [-4043435.1927233, 2148908.8114105] ]]), TYPE: 'xyz' }); insertFeature.setGeometryName('the_geom'); var inserts = [insertFeature]; var serialized = format.writeTransaction(inserts, null, null, { featureNS: 'http://foo', featureType: 'FAULTS', featurePrefix: 'feature', gmlOptions: {multiCurve: true, srsName: 'EPSG:900913'} }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/TransactionUpdate.xml', function(xml) { text = xml; done(); }); }); it('creates the correct update', 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] ]])); updateFeature.setId('FAULTS.4455'); var serialized = format.writeTransaction(null, [updateFeature], null, { featureNS: 'http://foo', featureType: 'FAULTS', featurePrefix: 'foo', gmlOptions: {srsName: 'EPSG:900913'} }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); it('creates the correct update if geometry name is alias', function() { var format = new _ol_format_WFS_(); var updateFeature = new _ol_Feature_(new _ol_geom_MultiLineString_([[ [-12279454, 6741885], [-12064207, 6732101], [-11941908, 6595126], [-12240318, 6507071], [-12416429, 6604910] ]])); updateFeature.setGeometryName('the_geom'); updateFeature.setId('FAULTS.4455'); var serialized = format.writeTransaction(null, [updateFeature], null, { featureNS: 'http://foo', featureType: 'FAULTS', featurePrefix: 'foo', gmlOptions: {srsName: 'EPSG:900913'} }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { it('creates the correct update with default featurePrefix', 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] ]])); updateFeature.setId('FAULTS.4455'); var serialized = format.writeTransaction(null, [updateFeature], null, { featureNS: 'http://foo', featureType: 'FAULTS', gmlOptions: {srsName: 'EPSG:900913'} }); expect(serialized.firstChild.attributes.getNamedItem('xmlns:feature') !== null).to.equal(true); }); }); 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] ]])); expect(function() { format.writeTransaction(null, [updateFeature], null, { featureNS: 'http://foo', featureType: 'FAULTS', featurePrefix: 'foo', gmlOptions: {srsName: 'EPSG:900913'} }); }).to.throwException(); }); }); describe('when writing out a Transaction request', function() { var text, filename = 'spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml'; before(function(done) { afterLoadText(filename, function(xml) { text = xml; done(); } ); }); it('handles multiple geometries', 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] ]])); updateFeature.set('geom2', new _ol_geom_MultiLineString_([[ [-12000000, 6700000], [-12000001, 6700001], [-12000002, 6700002] ]])); var serialized = format.writeTransaction([updateFeature], [], null, { featureNS: 'http://foo', featureType: 'FAULTS', featurePrefix: 'foo', gmlOptions: {srsName: 'EPSG:900913'} }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/TransactionMulti.xml', function(xml) { text = xml; done(); }); }); it('creates the correct transaction body', function() { var format = new _ol_format_WFS_(); var insertFeature = new _ol_Feature_({ the_geom: new MultiPoint([[1, 2]]), foo: 'bar', nul: null }); insertFeature.setGeometryName('the_geom'); var inserts = [insertFeature]; var updateFeature = new _ol_Feature_({ the_geom: new MultiPoint([[1, 2]]), foo: 'bar', // null value gets Property element with no Value nul: null, // undefined value means don't create a Property element unwritten: undefined }); updateFeature.setId('fid.42'); updateFeature.setGeometryName('the_geom'); var updates = [updateFeature]; var deleteFeature = new _ol_Feature_(); deleteFeature.setId('fid.37'); var deletes = [deleteFeature]; var serialized = format.writeTransaction(inserts, updates, deletes, { featureNS: 'http://www.openplans.org/topp', featureType: 'states', featurePrefix: 'topp' }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/Native.xml', function(xml) { text = xml; done(); }); }); it('handles writing out Native', function() { var format = new _ol_format_WFS_(); var serialized = format.writeTransaction(null, null, null, { nativeElements: [{ vendorId: 'ORACLE', safeToIgnore: true, value: 'ALTER SESSION ENABLE PARALLEL DML' }, { vendorId: 'ORACLE', safeToIgnore: false, value: 'Another native line goes here' }] }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; var filename = 'spec/ol/format/wfs/TransactionMultiVersion100.xml'; before(function(done) { afterLoadText(filename, function(xml) { text = xml; done(); }); }); it('handles the WFS version', function() { var format = new _ol_format_WFS_(); var insertFeature = new _ol_Feature_({ the_geom: new _ol_geom_LineString_([[1.1, 2], [3, 4.2]]), foo: 'bar', nul: null }); insertFeature.setGeometryName('the_geom'); var inserts = [insertFeature]; var updateFeature = new _ol_Feature_({ the_geom: new _ol_geom_LineString_([[1.1, 2], [3, 4.2]]), foo: 'bar', // null value gets Property element with no Value nul: null, // undefined value means don't create a Property element unwritten: undefined }); updateFeature.setId('fid.42'); updateFeature.setGeometryName('the_geom'); var updates = [updateFeature]; var deleteFeature = new _ol_Feature_(); deleteFeature.setId('fid.37'); var deletes = [deleteFeature]; var serialized = format.writeTransaction(inserts, updates, deletes, { featureNS: 'http://www.openplans.org/topp', featureType: 'states', featurePrefix: 'topp', version: '1.0.0' }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/TransactionMulti.xml', function(xml) { text = xml; done(); }); }); it('do not add feature prefix twice', function() { var format = new _ol_format_WFS_(); var insertFeature = new _ol_Feature_({ the_geom: new MultiPoint([[1, 2]]), foo: 'bar', nul: null }); insertFeature.setGeometryName('the_geom'); var inserts = [insertFeature]; var updateFeature = new _ol_Feature_({ the_geom: new MultiPoint([[1, 2]]), foo: 'bar', // null value gets Property element with no Value nul: null, // undefined value means don't create a Property element unwritten: undefined }); updateFeature.setId('fid.42'); updateFeature.setGeometryName('the_geom'); var updates = [updateFeature]; var deleteFeature = new _ol_Feature_(); deleteFeature.setId('fid.37'); var deletes = [deleteFeature]; var serialized = format.writeTransaction(inserts, updates, deletes, { featureNS: 'http://www.openplans.org/topp', featureType: 'topp:states', featurePrefix: 'topp' }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a transaction request', function() { var text; var filename = 'spec/ol/format/wfs/TransactionMultiVersion100_3D.xml'; before(function(done) { afterLoadText(filename, function(xml) { text = xml; done(); }); }); it('handles 3D in WFS 1.0.0', function() { var format = new _ol_format_WFS_(); var insertFeature = new _ol_Feature_({ the_geom: new _ol_geom_LineString_([[1.1, 2, 4], [3, 4.2, 5]]), foo: 'bar', nul: null }); insertFeature.setGeometryName('the_geom'); var inserts = [insertFeature]; var updateFeature = new _ol_Feature_({ the_geom: new _ol_geom_LineString_([[1.1, 2, 6], [3, 4.2, 7]]), foo: 'bar', // null value gets Property element with no Value nul: null, // undefined value means don't create a Property element unwritten: undefined }); updateFeature.setGeometryName('the_geom'); updateFeature.setId('fid.42'); var updates = [updateFeature]; var serialized = format.writeTransaction(inserts, updates, null, { featureNS: 'http://www.openplans.org/topp', featureType: 'states', featurePrefix: 'topp', hasZ: true, version: '1.0.0' }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a Transaction request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/TransactionMulti_3D.xml', function(xml) { text = xml; done(); }); }); it('handles 3D in WFS 1.1.0', function() { var format = new _ol_format_WFS_(); var insertFeature = new _ol_Feature_({ the_geom: new MultiPoint([[1, 2, 3]]), foo: 'bar', nul: null }); insertFeature.setGeometryName('the_geom'); var inserts = [insertFeature]; var updateFeature = new _ol_Feature_({ the_geom: new MultiPoint([[1, 2, 3]]), foo: 'bar', // null value gets Property element with no Value nul: null, // undefined value means don't create a Property element unwritten: undefined }); updateFeature.setGeometryName('the_geom'); updateFeature.setId('fid.42'); var updates = [updateFeature]; var serialized = format.writeTransaction(inserts, updates, null, { featureNS: 'http://www.openplans.org/topp', featureType: 'states', hasZ: true, featurePrefix: 'topp' }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when writing out a GetFeature request', function() { var text; before(function(done) { afterLoadText('spec/ol/format/wfs/GetFeatureMultiple.xml', function(xml) { text = xml; done(); }); }); it('handles writing multiple Query elements', function() { var format = new _ol_format_WFS_(); var serialized = format.writeGetFeature({ featureNS: 'http://www.openplans.org/topp', featureTypes: ['states', 'cities'], featurePrefix: 'topp' }); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); describe('when parsing GML from MapServer', function() { var features, feature; before(function(done) { afterLoadText('spec/ol/format/wfs/mapserver.xml', function(xml) { try { var config = { 'featureNS': 'http://mapserver.gis.umn.edu/mapserver', 'featureType': 'Historische_Messtischblaetter_WFS' }; features = new _ol_format_WFS_(config).readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('creates 7 features', function() { expect(features).to.have.length(7); }); it('creates a polygon for Arnstadt', function() { feature = features[0]; var fid = 'Historische_Messtischblaetter_WFS.71055885'; expect(feature.getId()).to.equal(fid); expect(feature.get('titel')).to.equal('Arnstadt'); expect(feature.getGeometry()).to.be.an(_ol_geom_Polygon_); }); }); describe('when parsing multiple feature types', function() { var features; before(function(done) { afterLoadText('spec/ol/format/gml/multiple-typenames.xml', function(xml) { try { features = new _ol_format_WFS_({ featureNS: 'http://localhost:8080/official', featureType: ['planet_osm_polygon', 'planet_osm_line'] }).readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('reads all features', function() { expect(features.length).to.be(12); }); }); describe('when parsing multiple feature types separately', function() { var lineFeatures, polygonFeatures; before(function(done) { afterLoadText('spec/ol/format/gml/multiple-typenames.xml', function(xml) { try { lineFeatures = new _ol_format_WFS_({ featureNS: 'http://localhost:8080/official', featureType: ['planet_osm_line'] }).readFeatures(xml); polygonFeatures = new _ol_format_WFS_({ featureNS: 'http://localhost:8080/official', featureType: ['planet_osm_polygon'] }).readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('reads all features', function() { expect(lineFeatures.length).to.be(3); expect(polygonFeatures.length).to.be(9); }); }); describe('when parsing multiple feature types', function() { var features; before(function(done) { afterLoadText('spec/ol/format/gml/multiple-typenames.xml', function(xml) { try { features = new _ol_format_WFS_().readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('reads all features with autoconfigure', function() { expect(features.length).to.be(12); }); }); describe('when parsing multiple feature types (MapServer)', function() { var features; before(function(done) { afterLoadText('spec/ol/format/gml/multiple-typenames-mapserver.xml', function(xml) { try { features = new _ol_format_WFS_().readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('reads all features', function() { expect(features.length).to.be(5); features.forEach(function(feature) { expect(feature instanceof _ol_Feature_).to.be(true); }); }); }); describe('when parsing multiple feature types separately (MapServer)', function() { var busFeatures, infoFeatures; before(function(done) { afterLoadText('spec/ol/format/gml/multiple-typenames-mapserver.xml', function(xml) { try { busFeatures = new _ol_format_WFS_({ featureNS: 'http://mapserver.gis.umn.edu/mapserver', featureType: ['bus_stop'] }).readFeatures(xml); infoFeatures = new _ol_format_WFS_({ featureNS: 'http://mapserver.gis.umn.edu/mapserver', featureType: ['information'] }).readFeatures(xml); } catch (e) { done(e); } done(); }); }); it('reads all features', function() { expect(busFeatures.length).to.be(3); expect(infoFeatures.length).to.be(2); }); }); describe('when writing out a WFS Filter', function() { it('creates a filter', function() { var text = '' + ' ' + ' ' + ' name' + ' Mississippi*' + ' ' + ' ' + ' waterway' + ' riverbank' + ' ' + ' ' + ''; var serialized = _ol_format_WFS_.writeFilter( _ol_format_filter_.and( _ol_format_filter_.like('name', 'Mississippi*'), _ol_format_filter_.equalTo('waterway', 'riverbank') ) ); expect(serialized).to.xmleql(_ol_xml_.parse(text)); }); }); });