Ticket #208: patch-MapFish-208-r919-A0.diff

File patch-MapFish-208-r919-A0.diff, 38.7 kB (added by elemoine, 5 months ago)
  • client/mfbase/mapfish/tests/core/test_SearchMediator.html

    old new  
     1<!DOCTYPE html> 
     2<html debug="true"> 
     3  <head> 
     4    <link rel="stylesheet" type="text/css" href="../../ext/resources/css/ext-all.css" /> 
     5 
     6    <script type="text/javascript" src="../../../openlayers/lib/Firebug/firebug.js"></script> 
     7    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script> 
     8 
     9    <script type="text/javascript" src="../../../ext/adapter/ext/ext-base.js"></script> 
     10    <script type="text/javascript" src="../../../ext/ext-all-debug.js"></script> 
     11 
     12    <script type="text/javascript"> 
     13      // Because of a bug in Firefox 2 we need to specify the MapFish base path. 
     14      // See https://bugzilla.mozilla.org/show_bug.cgi?id=351282 
     15      var gMfLocation = "../../../mapfish/"; 
     16    </script> 
     17    <script type="text/javascript" src="../../../mapfish/MapFish.js"></script> 
     18 
     19    <script type="text/javascript"><!-- 
     20    function test_SearchMediator_initialize(t) { 
     21        t.plan(5); 
     22 
     23        var url = 'url'; 
     24        var callback = function() {}; 
     25        var params = {'fake': 'params'}; 
     26 
     27        var mediator = new mapfish.SearchMediator(url, callback, params); 
     28 
     29        t.eq(mediator.url, url, 
     30            "ctor correctly sets url"); 
     31        t.ok(mediator.callback == callback, 
     32            "ctor correctly sets callback"); 
     33        t.eq(mediator.params.fake, params.fake, 
     34            "ctor correctly sets params"); 
     35        t.eq(mediator.searchers.length, 0, 
     36            "ctor correctly initializes array of searchers"); 
     37        t.eq(mediator.parser.CLASS_NAME, "OpenLayers.Format.GeoJSON", 
     38            "ctor correctly creates GeoJSON format object"); 
     39    } 
     40 
     41    function test_SearchMediator_setOptions(t) { 
     42        t.plan(3); 
     43 
     44        var options = { 
     45            "url": "url", 
     46            "callback": function() {}, 
     47            "params": {"fake": "params"} 
     48        }; 
     49 
     50        var mediator = new mapfish.SearchMediator(); 
     51        mediator.setOptions(options); 
     52 
     53        t.eq(mediator.url, options.url, 
     54            "setOptions correctly sets url"); 
     55        t.ok(mediator.callback == options.callback, 
     56            "setOptions correctly sets callback"); 
     57        t.eq(mediator.params.fake, options.params.fake, 
     58            "setOptions correctly sets params"); 
     59    } 
     60 
     61    function test_SearchMediator_register(t) { 
     62        t.plan(3); 
     63 
     64        var mediator = new mapfish.SearchMediator(); 
     65 
     66        var searcher1 = 'fake searcher 1'; 
     67        var searcher2 = 'fake searcher 2'; 
     68 
     69        mediator.register(searcher1); 
     70        mediator.register(searcher2); 
     71 
     72        t.eq(mediator.searchers.length, 2, 
     73            "register correctly registers two searchers"); 
     74        t.eq(mediator.searchers[0], searcher1, 
     75            "register correctly registers searcher 1"); 
     76        t.eq(mediator.searchers[1], searcher2, 
     77            "register correctly registers searcher 2"); 
     78    } 
     79 
     80    function test_SearchMediator_onSuccess(t) { 
     81        t.plan(4); 
     82 
     83        var mediator = new mapfish.SearchMediator(); 
     84 
     85        // monkey patch 
     86        mediator.parser.read = function(responseText) { 
     87            return responseText; 
     88        }; 
     89 
     90        var expected; 
     91 
     92        mediator.callback = function(f) { 
     93            t.ok(f == expected, 
     94                "callback called with expected arg"); 
     95        }; 
     96 
     97        // test with no request - 1 test 
     98        expected = null; 
     99        mediator.onSuccess(); 
     100 
     101        // test with no responseText - 1 test 
     102        expected = null; 
     103        mediator.onSuccess({"fake": "request"}); 
     104 
     105        // test with empty responseText - 1 test 
     106        expected = null; 
     107        mediator.onSuccess({"responseText": ""}); 
     108 
     109        // test with non-empty responseText - 1 test 
     110        expected = "fake"; 
     111        mediator.onSuccess({"responseText": expected}); 
     112    } 
     113 
     114    function test_SearchMediator_doSearch(t) { 
     115        t.plan(1); 
     116 
     117        var mediator = new mapfish.SearchMediator(); 
     118 
     119        // monkey patch 
     120        mediator.getSearchParams = function() {}; 
     121 
     122        // monkey patch 
     123        mediator.getUrl = function() {return "url"}; 
     124 
     125        // monkey patch 
     126        var _oar = OpenLayers.Ajax.Request; 
     127        OpenLayers.Ajax.Request = function(url) { 
     128            t.eq(url, "url", 
     129                "OpenLayers.Ajax.Request called with correct URL"); 
     130        }; 
     131 
     132        // 1 test 
     133        mediator.doSearch(); 
     134 
     135        // cleanup 
     136        OpenLayers.Ajax.Request = _oar; 
     137    } 
     138 
     139    function test_SearchMediator_getUrl(t) { 
     140        t.plan(3); 
     141 
     142        var mediator = new mapfish.SearchMediator(); 
     143 
     144        var url; 
     145        var params; 
     146        var expectedUrl; 
     147 
     148        // 1 test 
     149        params = {"foo": "foo", "bar": "bar"}; 
     150        mediator.url = "url"; 
     151        expectedUrl = "url?foo=foo&bar=bar"; 
     152        url = mediator.getUrl(params); 
     153        t.eq(url, expectedUrl, 
     154            "getUrl returns expected URL"); 
     155 
     156        // 1 test 
     157        params = {"foo": "foo", "bar": "bar"}; 
     158        mediator.url = "url?"; 
     159        expectedUrl = "url?foo=foo&bar=bar"; 
     160        url = mediator.getUrl(params); 
     161        t.eq(url, expectedUrl, 
     162            "getUrl returns expected URL"); 
     163 
     164        // 1 test 
     165        params = {"foo": "foo", "bar": "bar"}; 
     166        mediator.url = "url?p=p"; 
     167        expectedUrl = "url?foo=foo&bar=bar&p=p"; 
     168        url = mediator.getUrl(params); 
     169        t.eq(url, expectedUrl, 
     170            "getUrl returns expected URL"); 
     171    } 
     172 
     173    function test_SearchMediator_cancelSearch(t) { 
     174        t.plan(1); 
     175 
     176        var mediator = new mapfish.SearchMediator(); 
     177         
     178        mediator.request = { 
     179            "transport": { 
     180                "abort": function() { 
     181                    t.ok(true, "abort method called"); 
     182                } 
     183            } 
     184        }; 
     185 
     186        mediator.cancelSearch(); 
     187    } 
     188 
     189    function test_SearchMediator_getSearchParams(t) { 
     190        t.plan(1); 
     191 
     192        var mediator = new mapfish.SearchMediator(); 
     193 
     194        var paramsArray = [ 
     195            {"1_p1": "1_p1", "1_p2": "1_p2"}, 
     196            {"2_p1": "2_p1", "2_p2": "2_p2"}, 
     197            {"3_p1": "3_p1", "3_p2": "3_p2"} 
     198        ]; 
     199 
     200        var searcher1 = { 
     201            "getSearchParams": function() { 
     202                return paramsArray[0]; 
     203            } 
     204        }; 
     205        var searcher2 = { 
     206            "getSearchParams": function() { 
     207                return paramsArray[1]; 
     208            } 
     209        }; 
     210        var searcher3 = { 
     211            "getSearchParams": function() { 
     212                return paramsArray[2]; 
     213            } 
     214        }; 
     215 
     216        mediator.register(searcher1); 
     217        mediator.register(searcher2); 
     218        mediator.register(searcher3); 
     219 
     220        var allParams = mediator.getSearchParams(searcher2, paramsArray[1]); 
     221 
     222        var ok = true; 
     223        for (var i = 0; i < paramsArray.length; i++) { 
     224            var params = paramsArray[i]; 
     225            for (var k in params) { 
     226                if (allParams[k] != params[k]) { 
     227                    ok = false; 
     228                } 
     229            } 
     230        } 
     231 
     232        // 1 test 
     233        t.ok(ok, 
     234             "getSearchParams correctly gathers search params"); 
     235    } 
     236             
     237--></script> 
     238 
     239  </head> 
     240  <body> 
     241  </body> 
     242</html> 
  • client/mfbase/mapfish/tests/core/Searcher/test_XY.html

    old new  
     1<!DOCTYPE html> 
     2<html debug="true"> 
     3  <head> 
     4    <link rel="stylesheet" type="text/css" href="../../../ext/resources/css/ext-all.css" /> 
     5 
     6    <script type="text/javascript" src="../../../../openlayers/lib/Firebug/firebug.js"></script> 
     7    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script> 
     8 
     9    <script type="text/javascript" src="../../../../ext/adapter/ext/ext-base.js"></script> 
     10    <script type="text/javascript" src="../../../../ext/ext-all-debug.js"></script> 
     11 
     12    <script type="text/javascript"> 
     13      // Because of a bug in Firefox 2 we need to specify the MapFish base path. 
     14      // See https://bugzilla.mozilla.org/show_bug.cgi?id=351282 
     15      var gMfLocation = "../../../../mapfish/"; 
     16    </script> 
     17    <script type="text/javascript" src="../../../../mapfish/MapFish.js"></script> 
     18 
     19    <script type="text/javascript"><!-- 
     20    function test_XY_initialize(t) { 
     21        t.plan(1); 
     22 
     23        var map = {"fake": "map"}; 
     24        var xy = new mapfish.Searcher.XY(map); 
     25 
     26        t.ok(xy.map == map, 
     27            "ctor correctly sets map property"); 
     28    } 
     29 
     30    function test_XY_enable(t) { 
     31        t.plan(12); 
     32 
     33        var xy, create_hover, activate_hover; 
     34 
     35        // monkey patch 
     36        var _ohc = OpenLayers.Handler.Click; 
     37        OpenLayers.Handler.Click = function(control, callbacks, options) { 
     38            t.ok(control == xy, 
     39                "click handler ctor called with correct control object"); 
     40            t.ok(callbacks.click == xy._triggerSearch, 
     41                "click handler ctor called with correct callbacks"); 
     42            t.ok((options.delay == xy.delay) && 
     43                 (options.pixelTolerance == xy.pixelTolerance), 
     44                "click handler ctor called with correct options"); 
     45            create_hover = false; 
     46        }; 
     47        OpenLayers.Handler.Click.prototype.activate = function() { 
     48            t.ok(true, 
     49                "click handler is activated"); 
     50            activate_hover = false; 
     51        }; 
     52 
     53        // monkey patch 
     54        var _ohh = OpenLayers.Handler.Hover; 
     55        OpenLayers.Handler.Hover = function(control, callbacks, options) { 
     56            t.ok(control == xy, 
     57                "hover handler ctor called with correct control object"); 
     58            t.ok((callbacks.pause == xy._triggerSearch) && 
     59                 (callbacks.move == xy._cancelSearch), 
     60                "hover handler ctor called with correct callbacks"); 
     61            t.ok((options.delay == xy.delay) && 
     62                 (options.pixelTolerance == xy.pixelTolerance), 
     63                "hover handler ctor called with correct options"); 
     64            create_hover = true; 
     65        }; 
     66        OpenLayers.Handler.Hover.prototype.activate = function() { 
     67            t.ok(true, 
     68                "hover handler is activated"); 
     69            activate_hover = true; 
     70        }; 
     71 
     72        // click mode - 6 tests 
     73        create_hover = activate_hover = true; 
     74        xy = new mapfish.Searcher.XY("fake map"); 
     75        xy.enable(); 
     76        t.eq(create_hover, false, 
     77            "ctor creates click handler"); 
     78        t.eq(activate_hover, false, 
     79            "ctor activates click handler"); 
     80 
     81        // hover mode - 6 tests 
     82        create_hover = activate_hover = false; 
     83        xy = new mapfish.Searcher.XY("fake map", null, {"hover": true}); 
     84        xy.enable(); 
     85        t.eq(create_hover, true, 
     86            "ctor creates hover handler"); 
     87        t.eq(activate_hover, true, 
     88            "ctor activates hover handler"); 
     89 
     90        // cleanup 
     91        OpenLayers.Handler.Click = _ohc; 
     92        OpenLayers.Handler.Hover = _ohh; 
     93    } 
     94 
     95    function test_XY_disable(t) { 
     96        t.plan(3); 
     97 
     98        var xy = new mapfish.Searcher.XY("fake map"); 
     99 
     100        // monkey patch 
     101        xy.enabled = true; 
     102 
     103        // monkey path 
     104        xy.handler = { 
     105            "deactivate": function() { 
     106                t.ok(true, 
     107                    "disable deactivates handler"); 
     108            }, 
     109            "destroy": function() { 
     110                t.ok(true, 
     111                    "disable destroys handler"); 
     112            } 
     113        }; 
     114 
     115        // 3 tests 
     116        xy.disable(); 
     117        t.eq(xy.handler, null, 
     118            "disable nullifies handler property"); 
     119    } 
     120 
     121    function test_XY__triggerSearch(t) { 
     122        t.plan(3); 
     123 
     124        var xy = new mapfish.Searcher.XY("fake map"); 
     125 
     126        var _event = {"fake": "event"}; 
     127 
     128        // monkey patch 
     129        xy.cancelSearch = function() { 
     130            t.ok(true, 
     131                "_triggerSearch cancels ongoing search"); 
     132        }; 
     133        xy.doSearch = function() { 
     134            t.ok(true, 
     135                "_triggerSearch calls its parent's doSearch method"); 
     136        }; 
     137        xy.getSearchParams = function(evt) { 
     138            t.ok(evt == _event, 
     139                "_triggerSearch passes correct event to getSearchParams"); 
     140        }; 
     141 
     142        // 3 tests 
     143        xy._triggerSearch(_event); 
     144    } 
     145 
     146    function test_XY__cancelSearch(t) { 
     147        t.plan(2); 
     148 
     149        var xy = new mapfish.Searcher.XY("fake map", null, { 
     150            "onMouseMove": function() { 
     151                t.ok(true, 
     152                    "_cancelSearch calls user-defined onMouseMove func"); 
     153            } 
     154        }); 
     155 
     156        var _event = {"fake": "event"}; 
     157 
     158        // monkey patch 
     159        xy.cancelSearch = function() { 
     160            t.ok(true, 
     161                "_cancelSearch cancels ongoing search"); 
     162        }; 
     163 
     164        // 2 tests 
     165        xy._cancelSearch(_event); 
     166    } 
     167 
     168    function test_XY_getSearchParams(t) { 
     169        t.plan(4); 
     170 
     171        var params, expectedParams; 
     172 
     173        var resolution = 0.5; 
     174        var lon = 180; 
     175        var lat = 90; 
     176 
     177        // fake event 
     178        var _event = {"xy": "fake pixel"}; 
     179 
     180        // fake map 
     181        var map = { 
     182            "getLonLatFromViewPortPx": function() { 
     183                t.ok(true, 
     184                    "getSearchParams calls getLonLatFromViewPortPx"); 
     185                return new OpenLayers.LonLat(lon, lat); 
     186            }, 
     187            "getResolution": function() { 
     188                return resolution; 
     189            } 
     190        }; 
     191        var xy = new mapfish.Searcher.XY(map); 
     192 
     193        // 2 tests 
     194        expectedParams = { 
     195            "lon": lon, 
     196            "lat": lat, 
     197            "tolerance": xy.searchTolerance * resolution 
     198        }; 
     199        params = xy.getSearchParams(_event); 
     200        t.ok((params.lon == expectedParams.lon) && 
     201             (params.lat == expectedParams.lat) && 
     202             (params.tolerance == expectedParams.tolerance), 
     203            "getSearchParams returns expected params"); 
     204 
     205        // 2 tests 
     206        xy.searchToleranceUnits = "geo"; 
     207        expectedParams = { 
     208            "lon": lon, 
     209            "lat": lat, 
     210            "tolerance": xy.searchTolerance 
     211        }; 
     212        params = xy.getSearchParams(_event); 
     213        t.ok((params.lon == expectedParams.lon) && 
     214             (params.lat == expectedParams.lat) && 
     215             (params.tolerance == expectedParams.tolerance), 
     216            "getSearchParams returns expected params"); 
     217    } 
     218--></script> 
     219 
     220  </head> 
     221  <body> 
     222  </body> 
     223</html> 
  • client/mfbase/mapfish/tests/core/Searcher/test_Extent.html

    old new  
     1<!DOCTYPE html> 
     2<html debug="true"> 
     3  <head> 
     4    <link rel="stylesheet" type="text/css" href="../../../ext/resources/css/ext-all.css" /> 
     5 
     6    <script type="text/javascript" src="../../../../openlayers/lib/Firebug/firebug.js"></script> 
     7    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script> 
     8 
     9    <script type="text/javascript" src="../../../../ext/adapter/ext/ext-base.js"></script> 
     10    <script type="text/javascript" src="../../../../ext/ext-all-debug.js"></script> 
     11 
     12    <script type="text/javascript"> 
     13      // Because of a bug in Firefox 2 we need to specify the MapFish base path. 
     14      // See https://bugzilla.mozilla.org/show_bug.cgi?id=351282 
     15      var gMfLocation = "../../../../mapfish/"; 
     16    </script> 
     17    <script type="text/javascript" src="../../../../mapfish/MapFish.js"></script> 
     18 
     19    <script type="text/javascript"><!-- 
     20    function test_Extent_initialize(t) { 
     21        t.plan(1); 
     22 
     23        var map = {"fake": "map"}; 
     24        var extent = new mapfish.Searcher.Extent(map); 
     25 
     26        t.ok(extent.map == map, 
     27            "ctor correctly sets map property"); 
     28    } 
     29 
     30    function test_Extent_enable(t) { 
     31        t.plan(3); 
     32 
     33        var extent; 
     34 
     35        // fake map 
     36        var map = { 
     37            "events": { 
     38                "register": function(type, scope, cb) { 
     39                    t.eq(type, "moveend", 
     40                        "register called with correct event type"); 
     41                    t.ok(scope == extent, 
     42                        "register called with correct scope"); 
     43                    t.ok(cb == extent._onMoveend, 
     44                        "register called with correct callback"); 
     45                } 
     46            } 
     47        }; 
     48 
     49        // 3 tests 
     50        extent = new mapfish.Searcher.Extent(map); 
     51        extent.enable(); 
     52    } 
     53 
     54    function test_Extent_disable(t) { 
     55        t.plan(3); 
     56 
     57        var extent; 
     58 
     59        // fake map 
     60        var map = { 
     61            "events": { 
     62                "unregister": function(type, scope, cb) { 
     63                    t.eq(type, "moveend", 
     64                        "register called with correct event type"); 
     65                    t.ok(scope == extent, 
     66                        "register called with correct scope"); 
     67                    t.ok(cb == extent._onMoveend, 
     68                        "register called with correct callback"); 
     69                } 
     70            } 
     71        }; 
     72 
     73        // 3 test 
     74        extent = new mapfish.Searcher.Extent(map); 
     75        extent.enabled = true; 
     76        extent.disable(); 
     77    } 
     78 
     79    function test_Extent___onMoveend(t) { 
     80        t.plan(2); 
     81 
     82        var extent = new mapfish.Searcher.Extent("fake map"); 
     83 
     84        // monkey patch 
     85        extent.doSearch = function() { 
     86            t.ok(true, 
     87                "__onMoveend calls its parent's doSearch method"); 
     88        }; 
     89        extent.getSearchParams = function() { 
     90            t.ok(true, 
     91                "_onMoveend calls getSearchParams"); 
     92        }; 
     93 
     94        // 2 tests 
     95        extent._onMoveend({"fake": "event"}); 
     96    } 
     97 
     98    function test_Extent_getSearchParams(t) { 
     99        t.plan(1); 
     100 
     101        var bbox = "-180,-90,180,90"; 
     102        var expected = {"box": bbox}; 
     103 
     104        // fake map 
     105        var map = { 
     106            "getExtent": function() { 
     107                return { 
     108                    "toBBOX": function() { 
     109                        return bbox; 
     110                    } 
     111                }; 
     112            } 
     113        }; 
     114 
     115        var extent = new mapfish.Searcher.Extent(map); 
     116 
     117        // 1 test 
     118        var params = extent.getSearchParams(); 
     119        t.eq(params.box, expected.box, 
     120            "getSearchParams returns expected params"); 
     121    } 
     122--></script> 
     123 
     124  </head> 
     125  <body> 
     126  </body> 
     127</html> 
  • client/mfbase/mapfish/tests/core/Searcher/test_Box.html

    old new  
     1<!DOCTYPE html> 
     2<html debug="true"> 
     3  <head> 
     4    <link rel="stylesheet" type="text/css" href="../../../ext/resources/css/ext-all.css" /> 
     5 
     6    <script type="text/javascript" src="../../../../openlayers/lib/Firebug/firebug.js"></script> 
     7    <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script> 
     8 
     9    <script type="text/javascript" src="../../../../ext/adapter/ext/ext-base.js"></script> 
     10    <script type="text/javascript" src="../../../../ext/ext-all-debug.js"></script> 
     11 
     12    <script type="text/javascript"> 
     13      // Because of a bug in Firefox 2 we need to specify the MapFish base path. 
     14      // See https://bugzilla.mozilla.org/show_bug.cgi?id=351282 
     15      var gMfLocation = "../../../../mapfish/"; 
     16    </script> 
     17    <script type="text/javascript" src="../../../../mapfish/MapFish.js"></script> 
     18 
     19    <script type="text/javascript"><!-- 
     20    function test_Box_initialize(t) { 
     21        t.plan(1); 
     22 
     23        var map = {"fake": "map"}; 
     24        var box = new mapfish.Searcher.Box(map); 
     25 
     26        t.ok(box.map == map, 
     27            "ctor correctly sets map property"); 
     28    } 
     29 
     30    function test_Box_enable(t) { 
     31        t.plan(5); 
     32 
     33        var box; 
     34 
     35        // monkey patch 
     36        var _ohb = OpenLayers.Handler.Box; 
     37        OpenLayers.Handler.Box = function(control, callbacks, options) { 
     38            t.ok(control == box, 
     39                "box handler ctor called with correct control object"); 
     40            t.ok(callbacks.done == box._triggerSearch, 
     41                "box handler ctor called with correct callbacks"); 
     42            t.ok(options.boxDivClassName == box.boxDivClassName, 
     43                "box handler ctor called with correct options"); 
     44        }; 
     45        OpenLayers.Handler.Box.prototype.activate = function() { 
     46            t.ok(true, 
     47                "box handler is activated"); 
     48        }; 
     49 
     50        // 5 tests 
     51        box = new mapfish.Searcher.Box("fake map"); 
     52        box.enable(); 
     53        t.ok(box.handler != null, 
     54            "disable sets handler property"); 
     55 
     56        // cleanup 
     57        OpenLayers.Handler.Box = _ohb; 
     58    } 
     59 
     60    function test_Box_disable(t) { 
     61        t.plan(3); 
     62 
     63        var box = new mapfish.Searcher.Box("fake map"); 
     64 
     65        // monkey patch 
     66        box.enabled = true; 
     67 
     68        // monkey path 
     69        box.handler = { 
     70            "deactivate": function() { 
     71                t.ok(true, 
     72                    "disable deactivates handler"); 
     73            }, 
     74            "destroy": function() { 
     75                t.ok(true, 
     76                    "disable destroys handler"); 
     77            } 
     78        }; 
     79 
     80        // 3 tests 
     81        box.disable(); 
     82        t.eq(box.handler, null, 
     83            "disable nullifies handler property"); 
     84    } 
     85 
     86    function test_Box__triggerSearch(t) { 
     87        t.plan(3); 
     88 
     89        var box = new mapfish.Searcher.Box("fake map"); 
     90 
     91        var bounds = {"fake": "bounds"}; 
     92 
     93        // monkey patch 
     94        box.cancelSearch = function() { 
     95            t.ok(true, 
     96                "_triggerSearch cancels ongoing search"); 
     97        }; 
     98        box.doSearch = function() { 
     99            t.ok(true, 
     100                "_triggerSearch calls its parent's doSearch method"); 
     101        }; 
     102        box.getSearchParams = function(b) { 
     103            t.ok(b == bounds, 
     104                "_triggerSearch passes correct bounds to getSearchParams"); 
     105        }; 
     106 
     107        // 3 tests 
     108        box._triggerSearch(bounds); 
     109    } 
     110 
     111    function test_Box_getSearchParams(t) { 
     112        t.plan(4); 
     113 
     114        var left, bottom, right, top; 
     115        var params, position, expected; 
     116 
     117        // fake map 
     118        var map = { 
     119            "getLonLatFromPixel": function(px) { 
     120                t.ok(true, 
     121                    "getSearchParams calls getLonLatFromPixel"); 
     122                return new OpenLayers.LonLat(px.x, px.y); 
     123            } 
     124        }; 
     125        var box = new mapfish.Searcher.Box(map); 
     126 
     127        // getSearchParams is passed bounds - 3 tests 
     128        left = -100, bottom = -20, right = 100, top = 20; 
     129        expected = left.toFixed(4) + "," + bottom.toFixed(4) + "," + 
     130                   right.toFixed(4) + "," + top.toFixed(4); 
     131        position = new OpenLayers.Bounds(left, bottom, right, top); 
     132        params = box.getSearchParams(position); 
     133        t.eq(params.box, expected, 
     134            "getSearchParams returns expected params"); 
     135 
     136        // getSearchParams is passed pixel - 1 test 
     137        position = new OpenLayers.Pixel(left, bottom);  
     138        expected = left.toFixed(4) + "," + bottom.toFixed(4) + "," + 
     139                   left.toFixed(4) + "," + bottom.toFixed(4); 
     140        params = box.getSearchParams(position); 
     141        t.eq(params.box, expected, 
     142            "getSearchParams returns expected params"); 
     143    } 
     144--></script> 
     145 
     146  </head> 
     147  <body> 
     148  </body> 
     149</html> 
  • client/mfbase/mapfish/tests/core/test_Searcher.html

    old new  
     1<!DOCTYPE html> 
     2<html debug="true"> 
     3  <head> 
     4    <link rel="stylesheet" type="text/css" href="../../ext/resources/css/ext-all.css" /> 
     5 
     6    <script type="text/javascript" src="../../../openlayers/lib/Firebug/firebug.js"></script> 
     7    <script type="text/javascript" src="../../../openlayers/lib/OpenLayers.js"></script> 
     8 
     9    <script type="text/javascript" src="../../../ext/adapter/ext/ext-base.js"></script> 
     10    <script type="text/javascript" src="../../../ext/ext-all-debug.js"></script> 
     11 
     12    <script type="text/javascript"> 
     13      // Because of a bug in Firefox 2 we need to specify the MapFish base path. 
     14      // See https://bugzilla.mozilla.org/show_bug.cgi?id=351282 
     15      var gMfLocation = "../../../mapfish/"; 
     16    </script> 
     17    <script type="text/javascript" src="../../../mapfish/MapFish.js"></script> 
     18 
     19    <script type="text/javascript"><!-- 
     20 
     21    function test_Searcher_initialize(t) { 
     22        t.plan(6); 
     23 
     24        // 3 tests 
     25        var searcher = new mapfish.Searcher(); 
     26        t.eq(searcher.enabled, false, 
     27            "ctor does not enable searcher"); 
     28        t.eq(searcher.mediator.CLASS_NAME, "mapfish.SearchMediator", 
     29            "ctor creates a default mediator"); 
     30        t.ok(typeof searcher.mediator.callback == "function", 
     31            "ctor creates a default callback"); 
     32        t.ok(searcher.mediator.searchers[0] == searcher, 
     33            "ctor register searcher with mediator"); 
     34 
     35        // 1 test 
     36        var searcher = new mapfish.Searcher(null, {"a": "a"}); 
     37        t.eq(searcher.a, "a", 
     38            "ctor sets options in object"); 
     39 
     40        // 1 test 
     41        var mediator = new mapfish.SearchMediator(); 
     42        mediator.setOptions = function() { 
     43            t.ok(true, "mediator setOptions called"); 
     44        }; 
     45        var searcher = new mapfish.Searcher(mediator, null, { 
     46            "url": "url" 
     47        }); 
     48    } 
     49 
     50    function test_Searcher_enable(t) { 
     51        t.plan(4); 
     52 
     53        var searcher = new mapfish.Searcher(); 
     54 
     55        var ret; 
     56 
     57        // 2 tests 
     58        ret = searcher.enable(); 
     59        t.eq(searcher.enabled, true, 
     60            "enable sets enabled prop to true"); 
     61        t.eq(ret, true, 
     62            "enable returns true when searcher was not already enabled"); 
     63 
     64        // 2 tests 
     65        ret = searcher.enable(); 
     66        t.eq(searcher.enabled, true, 
     67            "enable sets enabled prop to true"); 
     68        t.eq(ret, false, 
     69            "enable returns false when searcher was already enabled"); 
     70    } 
     71 
     72    function test_Searcher_disable(t) { 
     73        t.plan(4); 
     74 
     75        var searcher = new mapfish.Searcher(); 
     76        searcher.enable(); 
     77 
     78        var ret; 
     79 
     80        // 2 tests 
     81        ret = searcher.disable(); 
     82        t.eq(searcher.enabled, false, 
     83            "disable sets enabled prop to false"); 
     84        t.eq(ret, true, 
     85            "disables returns true when searcher was not already disabled"); 
     86 
     87        // 2 tests 
     88        ret = searcher.disable(); 
     89        t.eq(searcher.enabled, false, 
     90            "disable sets enabled prop to false"); 
     91        t.eq(ret, false, 
     92            "disable returns false when searcher was already disabled"); 
     93    } 
     94 
     95    function test_Searcher_doSearch(t) { 
     96        t.plan(2); 
     97 
     98        var mediator = new mapfish.SearchMediator(); 
     99        var searcher = new mapfish.Searcher(mediator); 
     100 
     101        var params = {"fake": "params"}; 
     102 
     103        mediator.doSearch = function(s, p) { 
     104            t.ok(s == searcher, 
     105                "doSearch passes correct searcher to mediator"); 
     106            t.ok(p == params, 
     107                "doSearch passes correct params to mediator"); 
     108        }; 
     109 
     110        // 2 tests 
     111        searcher.doSearch(params); 
     112    } 
     113 
     114    function test_Searcher_cancelSearch(t) { 
     115        t.plan(1); 
     116 
     117        var mediator = new mapfish.SearchMediator(); 
     118        var searcher = new mapfish.Searcher(mediator); 
     119 
     120        mediator.cancelSearch = function() { 
     121            t.ok(true, 
     122                "mediator cancelSearch called"); 
     123        }; 
     124 
     125        // 1 test 
     126        searcher.cancelSearch(); 
     127    } 
     128--></script> 
     129 
     130  </head> 
     131  <body> 
     132  </body> 
     133</html> 
  • client/mfbase/mapfish/tests/list-tests.html

    old new  
    22    <li>core/test_Util.html</li> 
    33    <li>core/test_Offline.html</li> 
    44    <li>core/test_PrintProtocol.html</li> 
     5    <li>core/test_SearchMediator.html</li> 
     6    <li>core/test_Searcher.html</li> 
     7    <li>core/Searcher/test_XY.html</li> 
     8    <li>core/Searcher/test_Box.html</li> 
     9    <li>core/Searcher/test_Extent.html</li> 
    510    <li>widgets/tree/test_LayerTree.html</li> 
    611    <li>widgets/tree/test_LayerTree_separator.html</li> 
    712    <li>widgets/tree/test_LayerTree_wmsLayerRedraw.html</li> 
  • client/mfbase/mapfish/core/SearchMediator.js

    old new  
    151151     * params - {Object} 
    152152     */ 
    153153    doSearch: function(searcher, params) { 
    154         // build parameters string 
    155         var allParams = this.getSearchParams(searcher, params); 
    156         var paramsString = OpenLayers.Util.getParameterString(allParams); 
    157         // build full request string 
    158         var url = this.url; 
    159         if (typeof url == "function") { 
    160             url = url(); 
    161         } 
    162         var requestString = url + (url.match(/\?/) ? '&' : '?') + paramsString; 
     154        var url = this.getUrl(this.getSearchParams(searcher, params)); 
     155 
    163156        // send request 
    164         this.request = new OpenLayers.Ajax.Request( 
    165             requestString, 
    166             { 
    167                 method: "GET", 
    168                 onSuccess: OpenLayers.Function.bind(this.onSuccess, this), 
    169                 onFailure: function() { alert('Ajax request failed'); } 
    170             } 
    171         ); 
     157        this.request = new OpenLayers.Ajax.Request(url, { 
     158            method: "GET", 
     159            onSuccess: OpenLayers.Function.bind(this.onSuccess, this), 
     160            onFailure: function() { alert('Ajax request failed'); } 
     161        }); 
    172162    }, 
    173163 
    174164    /** 
     165     * Method: getUrl 
     166     * 
     167     * Parameters: 
     168     * params - {Object} The search params. 
     169     * 
     170     * Returns: 
     171     * {String} The complete URL string. 
     172     */ 
     173    getUrl: function(params) { 
     174        var url = typeof this.url == "function" ? this.url() : this.url; 
     175        var idx = url.indexOf("?"); 
     176        if (idx < 0) { 
     177            url += "?"; 
     178        } else { 
     179            params = OpenLayers.Util.extend(params, 
     180                OpenLayers.Util.getParameters(url)); 
     181            url = url.substring(0, idx + 1); 
     182        } 
     183        url += OpenLayers.Util.getParameterString(params); 
     184        return url; 
     185    }, 
     186 
     187    /** 
    175188     * APIMethod: cancelSearch 
    176189     *      Cancel ongoing search request sent to the search service. 
    177190     */ 
     
    200213            OpenLayers.Util.extend(allParams, s.getSearchParams()); 
    201214        } 
    202215        return allParams; 
    203     } 
     216    }, 
     217 
     218    CLASS_NAME: "mapfish.SearchMediator" 
    204219}); 
  • client/mfbase/mapfish/core/Searcher.js

    old new  
    117117    cancelSearch: function() { 
    118118        this.mediator.cancelSearch(); 
    119119    }, 
    120   
    121     /** 
    122      * Method: addLayers 
    123      *      Add layers as request params. 
    124      * 
    125      * FIXME: this function should be moved elsewhere or removed. 
    126      * 
    127      * Parameters: 
    128      * layers - {Array} 
    129      */ 
    130     addLayers: function(layers) { 
    131         if (!(layers instanceof Array)) { 
    132             layers = [layers]; 
    133         } 
    134         this.addParams({'layers': layers.join(',')}); 
    135     }, 
    136120 
    137121    /** 
    138      * Method: removeLayers 
    139      *      Remove layers from the params. 
    140      * 
    141      * FIXME: this function should be moved elsewhere or removed. 
    142      * 
    143      * Parameters: 
    144      * layers - {Array} 
    145      */ 
    146     removeLayers: function(layers) { 
    147         if (!this.params['layers']) { 
    148             return; 
    149         } 
    150         if (!layers) { 
    151             // remove all 
    152             this.params['layers'] = null; 
    153         } else { 
    154             // remove specified layers 
    155             if (!(layers instanceof Array)) { 
    156                 layers = [layers]; 
    157             } 
    158             var layerArray = this.params['layers'].split(','); 
    159             for (var i = 0; i < layers.length; i++) { 
    160                 OpenLayers.Util.removeItem(layerArray, layers[i]); 
    161             } 
    162         } 
    163     }, 
    164  
    165     /** 
    166      * Method: addParams 
    167      *      Add request params. 
    168      *