| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
|
|---|
| 6 |
function test_initialize(t) { |
|---|
| 7 |
t.plan(1); |
|---|
| 8 |
|
|---|
| 9 |
var ratio = 4; |
|---|
| 10 |
|
|---|
| 11 |
var s = new OpenLayers.Strategy.BBOX({ratio: ratio}); |
|---|
| 12 |
t.eq(s.ratio, ratio, "ctor sets ratio"); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
function test_activate(t) { |
|---|
| 16 |
t.plan(5); |
|---|
| 17 |
|
|---|
| 18 |
var l = new OpenLayers.Layer.Vector(); |
|---|
| 19 |
var s = new OpenLayers.Strategy.BBOX(); |
|---|
| 20 |
s.setLayer(l); |
|---|
| 21 |
|
|---|
| 22 |
t.eq(s.active, false, "not active after construction"); |
|---|
| 23 |
|
|---|
| 24 |
var activated = s.activate(); |
|---|
| 25 |
t.eq(activated, true, "activate returns true"); |
|---|
| 26 |
t.eq(s.active, true, "activated after activate"); |
|---|
| 27 |
t.ok(l.events.listeners["moveend"][0].obj == s && |
|---|
| 28 |
l.events.listeners["moveend"][0].func == s.update, |
|---|
| 29 |
"activates registers moveend listener"); |
|---|
| 30 |
t.ok(l.events.listeners["refresh"][0].obj == s && |
|---|
| 31 |
l.events.listeners["refresh"][0].func == s.update, |
|---|
| 32 |
"activates registers refresh listener"); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
function test_update(t) { |
|---|
| 36 |
t.plan(6); |
|---|
| 37 |
|
|---|
| 38 |
var s = new OpenLayers.Strategy.BBOX(); |
|---|
| 39 |
|
|---|
| 40 |
var invalidBoundsReturnValue; |
|---|
| 41 |
var bounds = new OpenLayers.Bounds(-100, -40, 100, 40); |
|---|
| 42 |
|
|---|
| 43 |
s.invalidBounds = function(b) { |
|---|
| 44 |
t.ok(b == bounds, |
|---|
| 45 |
"update calls invalidBounds with correct arg"); |
|---|
| 46 |
return invalidBoundsReturnValue; |
|---|
| 47 |
}; |
|---|
| 48 |
s.calculateBounds = function(b) { |
|---|
| 49 |
t.ok(b == bounds, |
|---|
| 50 |
"update calls calculateBounds with correct arg"); |
|---|
| 51 |
}; |
|---|
| 52 |
s.triggerRead = function() { |
|---|
| 53 |
t.ok(true, |
|---|
| 54 |
"update calls triggerRead"); |
|---|
| 55 |
}; |
|---|
| 56 |
|
|---|
| 57 |
s.setLayer({ |
|---|
| 58 |
map: { |
|---|
| 59 |
getExtent: function() { |
|---|
| 60 |
return bounds; |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
}); |
|---|
| 64 |
|
|---|
| 65 |
// 2 tests |
|---|
| 66 |
invalidBoundsReturnValue = true; |
|---|
| 67 |
s.update({force: true}); |
|---|
| 68 |
|
|---|
| 69 |
// 3 tests |
|---|
| 70 |
invalidBoundsReturnValue = true; |
|---|
| 71 |
s.update(); |
|---|
| 72 |
|
|---|
| 73 |
// 1 tests |
|---|
| 74 |
invalidBoundsReturnValue = false; |
|---|
| 75 |
s.update(); |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
function test_triggerRead(t) { |
|---|
| 79 |
t.plan(4); |
|---|
| 80 |
|
|---|
| 81 |
var s = new OpenLayers.Strategy.BBOX(); |
|---|
| 82 |
|
|---|
| 83 |
var filter = {"fake": "filter"}; |
|---|
| 84 |
|
|---|
| 85 |
s.createFilter = function() { |
|---|
| 86 |
return filter; |
|---|
| 87 |
}; |
|---|
| 88 |
s.response = {"fake": "response"}; |
|---|
| 89 |
|
|---|
| 90 |
var protocol = new OpenLayers.Protocol({ |
|---|
| 91 |
read: function(options) { |
|---|
| 92 |
t.ok(options.filter == filter, |
|---|
| 93 |
"protocol read called with correct filter"); |
|---|
| 94 |
t.ok(options.callback == s.merge, |
|---|
| 95 |
"protocol read called with correct callback"); |
|---|
| 96 |
t.ok(options.scope == s, |
|---|
| 97 |
"protocol read called with correct scope"); |
|---|
| 98 |
}, |
|---|
| 99 |
abort: function(response) { |
|---|
| 100 |
t.eq(response, s.response, |
|---|
| 101 |
"protocol abort called with correct response"); |
|---|
| 102 |
} |
|---|
| 103 |
}); |
|---|
| 104 |
|
|---|
| 105 |
s.setLayer({protocol: protocol}); |
|---|
| 106 |
|
|---|
| 107 |
// 4 tests |
|---|
| 108 |
s.triggerRead(); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
function test_createFilter(t) { |
|---|
| 112 |
t.plan(3); |
|---|
| 113 |
|
|---|
| 114 |
var s = new OpenLayers.Strategy.BBOX(); |
|---|
| 115 |
|
|---|
| 116 |
var f; |
|---|
| 117 |
|
|---|
| 118 |
// 2 test |
|---|
| 119 |
s.setLayer({}); |
|---|
| 120 |
f = s.createFilter(); |
|---|
| 121 |
t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Spatial/) != -1, |
|---|
| 122 |
"createFilter returns a spatial filter object"); |
|---|
| 123 |
t.eq(f.type, OpenLayers.Filter.Spatial.BBOX, |
|---|
| 124 |
"createFilter returns a BBOX-typed filter"); |
|---|
| 125 |
|
|---|
| 126 |
// 1 test |
|---|
| 127 |
s.setLayer({filter: {fake: "filter"}}); |
|---|
| 128 |
f = s.createFilter(); |
|---|
| 129 |
t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Logical/) != -1, |
|---|
| 130 |
"createFilter returns a logical filter object"); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
function test_merge(t) { |
|---|
| 134 |
t.plan(2); |
|---|
| 135 |
|
|---|
| 136 |
var s = new OpenLayers.Strategy.BBOX(); |
|---|
| 137 |
|
|---|
| 138 |
var features = ["fake", "feature", "array"]; |
|---|
| 139 |
|
|---|
| 140 |
s.setLayer({ |
|---|
| 141 |
destroyFeatures: function() { |
|---|
| 142 |
t.ok(true, |
|---|
| 143 |
"merge calls destroyFeatures"); |
|---|
| 144 |
}, |
|---|
| 145 |
addFeatures: function(f) { |
|---|
| 146 |
t.ok(f == features, |
|---|
| 147 |
"merge calls addFeatures with the correct features"); |
|---|
| 148 |
} |
|---|
| 149 |
}); |
|---|
| 150 |
|
|---|
| 151 |
// 2 tests |
|---|
| 152 |
s.merge({features: features}); |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
</script> |
|---|
| 156 |
</head> |
|---|
| 157 |
<body> |
|---|
| 158 |
<div id="map" style="width: 400px; height: 200px" /> |
|---|
| 159 |
</body> |
|---|
| 160 |
</html> |
|---|