Zoom control tests.

This commit is contained in:
Tim Schaub
2012-03-02 22:52:18 -07:00
parent 45b9c48c43
commit f45043967b
3 changed files with 77 additions and 2 deletions

View File

@@ -126,11 +126,11 @@ OpenLayers.Control.Zoom = OpenLayers.Class(OpenLayers.Control, {
*/
destroy: function() {
if (this.zoomInLink) {
delete this.zoomInLink.onclick;
this.zoomInLink.onclick = null;
delete this.zoomInLink;
}
if (this.zoomOutLink) {
delete this.zoomOutLink.onclick;
this.zoomOutLink.onclick = null;
delete this.zoomOutLink;
}
OpenLayers.Control.prototype.destroy.apply(this);

74
tests/Control/Zoom.html Normal file
View File

@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
function test_constructor(t) {
t.plan(5);
var control = new OpenLayers.Control.Zoom();
t.ok(control instanceof OpenLayers.Control, "instance of Control");
t.ok(control instanceof OpenLayers.Control.Zoom, "instance of Zoom");
t.eq(control.displayClass, "olControlZoom", "displayClass");
control.destroy();
control = new OpenLayers.Control.Zoom({
zoomInText: "zoom in!",
zoomOutText: "zoom out!"
});
t.eq(control.zoomInText, "zoom in!", "zoomInText");
t.eq(control.zoomOutText, "zoom out!", "zoomOutText");
control.destroy();
}
function test_addControl(t) {
t.plan(2);
var map = new OpenLayers.Map("map");
var control = new OpenLayers.Control.Zoom();
map.addControl(control);
t.ok(control.map === map, "Control.map set");
t.ok(!!~OpenLayers.Util.indexOf(map.controls, control), "map.controls contains control");
map.destroy();
}
function test_zoomIn(t) {
t.plan(2);
var map = new OpenLayers.Map({
div: "map",
layers: [new OpenLayers.Layer(null, {isBaseLayer: true})]
});
var control = new OpenLayers.Control.Zoom();
map.addControl(control);
map.setCenter([0, 0], 0);
t.eq(map.getZoom(), 0, "initial center");
control.zoomInLink.onclick();
t.eq(map.getZoom(), 1, "after zoom in");
map.destroy();
}
function test_zoomOut(t) {
t.plan(2);
var map = new OpenLayers.Map({
div: "map",
layers: [new OpenLayers.Layer(null, {isBaseLayer: true})]
});
var control = new OpenLayers.Control.Zoom();
map.addControl(control);
map.setCenter([0, 0], 1);
t.eq(map.getZoom(), 1, "initial center");
control.zoomOutLink.onclick();
t.eq(map.getZoom(), 0, "after zoom out");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 512px; height: 256px;"/>
</body>
</html>

View File

@@ -45,6 +45,7 @@
<li>Control/WMTSGetFeatureInfo.html</li>
<li>Control/PanPanel.html</li>
<li>Control/SLDSelect.html</li>
<li>Control/Zoom.html</li>
<li>Events.html</li>
<li>Events/buttonclick.html</li>
<li>Extras.html</li>