conditionally run Google tests based on protocol and host - print debug statements if key is not valid - this means that tests do not fail with an invalid key

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4060 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-08-27 18:27:23 +00:00
parent e4d857b167
commit b133435e06
3 changed files with 156 additions and 103 deletions
+106 -74
View File
@@ -5,96 +5,128 @@
<script src="../../lib/OpenLayers.js"></script> <script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var layer; var layer;
var validkey = (window.location.protocol == "file:") ||
(window.location.host == "localhost") ||
(window.location.host == "openlayers.org");
function test_01_Layer_Google_constructor (t) { function test_01_Layer_Google_constructor (t) {
t.plan( 4 ); if(validkey) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google('Goog Layer'); var map = new OpenLayers.Map('map');
map.addLayer(layer); var layer = new OpenLayers.Layer.Google('Goog Layer');
map.addLayer(layer);
t.ok( layer instanceof OpenLayers.Layer.Google, "new OpenLayers.Layer.Google returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Google", "CLASS_NAME variable set correctly"); t.ok( layer instanceof OpenLayers.Layer.Google, "new OpenLayers.Layer.Google returns object" );
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Google", "CLASS_NAME variable set correctly");
t.eq( layer.name, "Goog Layer", "layer.name is correct" );
t.eq( layer.name, "Goog Layer", "layer.name is correct" );
t.ok ( layer.mapObject != null, "GMap2 Object correctly loaded");
t.ok ( layer.mapObject != null, "GMap2 Object correctly loaded");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
} }
function test_02_Layer_Google_isBaseLayer (t) { function test_02_Layer_Google_isBaseLayer (t) {
t.plan(1); if(validkey) {
t.plan(1);
var layer = new OpenLayers.Layer.Google('Goog Layer');
var layer = new OpenLayers.Layer.Google('Goog Layer');
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
} }
function test_03_Layer_Google_Translation_lonlat (t) { function test_03_Layer_Google_Translation_lonlat (t) {
t.plan( 4 ); if(validkey) {
t.plan( 4 );
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google('Goog Layer'); var map = new OpenLayers.Map('map');
map.addLayer(layer); var layer = new OpenLayers.Layer.Google('Goog Layer');
map.addLayer(layer);
// these two lines specify an appropriate translation. // these two lines specify an appropriate translation.
// the code afterwards works by itself to test that translation // the code afterwards works by itself to test that translation
// works correctly both ways. // works correctly both ways.
var gLatLng = new GLatLng(50,100); var gLatLng = new GLatLng(50,100);
var correspondingOLLonLat = new OpenLayers.LonLat(100,50); var correspondingOLLonLat = new OpenLayers.LonLat(100,50);
olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng); olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng);
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works"); t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat); var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat);
t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works"); t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works");
t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null"); t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null"); t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
} }
function test_04_Layer_Google_Translation_pixel (t) { function test_04_Layer_Google_Translation_pixel (t) {
if(validkey) {
t.plan( 4 ); t.plan( 4 );
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.Google('Goog Layer'); var layer = new OpenLayers.Layer.Google('Goog Layer');
map.addLayer(layer); map.addLayer(layer);
// these two lines specify an appropriate translation. // these two lines specify an appropriate translation.
// the code afterwards works by itself to test that translation // the code afterwards works by itself to test that translation
// works correctly both ways. // works correctly both ways.
var gPoint = new GPoint(50,100); var gPoint = new GPoint(50,100);
var correspondingOLPixel = new OpenLayers.Pixel(50, 100); var correspondingOLPixel = new OpenLayers.Pixel(50, 100);
olPixel = layer.getOLPixelFromMapObjectPixel(gPoint); olPixel = layer.getOLPixelFromMapObjectPixel(gPoint);
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works"); t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel); var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel);
t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works"); t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works");
t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null"); t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null"); t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null");
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
} }
function test_99_Layer_destroy (t) { function test_99_Layer_destroy (t) {
t.plan( 5 ); if(validkey) {
t.plan( 5 );
var map = new OpenLayers.Map('map');
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Google('Test Layer');
map.addLayer(layer); layer = new OpenLayers.Layer.Google('Test Layer');
map.addLayer(layer);
layer.destroy();
layer.destroy();
t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.div, null, "layer.div is null after destroy" ); t.eq( layer.name, null, "layer.name is null after destroy" );
t.eq( layer.map, null, "layer.map is null after destroy" ); t.eq( layer.div, null, "layer.div is null after destroy" );
t.eq( layer.options, null, "layer.options is null after destroy" ); t.eq( layer.map, null, "layer.map is null after destroy" );
t.eq( layer.gmap, null, "layer.gmap is null after destroy" ); t.eq( layer.options, null, "layer.options is null after destroy" );
t.eq( layer.gmap, null, "layer.gmap is null after destroy" );
} else {
t.plan(0);
t.debug_print("Google tests can't be run from " +
window.location.host);
}
} }
</script> </script>
+23 -13
View File
@@ -199,19 +199,29 @@
} }
function test_20_Layer_MapServer_Reproject (t) { function test_20_Layer_MapServer_Reproject (t) {
t.plan(5); var validkey = (window.location.protocol == "file:") ||
var map = new OpenLayers.Map('map'); (window.location.host == "localhost") ||
var layer = new OpenLayers.Layer.Google("Google"); (window.location.host == "openlayers.org");
map.addLayer(layer);
layer = new OpenLayers.Layer.MapServer(name, url, params, {isBaseLayer: false, reproject: true}); if(validkey) {
layer.isBaseLayer=false; t.plan(5);
map.addLayer(layer); var map = new OpenLayers.Map('map');
map.setCenter(new OpenLayers.LonLat(0,0), 5); var layer = new OpenLayers.Layer.Google("Google");
var tile = layer.grid[0][0]; map.addLayer(layer);
t.eq( tile.bounds.left, -22.5, "left side matches" ); layer = new OpenLayers.Layer.MapServer(name, url, params, {isBaseLayer: false, reproject: true});
t.eq( tile.bounds.right, -11.25, "top side matches" ); layer.isBaseLayer=false;
t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" ); map.addLayer(layer);
t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" ); map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = layer.grid[0][0];
t.eq( tile.bounds.left, -22.5, "left side matches" );
t.eq( tile.bounds.right, -11.25, "top side matches" );
t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" );
t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" );
} else {
t.plan(1);
t.debug_print("can't test google layer from " +
window.location.host);
}
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.MapServer(name, url, params); layer = new OpenLayers.Layer.MapServer(name, url, params);
+27 -16
View File
@@ -270,23 +270,34 @@
map.destroy(); map.destroy();
} }
function test_20_Layer_WMS_Reproject (t) { function test_20_Layer_WMS_Reproject (t) {
t.plan(5); var validkey = (window.location.protocol == "file:") ||
(window.location.host == "localhost") ||
var map = new OpenLayers.Map('map'); (window.location.host == "openlayers.org");
var layer = new OpenLayers.Layer.Google("Google");
map.addLayer(layer);
wmslayer = new OpenLayers.Layer.WMS(name, url, params, {isBaseLayer: false});
wmslayer.isBaseLayer=false;
map.addLayer(wmslayer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = wmslayer.grid[0][0]; if(validkey) {
t.eq( tile.bounds.left, -22.5, "left side matches" ); t.plan(5);
t.eq( tile.bounds.right, -11.25, "top side matches" );
t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" ); var map = new OpenLayers.Map('map');
t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" ); var layer = new OpenLayers.Layer.Google("Google");
map.destroy(); map.addLayer(layer);
var wmslayer = new OpenLayers.Layer.WMS(name, url, params,
{isBaseLayer: false});
wmslayer.isBaseLayer=false;
map.addLayer(wmslayer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = wmslayer.grid[0][0];
t.eq( tile.bounds.left, -22.5, "left side matches" );
t.eq( tile.bounds.right, -11.25, "top side matches" );
t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" );
t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" );
map.destroy();
} else {
t.plan(1);
t.debug_print("can't test google layer from " +
window.location.host);
}
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(name, url, params); layer = new OpenLayers.Layer.WMS(name, url, params);