Pullup r2999:3087 for RC2.

svn merge trunk/openlayers/@2999 trunk/openlayers/@HEAD branches/openlayers/2.4/



git-svn-id: http://svn.openlayers.org/branches/openlayers/2.4@3088 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-04-20 01:10:43 +00:00
parent b6fb16153c
commit b5103eb8ce
58 changed files with 1399 additions and 503 deletions

View File

@@ -0,0 +1,107 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var map;
function test_01_Control_KeyboardDefaults_constructor (t) {
t.plan( 1 );
control = new OpenLayers.Control.KeyboardDefaults();
t.ok( control instanceof OpenLayers.Control.KeyboardDefaults,
"new OpenLayers.Control.KeyboardDefaults returns object" );
}
function test_02_Control_KeyboardDefaults_addControl (t) {
t.plan( 4 );
map = new OpenLayers.Map('map');
control = new OpenLayers.Control.KeyboardDefaults();
t.ok( control instanceof OpenLayers.Control.KeyboardDefaults,
"new OpenLayers.Control.KeyboardDefaults returns object" );
t.ok( map instanceof OpenLayers.Map,
"new OpenLayers.Map creates map" );
map.addControl(control);
t.ok( control.map === map, "Control.map is set to the map object" );
t.ok( map.controls[3] === control, "map.controls contains control" );
}
function test_03_Control_KeyboardDefaults_KeyDownEvent (t) {
t.plan( 10 );
var evt = {which: 1};
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.KeyboardDefaults();
map.addControl(control);
var centerLL = new OpenLayers.LonLat(0,0);
map.setCenter(centerLL,4);
evt.keyCode = OpenLayers.Event.KEY_LEFT;
control.defaultKeyDown(evt);
t.delay_call(
1, function() {
t.ok( map.getCenter().lon < centerLL.lon, "key left works correctly" );
evt.keyCode = OpenLayers.Event.KEY_RIGHT;
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lon == centerLL.lon, "key right works correctly" );
evt.keyCode = OpenLayers.Event.KEY_UP;
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lat > centerLL.lat, "key up works correctly" );
evt.keyCode = OpenLayers.Event.KEY_DOWN;
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lat == centerLL.lat, "key down works correctly" );
evt.keyCode = 33; //page up
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lat > centerLL.lat, "key page up works correctly" );
evt.keyCode = 34; //page down
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lat == centerLL.lat, "key page down works correctly" );
evt.keyCode = 35; //end
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lon > centerLL.lon, "key end works correctly" );
evt.keyCode = 36; //pos1
control.defaultKeyDown(evt);
},
1, function() {
t.ok( map.getCenter().lon == centerLL.lon, "key pos1 works correctly" );
evt.charCode = 43; //+
control.defaultKeyDown(evt);
},
1, function() {
t.eq( map.getZoom(), 5, "key + works correctly" );
// set zoomanimation flag manually,
// reason: loadend event in layers.js will not achieved in unittests
map.zoomanimationActive = false;
evt.charCode = 45; //-
control.defaultKeyDown(evt);
},
1, function() {
t.eq( map.getZoom(), 4, "key - works correctly" );
}
);
}
// -->
</script>
</head>
<body>
<div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>

View File

@@ -36,29 +36,84 @@
//ie can't simulate mouseclicks
t.plan(0)
} else {
t.plan( 7 );
t.plan(35);
t.open_window( "Control/test_PanZoom.html", function( wnd ) {
t.delay_call( 3, function() {
simulateClick(wnd, wnd.control.buttons[0]);
var flag;
function setFlag(evt) {
flag[evt.type] = true;
}
function resetFlags() {
flag = {
mousedown: false,
mouseup: false,
click: false,
dblclick: false
};
}
resetFlags();
wnd.mapper.events.register("mousedown", mapper, setFlag);
wnd.mapper.events.register("mouseup", mapper, setFlag);
wnd.mapper.events.register("click", mapper, setFlag);
wnd.mapper.events.register("dblclick", mapper, setFlag);
simulateClick(wnd, wnd.control.buttons[0]);
t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[1]);
t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "Pan left works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[2]);
t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[3]);
t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[4]);
t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[6]);
t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[5]);
t.eq( wnd.mapper.getZoom(), 2, "zoomworld works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(!flag.mouseup, "mouseup does not get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
});
});
}
@@ -67,7 +122,19 @@
function simulateClick(wnd, elem) {
var evt = wnd.document.createEvent("MouseEvents");
evt.initMouseEvent("mousedown", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var canceled = !elem.dispatchEvent(evt);
elem.dispatchEvent(evt);
evt = wnd.document.createEvent("MouseEvents");
evt.initMouseEvent("mouseup", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
evt = wnd.document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
evt = wnd.document.createEvent("MouseEvents");
evt.initMouseEvent("dblclick", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
}
function loader() {

View File

@@ -2,7 +2,6 @@
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var map;
var feature;

View File

@@ -83,7 +83,7 @@
coll.addComponents(new OpenLayers.Geometry.Point(10,10));
coll2 = coll.clone();
t.ok( coll2 instanceof OpenLayers.Geometry.Collection, "coll.clone() returns collection object" );
t.eq( coll2.getComponents().length, 2, "coll2.components.length is set correctly");
t.eq( coll2.components.length, 2, "coll2.components.length is set correctly");
t.ok( coll2.components[0] instanceof OpenLayers.Geometry.Point,
"coll2.components.length is set correctly");
}
@@ -95,21 +95,12 @@
coll.addComponents(point);
coll.addComponents(new OpenLayers.Geometry.Point(10,10));
coll.removeComponents(coll.components[0]);
t.eq( coll.getComponents().length, 1, "coll.components.length is smaller after removeComponent" );
t.eq( coll.components.length, 1, "coll.components.length is smaller after removeComponent" );
t.ok( coll.bounds == null, "bounds are nullified after call to remove (to trigger recalc on getBounds()");
bounds = coll.getBounds();
t.eq( bounds.left, 10, "left bound is 10 after removeComponent" );
t.eq( bounds.bottom, 10, "bottom bound is 10 after removeComponent" );
}
function test_05_Collection_getComponents (t) {
t.plan(1);
coll = new OpenLayers.Geometry.Collection();
coll.components = {};
t.eq( coll.getComponents(), coll.components, "getComponents returns great");
}
function test_06_Collection_calculateBounds(t) {
t.plan( 9 );

View File

@@ -18,7 +18,7 @@
t.eq( layer.name, "Test Layer", "layer.name is correct" );
t.ok( layer.id != null, "Layer is given an id");
t.ok( layer.projection, "none", "default layer projection correctly set");
t.eq( layer.projection, "none", "default layer projection correctly set");
t.ok( ((layer.chicken == 151) && (layer.foo == "bar")), "layer.options correctly set to Layer Object" );
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly backed up" );
@@ -39,7 +39,7 @@
}
function test_50_Layer_Image_tileTests (t) {
t.plan(4);
t.plan(9);
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Image('Test Layer',
@@ -49,8 +49,20 @@
map.addLayer(layer);
map.zoomToMaxExtent();
t.eq(layer.tile.position.x,-40, "Tile x positioned correctly at maxextent");
t.eq(layer.tile.position.y,107, "Tile y positioned correctly at maxextent");
t.ok(layer.imageSize, "layer.imageSize is set");
t.ok(layer.tileSize, "layer.tileSize is set");
t.ok(layer.tileSize.equals(layer.imageSize), "tileSize equals imageSize");
// no resolution info was sent, so maxResolution should be calculated
// by aspectRatio*extent/size (this is the pixel aspect ratio)
var aspectRatio = (layer.extent.getHeight() / layer.size.h) /
(layer.extent.getWidth() / layer.size.w);
t.eq(aspectRatio, layer.aspectRatio, "aspectRatio is properly set");
var maxExtent = aspectRatio * layer.extent.getWidth() / layer.size.w;
t.eq(maxExtent, layer.maxResolution, "maxResolution is properly set");
t.eq(layer.tile.position.x,-42, "Tile x positioned correctly at maxextent");
t.eq(layer.tile.position.y,106, "Tile y positioned correctly at maxextent");
t.eq(layer.tile.imgDiv.src, "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", "URL is correct");
map.zoomIn();
t.eq(layer.tile.imgDiv.src, "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", "URL is correct");

View File

@@ -147,7 +147,7 @@
*/
function test_10_Layer_KaMap_clone(t) {
t.plan(4);
t.plan(5);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
@@ -168,6 +168,8 @@
t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
t.eq( clone.CLASS_NAME, "OpenLayers.Layer.KaMap", "Clone is a ka-map layer");
layer.grid = null;
}

View File

@@ -21,8 +21,7 @@
var layer = new OpenLayers.Layer.Vector(name);
var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(layer, point);
var pointFeature = new OpenLayers.Feature.Vector(point);
layer.addFeatures([pointFeature]);
t.eq(layer.features.length, 1, "OpenLayers.Layer.Vector.addFeatures adds something to the array");
@@ -30,7 +29,7 @@
}
function test_03_Layer_Vector_removeFeatures(t) {
t.plan(1);
t.plan(2);
var layer = new OpenLayers.Layer.Vector(name);
@@ -43,6 +42,11 @@
var features = layer.removeFeatures([pointFeature1]);
t.ok(layer.features.length == 1, "OpenLayers.Layer.Vector.removeFeatures removes a feature from the features array");
layer.addFeatures([pointFeature1.clone(), pointFeature2.clone()]);
var features = layer.removeFeatures(layer.features);
t.ok(layer.features.length == 0,
"OpenLayers.Layer.Vector.removeFeatures(layer.features) removes all feature from the features array");
}
function test_Layer_Vector_addStyle (t) {
@@ -55,9 +59,70 @@
layer.addFeatures(f);
t.ok( f.style != null, "Feature style is set by layer.");
}
function test_Layer_Vector_drawFeature(t) {
t.plan(4);
var layer = new OpenLayers.Layer.Vector("Test Layer");
var map = new OpenLayers.Map('map');
map.addLayer(layer);
var geometry = new OpenLayers.Geometry.Point(10, 10);
var feature = new OpenLayers.Feature.Vector(geometry);
var f, s;
layer.renderer = {
drawFeature: function(feature, style) {
f = feature;
s = style;
}
};
layer.drawFeature(feature);
t.ok(geometry.equals(f.geometry),
"calls layer.renderer.drawFeature() with feature.geometry");
feature.style = 'exists';
layer.drawFeature(feature);
t.eq(feature.style, s,
"calls layer.renderer.drawFeature() with feature.style");
feature.style = null;
layer.style = 'exists';
layer.drawFeature(feature);
t.eq(layer.style, s,
"given null feature style, uses layer style");
feature.style = 'exists';
layer.style = 'exists';
var customStyle = 'custom';
layer.drawFeature(feature, customStyle);
t.eq(customStyle, s,
"given a custom style, renders with that");
}
function test_Layer_Vector_eraseFeatures(t) {
t.plan(2);
var layer = new OpenLayers.Layer.Vector("Test Layer");
var map = new OpenLayers.Map('map');
map.addLayer(layer);
var geometry = new OpenLayers.Geometry.Point(10, 10);
var feature = new OpenLayers.Feature.Vector(geometry);
var f;
layer.renderer = {
eraseFeatures: function(features) {
f = features[0];
}
};
layer.eraseFeatures([feature]);
t.ok(f, "calls layer.renderer.eraseFeatures");
t.ok(geometry.equals(f.geometry),
"calls layer.renderer.eraseFeatures() given an array of features");
}
function test_Layer_Vector_destroyFeatures (t) {
t.plan(2);
t.plan(3);
layer = new OpenLayers.Layer.Vector(name);
var map = new OpenLayers.Map('map');
map.addLayer(layer);
@@ -68,8 +133,10 @@
}
layer.addFeatures(features);
t.eq(layer.features.length, 5, "addFeatures adds 5 features");
layer.selectedFeatures.push(features[0]);
layer.destroyFeatures();
t.eq(layer.features.length, 0, "destroyFeatures triggers removal");
t.eq(layer.selectedFeatures, [], "Destroy features removes selected features");
}
function test_99_Layer_Vector_destroy (t) {

37
tests/Layer/test_WFS.html Normal file
View File

@@ -0,0 +1,37 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var name = "Vector Layer";
function test_01_Layer_WFS_constructor(t) {
t.plan(3);
var layer = new OpenLayers.Layer.WFS(name, "url", {});
t.ok(layer instanceof OpenLayers.Layer.WFS, "new OpenLayers.Layer.Vector returns correct object" );
t.eq(layer.name, name, "layer name is correctly set");
t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
}
function test_02_Layer_WFS_mapresizevector(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
map.addLayer(new OpenLayers.Layer.WMS("WMS", "url", {}));
var layer = new OpenLayers.Layer.WFS(name, "url", {});
t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
map.addLayer(layer);
setSize = false;
layer.renderer.setSize = function() { setSize = true; }
layer.onMapResize();
t.eq(setSize, true, "Renderer resize called on map size change.");
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>

362
tests/Marker/test_Box.html Normal file
View File

@@ -0,0 +1,362 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var box;
function test_01_Box_constructor (t) {
t.plan( 7 );
OpenLayers.Marker.Box.prototype._setBorder =
OpenLayers.Marker.Box.prototype.setBorder;
OpenLayers.Marker.Box.prototype.setBorder = function (x,y) {
g_Color = x;
g_Width = y;
};
var bounds = new OpenLayers.Bounds(1,2,3,4);
var borderColor = "blue";
var borderWidth = 55;
g_Color = g_Width = null;
box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
t.ok( box instanceof OpenLayers.Marker.Box, "new OpenLayers.Marker.Box returns Box object" );
t.ok( box.bounds.equals(bounds), "bounds object correctly set");
t.ok( box.div != null, "div created");
t.eq( box.div.style.overflow, "hidden", "div style overflow hidden");
t.ok( box.events != null, "events object created");
t.eq( g_Color, borderColor, "setBorder called with correct border color");
t.eq( g_Width, borderWidth, "setBorder called with correct border width");
OpenLayers.Marker.Box.prototype.setBorder =
OpenLayers.Marker.Box.prototype._setBorder;
}
function test_02_Box_setBorder(t) {
t.plan( 2 );
var box = {
div: {
style: {}
}
};
//defaults
var args = [];
OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
t.eq(box.div.style.border, "2px solid red", "style correctly set with no good values (defaults work)");
//good vals
var borderColor = "blue";
var borderWidth = 55;
args = [borderColor, borderWidth];
OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
t.eq(box.div.style.border, borderWidth + "px solid " + borderColor, "style correctly set with both good values");
}
function test_03_Box_draw(t) {
t.plan( 5 );
OpenLayers.Util._modifyDOMElement =
OpenLayers.Util.modifyDOMElement;
OpenLayers.Util.modifyDOMElement =
function (element, id, px, sz) {
g_Element = element;
g_Id = id;
g_Px = px;
g_Sz = sz;
};
var box = {
div: {}
};
var px = {};
var sz = {};
var args = [px, sz];
g_Element = g_Id = g_Px = g_Sz = null;
var retVal = OpenLayers.Marker.Box.prototype.draw.apply(box, args);
t.eq(g_Element, box.div, "modifyDOMElement passes box's div for element");
t.eq(g_Id, null, "modifyDOMElement passes null for id");
t.eq(g_Px, px, "modifyDOMElement passes new px value for px");
t.eq(g_Sz, sz, "modifyDOMElement passes new sz value for sz");
t.ok(retVal == box.div, "draw returns box's div");
OpenLayers.Util.modifyDOMElement =
OpenLayers.Util._modifyDOMElement;
}
function test_04_Box_onScreen(t) {
t.plan( 2 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url);
map.addLayer(layer);
mlayer = new OpenLayers.Layer.Boxes('Test Layer');
map.addLayer(mlayer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen box
var bounds = new OpenLayers.Bounds(-1,-1,1,1);
var box = new OpenLayers.Marker.Box(bounds);
mlayer.addMarker(box);
t.ok( box.onScreen(), "box knows it's onscreen" );
//offscreen box
var bounds = new OpenLayers.Bounds(100,100,150,150);
var box2 = new OpenLayers.Marker.Box(bounds);
mlayer.addMarker(box2);
t.ok( !box2.onScreen(), "box knows it's offscreen" );
map.destroy();
}
function test_05_Box_display(t) {
t.plan( 2 );
var box = {
div: {
style: {}
}
};
//display(true)
var args = [true];
OpenLayers.Marker.Box.prototype.display.apply(box, args);
t.eq(box.div.style.display, "", "style.display correctly set to '' when display(true)");
//display(false)
var args = [false];
OpenLayers.Marker.Box.prototype.display.apply(box, args);
t.eq(box.div.style.display, "none", "style.display correctly set to 'none' when display(false)");
}
function test_99_Box_destroy(t) {
t.plan(3);
OpenLayers.Marker.prototype._destroy =
OpenLayers.Marker.prototype.destroy;
OpenLayers.Marker.prototype.destroy = function() {
g_Destroy = true;
}
var bounds = new OpenLayers.Bounds(1,2,3,4);
var borderColor = "blue";
var borderWidth = 55;
g_Destroy = null;
box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
box.destroy();
t.eq(box.bounds, null, "bounds nullified");
t.eq(box.div, null, "div nullified");
t.ok(g_Destroy == true, "OpenLayers.Marker.destroy() called");
OpenLayers.Marker.prototype.destroy =
OpenLayers.Marker.prototype._destroy;
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var box;
function test_01_Box_constructor (t) {
t.plan( 7 );
OpenLayers.Marker.Box.prototype._setBorder =
OpenLayers.Marker.Box.prototype.setBorder;
OpenLayers.Marker.Box.prototype.setBorder = function (x,y) {
g_Color = x;
g_Width = y;
};
var bounds = new OpenLayers.Bounds(1,2,3,4);
var borderColor = "blue";
var borderWidth = 55;
g_Color = g_Width = null;
box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
t.ok( box instanceof OpenLayers.Marker.Box, "new OpenLayers.Marker.Box returns Box object" );
t.ok( box.bounds.equals(bounds), "bounds object correctly set");
t.ok( box.div != null, "div created");
t.eq( box.div.style.overflow, "hidden", "div style overflow hidden");
t.ok( box.events != null, "events object created");
t.eq( g_Color, borderColor, "setBorder called with correct border color");
t.eq( g_Width, borderWidth, "setBorder called with correct border width");
OpenLayers.Marker.Box.prototype.setBorder =
OpenLayers.Marker.Box.prototype._setBorder;
}
function test_02_Box_setBorder(t) {
t.plan( 2 );
var box = {
div: {
style: {}
}
};
//defaults
var args = [];
OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
t.eq(box.div.style.border, "2px solid red", "style correctly set with no good values (defaults work)");
//good vals
var borderColor = "blue";
var borderWidth = 55;
args = [borderColor, borderWidth];
OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
t.eq(box.div.style.border, borderWidth + "px solid " + borderColor, "style correctly set with both good values");
}
function test_03_Box_draw(t) {
t.plan( 5 );
OpenLayers.Util._modifyDOMElement =
OpenLayers.Util.modifyDOMElement;
OpenLayers.Util.modifyDOMElement =
function (element, id, px, sz) {
g_Element = element;
g_Id = id;
g_Px = px;
g_Sz = sz;
};
var box = {
div: {}
};
var px = {};
var sz = {};
var args = [px, sz];
g_Element = g_Id = g_Px = g_Sz = null;
var retVal = OpenLayers.Marker.Box.prototype.draw.apply(box, args);
t.eq(g_Element, box.div, "modifyDOMElement passes box's div for element");
t.eq(g_Id, null, "modifyDOMElement passes null for id");
t.eq(g_Px, px, "modifyDOMElement passes new px value for px");
t.eq(g_Sz, sz, "modifyDOMElement passes new sz value for sz");
t.ok(retVal == box.div, "draw returns box's div");
OpenLayers.Util.modifyDOMElement =
OpenLayers.Util._modifyDOMElement;
}
function test_04_Box_onScreen(t) {
t.plan( 2 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url);
map.addLayer(layer);
mlayer = new OpenLayers.Layer.Boxes('Test Layer');
map.addLayer(mlayer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen box
var bounds = new OpenLayers.Bounds(-1,-1,1,1);
var box = new OpenLayers.Marker.Box(bounds);
mlayer.addMarker(box);
t.ok( box.onScreen(), "box knows it's onscreen" );
//offscreen box
var bounds = new OpenLayers.Bounds(100,100,150,150);
var box2 = new OpenLayers.Marker.Box(bounds);
mlayer.addMarker(box2);
t.ok( !box2.onScreen(), "box knows it's offscreen" );
map.destroy();
}
function test_05_Box_display(t) {
t.plan( 2 );
var box = {
div: {
style: {}
}
};
//display(true)
var args = [true];
OpenLayers.Marker.Box.prototype.display.apply(box, args);
t.eq(box.div.style.display, "", "style.display correctly set to '' when display(true)");
//display(false)
var args = [false];
OpenLayers.Marker.Box.prototype.display.apply(box, args);
t.eq(box.div.style.display, "none", "style.display correctly set to 'none' when display(false)");
}
function test_99_Box_destroy(t) {
t.plan(3);
OpenLayers.Marker.prototype._destroy =
OpenLayers.Marker.prototype.destroy;
OpenLayers.Marker.prototype.destroy = function() {
g_Destroy = true;
}
var bounds = new OpenLayers.Bounds(1,2,3,4);
var borderColor = "blue";
var borderWidth = 55;
g_Destroy = null;
box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
box.destroy();
t.eq(box.bounds, null, "bounds nullified");
t.eq(box.div, null, "div nullified");
t.ok(g_Destroy == true, "OpenLayers.Marker.destroy() called");
OpenLayers.Marker.prototype.destroy =
OpenLayers.Marker.prototype._destroy;
}
// -->
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>

View File

@@ -20,6 +20,7 @@
<li>Format/test_WKT.html</li>
<li>test_Icon.html</li>
<li>test_Marker.html</li>
<li>Marker/test_Box.html</li>
<li>test_Popup.html</li>
<li>test_Feature.html</li>
<li>Feature/test_Vector.html</li>
@@ -41,6 +42,7 @@
<li>Layer/test_MapServer_Untiled.html</li>
<li>Layer/test_Text.html</li>
<li>Layer/test_WMS.html</li>
<li>Layer/test_WFS.html</li>
<li>Layer/test_TMS.html</li>
<li>Layer/test_Vector.html</li>
<li>Layer/test_GML.html</li>

View File

@@ -178,11 +178,10 @@
}
function test_99_Geometry_destroy(t) {
t.plan( 3 );
t.plan( 2 );
var g = new OpenLayers.Geometry();
g.bounds = new OpenLayers.Bounds();
g.feature = new Object();
g_style_destroy = null;
g.destroy();
@@ -190,7 +189,6 @@
t.eq(g.id, null, "id nullified");
t.eq(g.bounds, null, "bounds nullified");
t.eq(g.feature, null, "feature reference nullified");
}

View File

@@ -118,7 +118,7 @@
function test_05_Layer_visibility(t) {
t.plan(3)
t.plan(5)
var layer = new OpenLayers.Layer('Test Layer');
@@ -129,6 +129,22 @@
layer.setVisibility(true);
t.eq(layer.getVisibility(), true, "setVisibility true works");
// Need a map in order to have moveTo called.
// Tests added for #654.
var layer = new OpenLayers.Layer.WMS('Test Layer','http://example.com');
var m = new OpenLayers.Map('map');
m.addLayer(layer);
m.zoomToMaxExtent();
layermoved = false;
layer.moveTo = function() { layermoved = true; }
layer.setVisibility(false);
t.eq(layermoved, false, "Layer didn't move when calling setvis false");
layer.setVisibility(true);
t.eq(layermoved, true, "Layer moved when calling setvis true.");
}