Fix a typo in Layer.Vector.destroy and add unit tests for protocol and strategies construct/destroy, r=crschmidt (closes #1659)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7703 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Frédéric Junod
2008-08-05 05:39:11 +00:00
parent a3ffb5734c
commit 14119a6811
2 changed files with 20 additions and 7 deletions

View File

@@ -228,7 +228,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
* Destroy this layer * Destroy this layer
*/ */
destroy: function() { destroy: function() {
if (this.stategies) { if (this.strategies) {
for(var i=0, len=this.strategies.length; i<len; i++) { for(var i=0, len=this.strategies.length; i<len; i++) {
this.strategies[i].destroy(); this.strategies[i].destroy();
} }

View File

@@ -6,13 +6,19 @@
var name = "Vector Layer"; var name = "Vector Layer";
function test_Layer_Vector_constructor(t) { function test_Layer_Vector_constructor(t) {
t.plan(3); t.plan(4);
var options = {protocol: new OpenLayers.Protocol(),
strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]}
var layer = new OpenLayers.Layer.Vector(name, options);
var layer = new OpenLayers.Layer.Vector(name);
t.ok(layer instanceof OpenLayers.Layer.Vector, "new OpenLayers.Layer.Vector returns correct object" ); t.ok(layer instanceof OpenLayers.Layer.Vector, "new OpenLayers.Layer.Vector returns correct object" );
t.eq(layer.name, name, "layer name is correctly set"); t.eq(layer.name, name, "layer name is correctly set");
t.ok(layer.renderer.CLASS_NAME, "layer has a renderer"); t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
t.ok((layer.name == layer.strategies[0].layer.name) &&
(layer.strategies[0].layer.name == layer.strategies[1].layer.name),
"setLayer was called on strategies");
} }
function test_Layer_Vector_addFeatures(t) { function test_Layer_Vector_addFeatures(t) {
@@ -216,13 +222,20 @@
} }
function test_Layer_Vector_destroy (t) { function test_Layer_Vector_destroy (t) {
t.plan(2); t.plan(4);
layer = new OpenLayers.Layer.Vector(name);
var options = {protocol: new OpenLayers.Protocol(),
strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]}
var layer = new OpenLayers.Layer.Vector(name, options);
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
map.addLayer(layer); map.addLayer(layer);
layer.destroy(); layer.destroy();
t.eq(layer.map, null, "layer.map is null after destroy"); t.eq(layer.map, null, "layer.map is null after destroy");
t.eq(layer.getFeatureFromEvent({'target':'map'}), null, "getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed."); t.eq(layer.getFeatureFromEvent({'target':'map'}), null,
"getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed.");
t.eq(layer.protocol, null, "layer.protocol is null after destroy");
t.eq(layer.strategies, null, "layer.strategies is null after destroy");
} }
function test_Layer_Vector_externalGraphic(t) { function test_Layer_Vector_externalGraphic(t) {