From 0d2760831d83c0b649146c99a768e686e0bccf9f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 5 Nov 2008 17:44:51 +0000 Subject: [PATCH] Adding a test to show that we can stop feature modification from an event listener. git-svn-id: http://svn.openlayers.org/trunk/openlayers@8282 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- tests/Control/ModifyFeature.html | 42 +++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/Control/ModifyFeature.html b/tests/Control/ModifyFeature.html index 7c3b2f4679..fbc6611746 100644 --- a/tests/Control/ModifyFeature.html +++ b/tests/Control/ModifyFeature.html @@ -161,7 +161,47 @@ layer.destroyFeatures = function() {}; control.destroy(); layer.destroy(); - } + } + + function test_stop_modification(t) { + t.plan(1); + var map = new OpenLayers.Map('map'); + var layer = new OpenLayers.Layer.Vector("Vectors!", {isBaseLayer: true}); + var feature = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(0, 0) + ); + layer.addFeatures([feature]); + map.addLayer(layer); + map.setCenter(new OpenLayers.LonLat(0, 0)); + + + // If a feature is to be modified, control.selectFeature gets called. + // We want this test to fail if selectFeature gets called. + var modified = false; + var _ = OpenLayers.Control.ModifyFeature.prototype.selectFeature; + OpenLayers.Control.ModifyFeature.prototype.selectFeature = function() { + modified = true; + } + + var control = new OpenLayers.Control.ModifyFeature(layer); + map.addControl(control); + control.activate(); + + // register a listener that will stop feature modification + layer.events.on({"beforefeaturemodified": function() {return false}}); + + // we can initiate feature modification by selecting a feature with + // the control's select feature control + control.selectControl.select(feature); + + if(modified) { + t.fail("selectFeature called, prepping feature for modification"); + } else { + t.ok(true, "the beforefeaturemodified listener stopped feature modification"); + } + + OpenLayers.Control.ModifyFeature.prototype.selectFeature = _; + } function test_selectFeature(t) { t.plan(12);