<commit_before><!DOCTYPE html>
<html debug="true">
  <head>
    <link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext/gpl/4.2.1/resources/css/ext-all.css">
    <script type="text/javascript" src="http://openlayers.org/api/2.13.1/OpenLayers.js"></script>
    <script type="text/javascript" src="http://cdn.sencha.io/ext/gpl/4.2.1/ext-all-debug.js"></script>

    <script type="text/javascript">

        Ext.Loader.setConfig({
            enabled:true,
            disableCaching: false,
            paths: {
                "GeoExt": "../../src/GeoExt"
            }
        });

        // loading happens with syncrequire, because in IE8, the registering of
        // GeoExt.container.WmsLegend as available legend type would happen to
        // late and the legend test would fail.
        Ext.Loader.syncRequire([
            'GeoExt.data.PrintPage', 
            'GeoExt.data.MapfishPrintProvider',
            'GeoExt.panel.Legend',
            'GeoExt.container.WmsLegend',
            'GeoExt.container.UrlLegend',
            'GeoExt.container.VectorLegend'
        ]);

    </script>

    <script type="text/javascript">
        var printCapabilities = {"scales":[{"name":"1:25,000","value":"25000"},{"name":"1:50,000","value":"50000"},{"name":"1:100,000","value":"100000"},{"name":"1:200,000","value":"200000"},{"name":"1:500,000","value":"500000"},{"name":"1:1,000,000","value":"1000000"},{"name":"1:2,000,000","value":"2000000"},{"name":"1:4,000,000","value":"4000000"}],"dpis":[{"name":"75","value":"75"},{"name":"150","value":"150"},{"name":"300","value":"300"}],"layouts":[{"name":"A4 portrait","map":{"width":440,"height":483},"rotation":true},{"name":"Legal","map":{"width":440,"height":483},"rotation":false}],"printURL":"http://demo.opengeo.org/geoserver/pdf/print.pdf","createURL":"http://demo.opengeo.org/geoserver/pdf/create.json"};
        
        function test_constructor(t) {
            t.plan(9);
            var log = {};
            
            var origRequest = Ext.Ajax.request;
            Ext.Ajax.request = function(req) {
                req.success.call(req.scope, {responseText: Ext.encode(printCapabilities)});
            };
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                url: "PrintProvider",
                autoLoad: true,
                listeners: {
                    "loadcapabilities": function() {
                        log.loadcapabilities = arguments;
                    }
                }
            });
            
            t.eq(printProvider.customParams, {}, "customParams initialized properly.");
            t.ok(log.loadcapabilities[0] == printProvider, "printProvider passed as 1st argument of the loadcapabilities listener.");
            t.ok(log.loadcapabilities[1] == printProvider.capabilities, "capabilities passed as 2nd argument of the loadcapabilities listener.");
            t.eq(printProvider.capabilities.createURL, "http://demo.opengeo.org/geoserver/pdf/create.json", "capabilities available and createURL correct after loadcapabilities event");
            t.ok(printProvider.layout == printProvider.layouts.getAt(0), "layout set to first available layout record.");
            t.ok(printProvider.dpi == printProvider.dpis.getAt(0), "dpi set to first available dpi record.");
            t.eq(printProvider.scales.getCount(), 8, "8 scales read in properly.");

            log = {};
            printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                url: "PrintProvider",
                listeners: {
                    "loadcapabilities": function() {
                        log.loadcapabilities = arguments;
                    }
                }
            });
            t.eq(log.loadcapabilities, undefined, "capabilities not loaded if autoLoad is not set");
            printProvider.loadCapabilities();
            t.ok(log.loadcapabilities, "capabilities loaded by calling loadCapabilities");

            Ext.Ajax.request = origRequest;
        }
        
        function test_setLayout(t) {
            t.plan(3);
            var log = {};
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                capabilities: printCapabilities,
                listeners: {
                    "layoutchange": function() {
                        log.layoutchange = arguments;
                    }
                }
            });
            var layout = printProvider.layouts.getAt(1);
            printProvider.setLayout(layout);
            t.ok(printProvider.layout == layout, "layout set correctly.");
            t.ok(log.layoutchange[0] == printProvider, "printProvider passed as 1st argment of the layoutchange listener.");
            t.ok(log.layoutchange[1] == layout, "layout passed as 2nd argment of the layoutchange listener.");
        }

        function test_setDpi(t) {
            t.plan(3);
            var log = {};
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                capabilities: printCapabilities,
                listeners: {
                    "dpichange": function() {
                        log.dpichange = arguments;
                    }
                }
            });
            var dpi = printProvider.dpis.getAt(1);
            printProvider.setDpi(dpi);
            t.ok(printProvider.dpi == dpi, "dpi set correctly.");
            t.ok(log.dpichange[0] == printProvider, "printProvider passed as 1st argment of the dpichange listener.");
            t.ok(log.dpichange[1] == dpi, "dpi passed as 2nd argment of the dpichange listener.");
        }
        
        function test_getAbsoluteUrl(t) {
            t.plan(2);
            
            var getAbsoluteUrl = GeoExt.data.MapfishPrintProvider.prototype.getAbsoluteUrl;
            var baseUrl = parent.location.href.substr(0, parent.location.href.indexOf("/tests/run-tests.html"));
            t.eq(getAbsoluteUrl("/foo/bar.html"), location.protocol + "//" + location.host + (location.port && ":" + location.port) + "/foo/bar.html", "Relative url converted to absolute url correctly.");
            t.eq(getAbsoluteUrl("../../bar.html"), baseUrl + "/bar.html", "Relative url with relative path converted to absolute url correctly.");
        }
        
        function test_print(t) {
            t.plan(2);
            var log = {};
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                capabilities: printCapabilities,
                customParams: {customParam: "foo"},
                listeners: {
                    "dpichange": function() {
                        log.dpichange = arguments;
                    },
                    "beforeencodelayer": function(provider, layer) {
                        return layer.name !== "don't print me";
                    },
                    "encodelayer": function(provider, layer, encodedLayer) {
                        if (layer instanceof OpenLayers.Layer.WMS) {
                            encodedLayer.customParams = Ext.apply({
                                map_resolution: 150
                            }, encodedLayer.customParams);<commit_msg>Correct the port-awareness of test.<commit_after><!DOCTYPE html>
<html debug="true">
  <head>
    <link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext/gpl/4.2.1/resources/css/ext-all.css">
    <script type="text/javascript" src="http://openlayers.org/api/2.13.1/OpenLayers.js"></script>
    <script type="text/javascript" src="http://cdn.sencha.io/ext/gpl/4.2.1/ext-all-debug.js"></script>

    <script type="text/javascript">

        Ext.Loader.setConfig({
            enabled:true,
            disableCaching: false,
            paths: {
                "GeoExt": "../../src/GeoExt"
            }
        });

        // loading happens with syncrequire, because in IE8, the registering of
        // GeoExt.container.WmsLegend as available legend type would happen to
        // late and the legend test would fail.
        Ext.Loader.syncRequire([
            'GeoExt.data.PrintPage', 
            'GeoExt.data.MapfishPrintProvider',
            'GeoExt.panel.Legend',
            'GeoExt.container.WmsLegend',
            'GeoExt.container.UrlLegend',
            'GeoExt.container.VectorLegend'
        ]);

    </script>

    <script type="text/javascript">
        var printCapabilities = {"scales":[{"name":"1:25,000","value":"25000"},{"name":"1:50,000","value":"50000"},{"name":"1:100,000","value":"100000"},{"name":"1:200,000","value":"200000"},{"name":"1:500,000","value":"500000"},{"name":"1:1,000,000","value":"1000000"},{"name":"1:2,000,000","value":"2000000"},{"name":"1:4,000,000","value":"4000000"}],"dpis":[{"name":"75","value":"75"},{"name":"150","value":"150"},{"name":"300","value":"300"}],"layouts":[{"name":"A4 portrait","map":{"width":440,"height":483},"rotation":true},{"name":"Legal","map":{"width":440,"height":483},"rotation":false}],"printURL":"http://demo.opengeo.org/geoserver/pdf/print.pdf","createURL":"http://demo.opengeo.org/geoserver/pdf/create.json"};
        
        function test_constructor(t) {
            t.plan(9);
            var log = {};
            
            var origRequest = Ext.Ajax.request;
            Ext.Ajax.request = function(req) {
                req.success.call(req.scope, {responseText: Ext.encode(printCapabilities)});
            };
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                url: "PrintProvider",
                autoLoad: true,
                listeners: {
                    "loadcapabilities": function() {
                        log.loadcapabilities = arguments;
                    }
                }
            });
            
            t.eq(printProvider.customParams, {}, "customParams initialized properly.");
            t.ok(log.loadcapabilities[0] == printProvider, "printProvider passed as 1st argument of the loadcapabilities listener.");
            t.ok(log.loadcapabilities[1] == printProvider.capabilities, "capabilities passed as 2nd argument of the loadcapabilities listener.");
            t.eq(printProvider.capabilities.createURL, "http://demo.opengeo.org/geoserver/pdf/create.json", "capabilities available and createURL correct after loadcapabilities event");
            t.ok(printProvider.layout == printProvider.layouts.getAt(0), "layout set to first available layout record.");
            t.ok(printProvider.dpi == printProvider.dpis.getAt(0), "dpi set to first available dpi record.");
            t.eq(printProvider.scales.getCount(), 8, "8 scales read in properly.");

            log = {};
            printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                url: "PrintProvider",
                listeners: {
                    "loadcapabilities": function() {
                        log.loadcapabilities = arguments;
                    }
                }
            });
            t.eq(log.loadcapabilities, undefined, "capabilities not loaded if autoLoad is not set");
            printProvider.loadCapabilities();
            t.ok(log.loadcapabilities, "capabilities loaded by calling loadCapabilities");

            Ext.Ajax.request = origRequest;
        }
        
        function test_setLayout(t) {
            t.plan(3);
            var log = {};
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                capabilities: printCapabilities,
                listeners: {
                    "layoutchange": function() {
                        log.layoutchange = arguments;
                    }
                }
            });
            var layout = printProvider.layouts.getAt(1);
            printProvider.setLayout(layout);
            t.ok(printProvider.layout == layout, "layout set correctly.");
            t.ok(log.layoutchange[0] == printProvider, "printProvider passed as 1st argment of the layoutchange listener.");
            t.ok(log.layoutchange[1] == layout, "layout passed as 2nd argment of the layoutchange listener.");
        }

        function test_setDpi(t) {
            t.plan(3);
            var log = {};
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                capabilities: printCapabilities,
                listeners: {
                    "dpichange": function() {
                        log.dpichange = arguments;
                    }
                }
            });
            var dpi = printProvider.dpis.getAt(1);
            printProvider.setDpi(dpi);
            t.ok(printProvider.dpi == dpi, "dpi set correctly.");
            t.ok(log.dpichange[0] == printProvider, "printProvider passed as 1st argment of the dpichange listener.");
            t.ok(log.dpichange[1] == dpi, "dpi passed as 2nd argment of the dpichange listener.");
        }
        
        function test_getAbsoluteUrl(t) {
            t.plan(2);
            
            var getAbsoluteUrl = GeoExt.data.MapfishPrintProvider.prototype.getAbsoluteUrl;
            var baseUrl = parent.location.href.substr(0, parent.location.href.indexOf("/tests/run-tests.html"));
            t.eq(getAbsoluteUrl("/foo/bar.html"), location.protocol + "//" + location.host + "/foo/bar.html", "Relative url converted to absolute url correctly.");
            t.eq(getAbsoluteUrl("../../bar.html"), baseUrl + "/bar.html", "Relative url with relative path converted to absolute url correctly.");
        }
        
        function test_print(t) {
            t.plan(2);
            var log = {};
            var printProvider = Ext.create('GeoExt.data.MapfishPrintProvider', {
                capabilities: printCapabilities,
                customParams: {customParam: "foo"},
                listeners: {
                    "dpichange": function() {
                        log.dpichange = arguments;
                    },
                    "beforeencodelayer": function(provider, layer) {
                        return layer.name !== "don't print me";
                    },
                    "encodelayer": function(provider, layer, encodedLayer) {
                        if (layer instanceof OpenLayers.Layer.WMS) {
                            encodedLayer.customParams = Ext.apply({
                                map_resolution: 150
                            }, encodedLayer.customParams);
{'fraction_non_alphanumeric': 0.142085209560097, 'fraction_numerical': 0.02396951853134742, 'mean_word_length': 1.989438807206461, 'pattern_counts': {'":': 91, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7133465', 'n_tokens_mistral': 4130, 'n_tokens_neox': 3826, 'n_words': 691}