more cleanup of tests. adding ';' to end of function definition and other minor coding style mods. tests still pass in IE6/FF.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4153 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-08-31 12:31:43 +00:00
parent 0c108138e8
commit a8d7097e67
5 changed files with 73 additions and 64 deletions
+52 -35
View File
@@ -2,8 +2,10 @@
<head> <head>
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var map; var map;
function test_01_Map_constructor (t) { function test_01_Map_constructor (t) {
t.plan( 9 ); t.plan( 9 );
@@ -28,7 +30,8 @@
t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" ); t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );
t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" ); t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
t.ok( map.getNumZoomLevels() > 0, "map has a default numZoomLevels" ); t.ok( map.getNumZoomLevels() > 0, "map has a default numZoomLevels" );
} };
function test_02_Map_center(t) { function test_02_Map_center(t) {
t.plan(3); t.plan(3);
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
@@ -41,7 +44,8 @@
t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat"); t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat");
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter"); t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter");
t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter"); t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter");
} };
function test_03_Map_add_layers(t) { function test_03_Map_add_layers(t) {
t.plan(6); t.plan(6);
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
@@ -60,14 +64,16 @@
"layer1 zIndex is set" ); "layer1 zIndex is set" );
t.eq( parseInt(layer2.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 5, t.eq( parseInt(layer2.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 5,
"layer2 zIndex is set" ); "layer2 zIndex is set" );
} };
function test_04_Map_options(t) { function test_04_Map_options(t) {
t.plan(3); t.plan(3);
map = new OpenLayers.Map('map', {numZoomLevels: 6, maxResolution: 3.14159, theme: 'foo'}); map = new OpenLayers.Map('map', {numZoomLevels: 6, maxResolution: 3.14159, theme: 'foo'});
t.eq( map.numZoomLevels, 6, "map.numZoomLevels set correctly via options hashtable" ); t.eq( map.numZoomLevels, 6, "map.numZoomLevels set correctly via options hashtable" );
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" ); t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" );
t.eq( map.theme, 'foo', "map theme set correctly." ); t.eq( map.theme, 'foo', "map theme set correctly." );
} };
function test_05_Map_center(t) { function test_05_Map_center(t) {
t.plan(4); t.plan(4);
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
@@ -83,20 +89,22 @@
map.zoomOut(); map.zoomOut();
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out"); t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
map.zoomTo(5); map.zoomTo(5);
t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" ); t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" );
/**
map.zoomToMaxExtent();
t.eq( map.getZoom(), 2, "map.zoom is correct after calling zoomToMaxExtent" );
var lonlat = map.getCenter();
var zero = new OpenLayers.LonLat(0, 0);
t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" );
/**
map.zoomToMaxExtent();
t.eq( map.getZoom(), 2, "map.zoom is correct after calling zoomToMaxExtent" );
var lonlat = map.getCenter();
var zero = new OpenLayers.LonLat(0, 0);
t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" );
*/ */
}
};
function test_06_Map_zoomend_event (t) { function test_06_Map_zoomend_event (t) {
t.plan(2); t.plan(2);
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?", "http://octo.metacarta.com/cgi-bin/mapserv?",
@@ -109,8 +117,8 @@
map.setCenter(new OpenLayers.LonLat(2, 1), 0); map.setCenter(new OpenLayers.LonLat(2, 1), 0);
map.zoomIn(); map.zoomIn();
map.zoomOut(); map.zoomOut();
} };
function test_07_Map_add_remove_popup (t) { function test_07_Map_add_remove_popup (t) {
t.plan(4); t.plan(4);
@@ -153,7 +161,8 @@
} }
} }
t.ok(!found, "popup.div successfully removed from the map's viewPort"); t.ok(!found, "popup.div successfully removed from the map's viewPort");
} };
/*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS. /*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS.
* Also, it won't work until we figure out the viewSize bug * Also, it won't work until we figure out the viewSize bug
@@ -186,10 +195,12 @@
t.ok( newPixel instanceof OpenLayers.Pixel, "getPixelFromLonLat returns valid OpenLayers.Pixel" ); t.ok( newPixel instanceof OpenLayers.Pixel, "getPixelFromLonLat returns valid OpenLayers.Pixel" );
t.ok( newPixel.equals(pixel), "2nd translation to pixel and back to lonlat is consistent"); t.ok( newPixel.equals(pixel), "2nd translation to pixel and back to lonlat is consistent");
} };
*/ */
function test_09_Map_isValidLonLat(t) { function test_09_Map_isValidLonLat(t) {
t.plan( 3 ); t.plan( 3 );
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS('Test Layer', layer = new OpenLayers.Layer.WMS('Test Layer',
"http://octo.metacarta.com/cgi-bin/mapserv", "http://octo.metacarta.com/cgi-bin/mapserv",
@@ -200,10 +211,11 @@
t.ok( !map.isValidLonLat(null), "null lonlat is not valid" ); t.ok( !map.isValidLonLat(null), "null lonlat is not valid" );
t.ok( map.isValidLonLat(new OpenLayers.LonLat(33862, 717606)), "lonlat outside max extent is valid" ); t.ok( map.isValidLonLat(new OpenLayers.LonLat(33862, 717606)), "lonlat outside max extent is valid" );
t.ok( !map.isValidLonLat(new OpenLayers.LonLat(10, 10)), "lonlat outside max extent is not valid" ); t.ok( !map.isValidLonLat(new OpenLayers.LonLat(10, 10)), "lonlat outside max extent is not valid" );
} };
function test_10_Map_getLayer(t) { function test_10_Map_getLayer(t) {
t.plan( 2 ); t.plan( 2 );
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS('Test Layer', layer = new OpenLayers.Layer.WMS('Test Layer',
"http://octo.metacarta.com/cgi-bin/mapserv", "http://octo.metacarta.com/cgi-bin/mapserv",
@@ -218,10 +230,11 @@
gotLayer = map.getLayer("chicken"); gotLayer = map.getLayer("chicken");
t.ok( gotLayer == null, "getLayer correctly returns null when layer not found"); t.ok( gotLayer == null, "getLayer correctly returns null when layer not found");
} };
function test_11_Map_double_addLayer(t) { function test_11_Map_double_addLayer(t) {
t.plan( 1 ); t.plan( 1 );
map = new OpenLayers.Map($('map')); map = new OpenLayers.Map($('map'));
layer = new OpenLayers.Layer.WMS('Test Layer', layer = new OpenLayers.Layer.WMS('Test Layer',
"http://octo.metacarta.com/cgi-bin/mapserv", "http://octo.metacarta.com/cgi-bin/mapserv",
@@ -232,7 +245,7 @@
t.eq( map.layers.length, 1, "Map does not allow double adding of layers." ); t.eq( map.layers.length, 1, "Map does not allow double adding of layers." );
} };
function test_12_Map_setBaseLayer(t) { function test_12_Map_setBaseLayer(t) {
t.plan( 4 ); t.plan( 4 );
@@ -261,10 +274,11 @@
map.setBaseLayer(wmslayer2); map.setBaseLayer(wmslayer2);
t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property"); t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property");
} };
function test_13_Map_setBaseLayer_after_pan (t) { function test_13_Map_setBaseLayer_after_pan (t) {
t.plan(1); t.plan(1);
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
@@ -279,10 +293,11 @@
map.pan(0, -200); map.pan(0, -200);
map.setBaseLayer(wmsLayer); map.setBaseLayer(wmsLayer);
t.eq(map.layerContainerDiv.style.top, "0px", "layerContainer is recentered after setBaseLayer"); t.eq(map.layerContainerDiv.style.top, "0px", "layerContainer is recentered after setBaseLayer");
} };
function test_14_Map_moveLayer (t) { function test_14_Map_moveLayer (t) {
t.plan(10); t.plan(10);
var ct = 0; var ct = 0;
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
var wmslayer = new OpenLayers.Layer.WMS('Test Layer', var wmslayer = new OpenLayers.Layer.WMS('Test Layer',
@@ -318,10 +333,11 @@
"layer div has the right zIndex after moving up" ); "layer div has the right zIndex after moving up" );
t.eq( map.getLayerIndex(wmslayer3), 0, "top layer is now on the bottom" ); t.eq( map.getLayerIndex(wmslayer3), 0, "top layer is now on the bottom" );
t.eq( ct, 3, "raiseLayer triggered changelayer the right # of times" ); t.eq( ct, 3, "raiseLayer triggered changelayer the right # of times" );
} };
function test_15_Map_setCenter(t) { function test_15_Map_setCenter(t) {
t.plan(1); t.plan(1);
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?", "http://octo.metacarta.com/cgi-bin/mapserv?",
@@ -331,9 +347,8 @@
var ll = new OpenLayers.LonLat(-100,-150); var ll = new OpenLayers.LonLat(-100,-150);
map.setCenter(ll, 0); map.setCenter(ll, 0);
t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat"); t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat");
} };
function test_16_Map_defaultTheme(t) { function test_16_Map_defaultTheme(t) {
t.plan(5); t.plan(5);
@@ -356,7 +371,8 @@
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
t.eq(links.length, document.getElementsByTagName('link').length, t.eq(links.length, document.getElementsByTagName('link').length,
"calling the map constructor twice with the same theme doesn't add duplicate link nodes"); "calling the map constructor twice with the same theme doesn't add duplicate link nodes");
} };
function test_17_Map_customTheme(t) { function test_17_Map_customTheme(t) {
t.plan(5); t.plan(5);
@@ -379,7 +395,8 @@
t.ok(themeNode != null, "a link node with the theme href was added"); t.ok(themeNode != null, "a link node with the theme href was added");
t.eq(themeNode.rel, "stylesheet", "node added has rel set to stylesheet"); t.eq(themeNode.rel, "stylesheet", "node added has rel set to stylesheet");
t.eq(themeNode.type, "text/css", "node added has type set to text/css"); t.eq(themeNode.type, "text/css", "node added has type set to text/css");
} };
function test_18_Map_noTheme(t) { function test_18_Map_noTheme(t) {
t.plan(1); t.plan(1);
@@ -390,8 +407,8 @@
map = new OpenLayers.Map('map', options); map = new OpenLayers.Map('map', options);
t.eq(nodeCount, head.childNodes.length, "with no theme, a node is not added to document head" ); t.eq(nodeCount, head.childNodes.length, "with no theme, a node is not added to document head" );
} };
function test_19_Map_getControl(t) { function test_19_Map_getControl(t) {
t.plan(2); t.plan(2);
@@ -405,7 +422,7 @@
gotControl = map1.getControl("bogus id"); gotControl = map1.getControl("bogus id");
t.ok(gotControl == null, "getControl() for bad id returns null"); t.ok(gotControl == null, "getControl() for bad id returns null");
} };
function test_19_Map_removeControl(t) { function test_19_Map_removeControl(t) {
t.plan(6); t.plan(6);
@@ -453,7 +470,7 @@
map1.removeControl(control); map1.removeControl(control);
newNumControls = map1.controls.length; newNumControls = map1.controls.length;
t.ok( newNumControls == oldNumControls, "removing bad controlid doesnt crash or decrease control count") t.ok( newNumControls == oldNumControls, "removing bad controlid doesnt crash or decrease control count")
} };
function test_99_Map_destroy (t) { function test_99_Map_destroy (t) {
t.plan( 3 ); t.plan( 3 );
@@ -462,7 +479,7 @@
t.eq( map.layers, null, "map.layers is null after destroy" ); t.eq( map.layers, null, "map.layers is null after destroy" );
t.eq( map.controls, null, "map.controls is null after destroy" ); t.eq( map.controls, null, "map.controls is null after destroy" );
t.eq( map.viewPortDiv, null, "map's viewportDiv nullified"); t.eq( map.viewPortDiv, null, "map's viewportDiv nullified");
} };
</script> </script>
</head> </head>
+8 -8
View File
@@ -2,8 +2,9 @@
<head> <head>
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var marker;
var marker;
function test_01_Marker_constructor (t) { function test_01_Marker_constructor (t) {
t.plan( 4 ); t.plan( 4 );
var ll = new OpenLayers.LonLat(2,1); var ll = new OpenLayers.LonLat(2,1);
@@ -12,7 +13,7 @@
t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" ); t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" );
t.ok( marker.lonlat instanceof OpenLayers.LonLat, "new marker.lonlat returns LonLat object" ); t.ok( marker.lonlat instanceof OpenLayers.LonLat, "new marker.lonlat returns LonLat object" );
t.ok( marker.lonlat.equals(ll), "marker.lonlat returns correct" ); t.ok( marker.lonlat.equals(ll), "marker.lonlat returns correct" );
} };
function test_02_Marker_onScreen(t) { function test_02_Marker_onScreen(t) {
t.plan( 2 ); t.plan( 2 );
@@ -43,7 +44,7 @@
t.ok( !marker2.onScreen(), "marker knows it's offscreen" ); t.ok( !marker2.onScreen(), "marker knows it's offscreen" );
map.destroy(); map.destroy();
} };
function test_03_Marker_setOpacity(t) { function test_03_Marker_setOpacity(t) {
t.plan( 2 ); t.plan( 2 );
@@ -71,7 +72,8 @@
t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works"); t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works");
map.destroy(); map.destroy();
} };
function test_04_Marker_moveTo(t) { function test_04_Marker_moveTo(t) {
t.plan( 6 ); t.plan( 6 );
@@ -103,9 +105,7 @@
t.eq(marker.lonlat.lon, map.getExtent().left, "on left edge of map"); t.eq(marker.lonlat.lon, map.getExtent().left, "on left edge of map");
t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map"); t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map");
map.destroy(); map.destroy();
};
}
</script> </script>
</head> </head>
+6 -11
View File
@@ -2,8 +2,9 @@
<head> <head>
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var popup;
var popup;
function test_01_Popup_default_constructor(t) { function test_01_Popup_default_constructor(t) {
t.plan( 8 ); t.plan( 8 );
@@ -24,7 +25,7 @@
popup = new OpenLayers.Popup(); popup = new OpenLayers.Popup();
var newID = popup.id; var newID = popup.id;
t.ok(newID != firstID, "default id generator creating unique ids"); t.ok(newID != firstID, "default id generator creating unique ids");
} };
function test_02_Popup_constructor (t) { function test_02_Popup_constructor (t) {
t.plan( 5 ); t.plan( 5 );
@@ -48,10 +49,9 @@
t.ok(popup.lonlat.equals(ll), "popup.lonlat set correctly"); t.ok(popup.lonlat.equals(ll), "popup.lonlat set correctly");
t.ok(popup.size.equals(sz), "popup.size set correctly"); t.ok(popup.size.equals(sz), "popup.size set correctly");
t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly"); t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly");
} };
function test_03_Popup_draw(t) { function test_03_Popup_draw(t) {
t.plan( 17 ); t.plan( 17 );
var id = "chicken"; var id = "chicken";
@@ -65,7 +65,6 @@
var opacity = 0.5; var opacity = 0.5;
var border = "1px solid"; var border = "1px solid";
popup = new OpenLayers.Popup(id); popup = new OpenLayers.Popup(id);
popup.setSize(new OpenLayers.Size(w, h)); popup.setSize(new OpenLayers.Size(w, h));
popup.setContentHTML(content); popup.setContentHTML(content);
@@ -105,11 +104,7 @@
popup.moveTo(new OpenLayers.Pixel(x, y)); popup.moveTo(new OpenLayers.Pixel(x, y));
t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly"); t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly");
t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly"); t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly");
};
}
</script> </script>
</head> </head>
+4 -4
View File
@@ -3,14 +3,14 @@
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var layer; var layer;
function test_01_Renderer_drawGeometry(t) { function test_01_Renderer_drawGeometry(t) {
t.plan(1); t.plan(1);
var r = new OpenLayers.Renderer(); var r = new OpenLayers.Renderer();
t.ok( r instanceof OpenLayers.Renderer, "new OpenLayers.Renderer returns REnderer object" ); t.ok( r instanceof OpenLayers.Renderer, "new OpenLayers.Renderer returns REnderer object" );
} };
/* /*
function test_01_Renderer_drawGeometry(t) { function test_01_Renderer_drawGeometry(t) {
t.plan(12); t.plan(12);
@@ -155,7 +155,7 @@ function test_01_Renderer_drawGeometry(t) {
r.drawGeometry(geometry, style); r.drawGeometry(geometry, style);
t.ok(properDraw, "drawGeometry called drawPolygon when passed a multi-polygon"); t.ok(properDraw, "drawGeometry called drawPolygon when passed a multi-polygon");
} };
*/ */
</script> </script>
+3 -6
View File
@@ -25,12 +25,11 @@
t.ok( tile.id != null, "tile is given an id"); t.ok( tile.id != null, "tile is given an id");
t.ok( tile.id.startsWith("Tile_"), "tile's id starts correctly"); t.ok( tile.id.startsWith("Tile_"), "tile's id starts correctly");
t.ok( tile.events != null, "tile's events intitialized"); t.ok( tile.events != null, "tile's events intitialized");
} };
function test_99_Tile_destroy(t) { function test_99_Tile_destroy(t) {
t.plan( 6 ); t.plan( 6 );
var layer = {}; // bogus layer var layer = {}; // bogus layer
var position = new OpenLayers.Pixel(10,20); var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4); var bounds = new OpenLayers.Bounds(1,2,3,4);
@@ -51,9 +50,7 @@
t.ok(tile.position == null, "tile.position set to null"); t.ok(tile.position == null, "tile.position set to null");
t.ok(tile.events == null, "tile.events set to null"); t.ok(tile.events == null, "tile.events set to null");
} };
</script> </script>
</head> </head>