From 64a611e8619694c55b802d924fbe92492637ef42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 7 Apr 2011 06:49:38 +0000 Subject: [PATCH] Protocol.HTTP.read should not write params into the protocol's options object, p=etdube,me r=me (closes #3237) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11883 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Protocol/HTTP.js | 3 ++- tests/Protocol/HTTP.html | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Protocol/HTTP.js b/lib/OpenLayers/Protocol/HTTP.js index 3b5d3f9572..2b86c0c77e 100644 --- a/lib/OpenLayers/Protocol/HTTP.js +++ b/lib/OpenLayers/Protocol/HTTP.js @@ -175,9 +175,10 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { */ read: function(options) { OpenLayers.Protocol.prototype.read.apply(this, arguments); - options = OpenLayers.Util.applyDefaults(options, this.options); + options = options || {}; options.params = OpenLayers.Util.applyDefaults( options.params, this.options.params); + options = OpenLayers.Util.applyDefaults(options, this.options); if (options.filter && this.filterToParams) { options.params = this.filterToParams( options.filter, options.params diff --git a/tests/Protocol/HTTP.html b/tests/Protocol/HTTP.html index 6d2e26b186..fac460b547 100644 --- a/tests/Protocol/HTTP.html +++ b/tests/Protocol/HTTP.html @@ -779,7 +779,7 @@ }); protocol.read(); - t.delay_call(1, function() { + t.delay_call(2, function() { t.eq(log1.callbackCalled, true, "[read] callback called"); t.eq(log1.callbackScope, scope, "[read] correct scope"); t.ok(log1.request instanceof OpenLayers.Request.XMLHttpRequest, "[read] correct priv type"); @@ -801,11 +801,37 @@ {state: OpenLayers.State.DELETE, url: "./3"}, {state: OpenLayers.State.DELETE, url: "./4"} ]); - t.delay_call(1, function() { + t.delay_call(2, function() { t.eq(log2.called, 1, "[commit] Callback called once."); t.eq(log2.scope, scope, "[commit] Correct scope."); }); + } + function test_read_global_options(t) { + + // test that calling read doesn't write params into the protocol's + // options object, see ticket #3237 + + t.plan(2); + + var protocol = new OpenLayers.Protocol.HTTP({ + url: '.', + callback: function() {}, + params: {'a': 'a'} + }); + + // check initial state first + t.eq(protocol.options.params, {'a': 'a'}, + 'protocol params are ok at initial state'); + + var filter = new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.EQUAL_TO, + property: 'b', + value: 'b' + }); + protocol.read({filter: filter}); + t.eq(protocol.options.params, {'a': 'a'}, + "protocol params are ok after read"); }