~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/Strategy/BBOX.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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(7);
 
80
 
 
81
        var s = new OpenLayers.Strategy.BBOX();
 
82
 
 
83
        var filter = {"fake": "filter"};
 
84
 
 
85
        s.createFilter = function() {
 
86
            return filter;
 
87
        };
 
88
 
 
89
        s.setLayer({
 
90
            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
            }
 
100
        });
 
101
 
 
102
        // 3 tests
 
103
        s.triggerRead();
 
104
 
 
105
        // 4 tests
 
106
        s.response = {
 
107
            priv: {
 
108
                abort: function() {
 
109
                    t.ok(true,
 
110
                         "triggerRead aborts previous read request");
 
111
                }
 
112
            }
 
113
        };
 
114
        s.triggerRead();
 
115
    }
 
116
 
 
117
    function test_createFilter(t) {
 
118
        t.plan(3);
 
119
 
 
120
        var s = new OpenLayers.Strategy.BBOX();
 
121
 
 
122
        var f;
 
123
 
 
124
        // 2 test
 
125
        s.setLayer({});
 
126
        f = s.createFilter();
 
127
        t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Spatial/) != -1,
 
128
             "createFilter returns a spatial filter object");
 
129
        t.eq(f.type, OpenLayers.Filter.Spatial.BBOX,
 
130
             "createFilter returns a BBOX-typed filter");
 
131
 
 
132
        // 1 test
 
133
        s.setLayer({filter: {fake: "filter"}});
 
134
        f = s.createFilter();
 
135
        t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Logical/) != -1,
 
136
             "createFilter returns a logical filter object");
 
137
    }
 
138
 
 
139
    function test_merge(t) {
 
140
        t.plan(2);
 
141
 
 
142
        var s = new OpenLayers.Strategy.BBOX();
 
143
 
 
144
        var features = ["fake", "feature", "array"];
 
145
 
 
146
        s.setLayer({
 
147
           destroyFeatures: function() {
 
148
               t.ok(true,
 
149
                    "merge calls destroyFeatures");
 
150
           },
 
151
           addFeatures: function(f) {
 
152
               t.ok(f == features,
 
153
                    "merge calls addFeatures with the correct features");
 
154
           }
 
155
        });
 
156
 
 
157
        // 2 tests
 
158
        s.merge({features: features});
 
159
    }
 
160
 
 
161
  </script>
 
162
</head>
 
163
<body>
 
164
    <div id="map" style="width: 400px; height: 200px" />
 
165
</body>
 
166
</html>