]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Strategy/Save.html
do not allow empty passwords
[syp.git] / openlayers / tests / Strategy / Save.html
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         var strategy = new OpenLayers.Strategy.Save();
9         t.eq(strategy.auto, false, "auto is false by default");
10     }
11
12     function test_activate(t) {
13         
14         t.plan(3);
15         
16         var strategy = new OpenLayers.Strategy.Save();
17         var layer = new OpenLayers.Layer.Vector(null, {
18             isBaseLayer: true,
19             protocol: new OpenLayers.Protocol(),
20             strategies: [strategy]
21         });
22         var map = new OpenLayers.Map("map");
23         map.addLayer(layer);
24         map.zoomToMaxExtent();
25         
26         // check that auto true registers listeners
27         strategy.deactivate();
28         strategy.auto = true;
29         strategy.activate();
30         t.ok(layer.events.listeners["featureadded"][0].func === strategy.triggerSave,
31              "[auto true] triggerSave registered as listener for featureadded");
32         t.ok(layer.events.listeners["afterfeaturemodified"][0].func === strategy.triggerSave,
33              "[auto true] triggerSave registered as listener for afterfeaturemodified");
34
35         // check that auto can be set to interval
36         strategy.deactivate();
37         strategy.auto = 1;
38         strategy.activate();
39         t.ok(strategy.timer != null, "[auto number] timer set")
40         
41         map.destroy();
42         
43     }
44     
45     function test_save(t) {
46         t.plan(5);
47
48         var strategy = new OpenLayers.Strategy.Save();
49         
50         // mock up a protocol for synchronous and successful commits
51         var protocol = new OpenLayers.Protocol({
52             commit: function(features, options) {
53                 var response = new OpenLayers.Protocol.Response();
54                 response.reqFeatures = features;
55                 response.insertIds = [];
56                 for(var i=0; i<features.length; ++i) {
57                     if(features[i].state == OpenLayers.State.INSERT) {
58                         response.insertIds.push("new_" + i);
59                     }
60                 }
61                 response.code = OpenLayers.Protocol.Response.SUCCESS;
62                 options.callback.call(options.scope, response);
63             }
64         });
65
66         var layer = new OpenLayers.Layer.Vector(null, {
67             isBaseLayer: true,
68             protocol: protocol,
69             strategies: [strategy]
70         });
71         var map = new OpenLayers.Map("map");
72         map.addLayer(layer);
73         map.zoomToMaxExtent();
74         
75         // give the layer some features
76         var features = [
77             new OpenLayers.Feature.Vector(), // insert
78             new OpenLayers.Feature.Vector(), // delete
79             new OpenLayers.Feature.Vector(), // update
80             new OpenLayers.Feature.Vector()  // nothing
81         ];
82         features[0].state = OpenLayers.State.INSERT;
83         features[1].state = OpenLayers.State.DELETE;
84         features[2].state = OpenLayers.State.UPDATE;
85         layer.addFeatures(features);
86         
87         // save feature modifications
88         strategy.save(features);
89         
90         // confirm that newly created feature has an id and no longer has insert state
91         t.eq(features[0].fid, "new_0", "newly created feature gets fid");
92         t.ok(features[0].state == null, "newly created feature no longer insert state");
93         
94         // confirm that deleted features are not on layer
95         t.eq(layer.features.length, 3, "layer only has three features");
96         t.ok(features[1].layer == null, "deleted feature has no layer");
97         
98         // confirm that updated feature no longer has update state
99         t.ok(features[2].state == null, "updated feature no longer update state");
100         
101     }
102
103   </script>
104 </head>
105 <body>
106     <div id="map" style="width: 400px; height: 200px" />
107 </body>
108 </html>