[Commits] r2719 - sandbox/gxm/geoext/gxm/tests/lib
commits at geoext.org
commits at geoext.org
Tue May 24 10:05:52 CEST 2011
Author: marcjansen
Date: 2011-05-24 10:05:52 +0200 (Tue, 24 May 2011)
New Revision: 2719
Modified:
sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html
Log:
- more mappanel tests
Modified: sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html
===================================================================
--- sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html 2011-05-23 15:11:06 UTC (rev 2718)
+++ sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html 2011-05-24 08:05:52 UTC (rev 2719)
@@ -32,7 +32,9 @@
function getMapPanel(opts) {
var map = getMap();
var options = Ext.apply(opts || {});
- options.map = map;
+ if (!opts || !opts.map) {
+ options.map = map;
+ }
var mappanel = new GXM.MapPanel(options);
return mappanel;
}
@@ -193,34 +195,116 @@
panel.destroy();
}
+
+//TODO: remove eventually
+var log = function(){
+ if (console && console.log) {
+ for (arg in arguments) {
+ console.log(arguments[arg]);
+ }
+ }
+};
+var dir = function(){
+ if (console && console.dir) {
+ for (arg in arguments) {
+ console.dir(arguments[arg]);
+ }
+ }
+};
+
function test_extent(t){
t.plan(2);
var panel;
- var log = {};
+ var logger = {};
var map = getMap();
+ map.zoomToExtent = function(extent, force){
+ logger.extent = extent;
+ };
-
panel = getMapPanel({
map: map,
extent: new OpenLayers.Bounds(1, 2, 3, 4)
});
- map.zoomToExtent = function(extent){
- alert(1321)
- log.extent = extent;
- };
- t.eq(log.extent, '1,2,3,4', "extent as OpenLayers.Bounds-object is set on the map");
- log = {};
+
+ t.eq(logger.extent.toString(), '1,2,3,4', "extent as OpenLayers.Bounds-object is set on the map");
+ logger = {};
panel.destroy();
panel = getMapPanel({
map: map,
extent: [5,6,7,8]
});
- t.eq(log.extent, '5,6,7,8', "extent as array is set on the map");
+ t.eq(logger.extent.toString(), '5,6,7,8', "extent as array is set on the map");
panel.destroy();
+ map.destroy();
}
+function test_destroy(t) {
+ t.plan(6);
+ /**
+ * If the panel is passed an instance of OpenLayers.Map, we don't
+ * touch it in the destroy sequence, we only remove our reference
+ * to it. If the panel is passed a map config object, the panel
+ * creates the OpenLayers.Map instance, and the panel destroys the
+ * map in its destroy sequence.
+ */
+ var mappanel = new GXM.MapPanel({
+ layers: [
+ new OpenLayers.Layer()
+ ],
+ center: '0,0'
+ });
+ t.ok(mappanel.map instanceof OpenLayers.Map, 'GXM.MapPanel creates an OpenLayers.Map-instance');
+
+ var called = false;
+ mappanel.map.destroy = function() {
+ called = true;
+ OpenLayers.Map.prototype.destroy.apply(mappanel.map, arguments);
+ };
+ try {
+ mappanel.destroy();
+ t.ok(called, "mappanel.destroy calls map.destroy");
+ } catch(err) {
+ t.fail("mappanel.destroy causes problems: " + err);
+ }
+ t.ok(!mappanel.map, "mappanel has no reference to a map");
+
+
+ // if we have a reference to a map, do not touch it
+ var map = new OpenLayers.Map({
+ layers: [
+ new OpenLayers.Layer()
+ ],
+ // an fixed prop to check wether the right refernece is taken
+ humptyDumpty: 'foo-bar-baz'
+ });
+
+
+ var mappanel2 = new GXM.MapPanel({
+ fullscreen: false,
+ map: map,
+ center: '1,1'
+ });
+
+ t.eq(mappanel2.map.humptyDumpty , 'foo-bar-baz' , 'GXM.MapPanel respects a given OpenLayers.Map-instance');
+
+ called = false;
+ mappanel2.map.destroy = function(){
+ called = true;
+ OpenLayers.Map.prototype.destroy.apply(mappanel2.map, arguments);
+ }
+
+ try {
+ mappanel2.destroy();
+ t.eq(called, false, "mappanel.destroy does not call map.destroy when it's from outside");
+ } catch(err) {
+ t.fail("mappanel.destroy causes problems: " + err);
+ }
+
+ t.ok(map instanceof OpenLayers.Map, 'map is still a OpenLayers.Map-instance after the panel has been destroyed.');
+}
+
</script>
</head>
<body></body>
More information about the Commits
mailing list