Making it so mergeWithDefaultFilter returns undefined if the protocol defaultFilter is falsey. r=ahocevar,me (closes #2796)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10658 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-08-20 23:48:45 +00:00
parent ee7065c9fa
commit f37c9f8aef
2 changed files with 20 additions and 12 deletions

View File

@@ -57,20 +57,18 @@ OpenLayers.Protocol = OpenLayers.Class({
* filter - {OpenLayers.Filter} * filter - {OpenLayers.Filter}
*/ */
mergeWithDefaultFilter: function(filter) { mergeWithDefaultFilter: function(filter) {
if(filter) { var merged;
if(this.defaultFilter) { if (filter && this.defaultFilter) {
filter = new OpenLayers.Filter.Logical({ merged = new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.AND, type: OpenLayers.Filter.Logical.AND,
filters: [this.defaultFilter, filter] filters: [this.defaultFilter, filter]
}); });
}
} else { } else {
filter = this.defaultFilter; merged = filter || this.defaultFilter || undefined;
} }
return filter; return merged;
}, },
/** /**
* APIMethod: destroy * APIMethod: destroy
* Clean up the protocol. * Clean up the protocol.

View File

@@ -16,13 +16,22 @@
} }
function test_read_defaultFilter(t) { function test_read_defaultFilter(t) {
t.plan(3); t.plan(4);
var protocol = new OpenLayers.Protocol({filter: "a"});
var options = {};
protocol.read(options);
// the line below is what happens in Protocol.WFS.v1::read
OpenLayers.Util.applyDefaults(options, protocol.options);
t.eq(options.filter, "a", "filter from protocol.options applied to options");
protocol.destroy();
var defaultFilter = 'a'; var defaultFilter = 'a';
var options = { var options = {
defaultFilter: defaultFilter defaultFilter: defaultFilter
}; };
var protocol = new OpenLayers.Protocol(options); protocol = new OpenLayers.Protocol(options);
var readFilter = 'b'; var readFilter = 'b';
var options = { filter: readFilter }; var options = { filter: readFilter };
@@ -32,6 +41,7 @@
t.ok(filter instanceof OpenLayers.Filter.Logical, "read method merge default filter & options filter to a logical one"); t.ok(filter instanceof OpenLayers.Filter.Logical, "read method merge default filter & options filter to a logical one");
t.eq(filter.type, OpenLayers.Filter.Logical.AND, "logical filter type is OpenLayers.Filter.Logical.AND"); t.eq(filter.type, OpenLayers.Filter.Logical.AND, "logical filter type is OpenLayers.Filter.Logical.AND");
t.eq(filter.filters, [defaultFilter, readFilter], "read method has merged filters"); t.eq(filter.filters, [defaultFilter, readFilter], "read method has merged filters");
protocol.destroy();
} }
function test_destroy(t) { function test_destroy(t) {