Batch merge for rc2 of 2.7. 'svn merge -r7967:HEAD from trunk (Closes #1733) (Closes #1489) (Closes #1639) (Closes #1718) (Closes #1723) (Closes #1732) (Closes #1616) (Closes #1722)
git-svn-id: http://svn.openlayers.org/branches/openlayers/2.7@8012 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -134,6 +134,99 @@
|
||||
t.eq(this.map.controls[this.map.controls.length-1].CLASS_NAME, "CustomArgParser", "Custom ArgParser added correctly.");
|
||||
t.eq(control.div.firstChild.getAttribute("href"), "./edit.html?zoom=2&lat=0&lon=1.75781&layers=B&customParam=foo", "Custom parameter encoded correctly.");
|
||||
}
|
||||
|
||||
function test_Control_Permalink_createParams(t) {
|
||||
t.plan(18);
|
||||
|
||||
var baseLayer = { 'isBaseLayer': true };
|
||||
|
||||
var m = {
|
||||
'getCenter': function() { return null; }
|
||||
};
|
||||
|
||||
var pl = {
|
||||
'map': m,
|
||||
'base': {}
|
||||
};
|
||||
|
||||
old_getParameters = OpenLayers.Util.getParameters;
|
||||
OpenLayers.Util.getParameters = function(base) {
|
||||
t.ok(base == pl.base, "correct base sent in to Util.getParameters()");
|
||||
return g_Params;
|
||||
};
|
||||
|
||||
//null center, null map.getCenter()
|
||||
g_Params = {};
|
||||
m.baseLayer = baseLayer;
|
||||
var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, []);
|
||||
t.ok(returnParams == g_Params, "correct params returned on null center");
|
||||
|
||||
//valid center, zoom, layers
|
||||
g_Params = { 'test': {} };
|
||||
var center = { 'lon': 1.2345678901, 'lat': 9.8765432109 };
|
||||
var zoom = {};
|
||||
var layers = [
|
||||
{ 'isBaseLayer': true },
|
||||
baseLayer,
|
||||
{ 'isBaseLayer': false, 'getVisibility': function() { return true; } },
|
||||
{ 'isBaseLayer': false, 'getVisibility': function() { return false; } }
|
||||
];
|
||||
var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, [center, zoom, layers]);
|
||||
|
||||
t.ok(returnParams.test == g_Params.test, "correct params returned from Util.getParameters() when valid center, zoom, layers");
|
||||
t.ok(returnParams.zoom == zoom, "params.zoom set correctly when valid center, zoom, layers");
|
||||
t.eq(returnParams.lon, 1.23457, "lon set and rounded correctly when valid center, zoom, layers");
|
||||
t.eq(returnParams.lat, 9.87654, "lat set and rounded correctly when valid center, zoom, layers");
|
||||
t.eq(returnParams.layers, "0BTF", "layers processed correctly when valid center, zoom, layers")
|
||||
|
||||
|
||||
//null center, zoom, layers, with displayProjection
|
||||
g_Params = { 'test': {} };
|
||||
g_Projection = {};
|
||||
m = {
|
||||
'baseLayer': baseLayer,
|
||||
'getProjectionObject': function() { return g_Projection; },
|
||||
'center': { 'lon': {}, 'lat': {} },
|
||||
'getCenter': function() { return this.center; },
|
||||
'zoom': {},
|
||||
'getZoom': function() { return this.zoom; },
|
||||
'layers': [
|
||||
{ 'isBaseLayer': false, 'getVisibility': function() { return true; } },
|
||||
baseLayer,
|
||||
{ 'isBaseLayer': false, 'getVisibility': function() { return false; } },
|
||||
{ 'isBaseLayer': true }
|
||||
],
|
||||
'getLayers': function() { return this.layers; }
|
||||
};
|
||||
pl = {
|
||||
'base': {},
|
||||
'map': m,
|
||||
'displayProjection': {}
|
||||
};
|
||||
|
||||
old_transform = OpenLayers.Projection.transform;
|
||||
OpenLayers.Projection.transform = function(point, projObj, dispProj) {
|
||||
t.ok(point.x = m.center.lon, "correct x value passed into transform");
|
||||
t.ok(point.y = m.center.lat, "correct x value passed into transform");
|
||||
t.ok(projObj == g_Projection, "correct projection object from map passed into transform");
|
||||
t.ok(dispProj == pl.displayProjection, "correct displayProjection from control passed into transform");
|
||||
|
||||
return { 'x': 9.8765432109, 'y': 1.2345678901 };
|
||||
};
|
||||
|
||||
center = zoom = layers = null;
|
||||
|
||||
var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, [center, zoom, layers]);
|
||||
t.ok(returnParams.test == g_Params.test, "correct params returned from Util.getParameters() when null center, zoom, layers, with displayProjection");
|
||||
t.ok(returnParams.zoom == m.zoom, "params.zoom set correctly when null center, zoom, layers, with displayProjection");
|
||||
t.eq(returnParams.lon, 9.87654, "lon set, transformed, and rounded correctly when null center, zoom, layers, with displayProjection");
|
||||
t.eq(returnParams.lat, 1.23457, "lat set, transformed, and rounded correctly when null center, zoom, layers, with displayProjection");
|
||||
t.eq(returnParams.layers, "TBF0", "layers processed correctly when null center, zoom, layers, with displayProjection");
|
||||
|
||||
OpenLayers.Util.getParameters = old_getParameters;
|
||||
OpenLayers.Projection.transform = old_transform;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_Format_constructor(t) {
|
||||
t.plan(4);
|
||||
t.plan(5);
|
||||
|
||||
var options = {'foo': 'bar'};
|
||||
var format = new OpenLayers.Format(options);
|
||||
@@ -13,6 +13,7 @@
|
||||
t.eq(format.foo, "bar", "constructor sets options correctly");
|
||||
t.eq(typeof format.read, "function", "format has a read function");
|
||||
t.eq(typeof format.write, "function", "format has a write function");
|
||||
t.eq(format.options, options, "format.options correctly set");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
222
tests/Format/GML/cases.js
Normal file
222
tests/Format/GML/cases.js
Normal file
@@ -0,0 +1,222 @@
|
||||
var xml = new OpenLayers.Format.XML();
|
||||
function readXML(file) {
|
||||
return xml.read(document.getElementById(file).firstChild.nodeValue);
|
||||
}
|
||||
|
||||
var cases = {
|
||||
|
||||
"v2/point-coord.xml": new OpenLayers.Geometry.Point(1, 2),
|
||||
|
||||
"v2/point-coordinates.xml": new OpenLayers.Geometry.Point(1, 2),
|
||||
|
||||
"v2/linestring-coord.xml": new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/linestring-coordinates.xml": new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/linearring-coord.xml": new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
|
||||
"v2/linearring-coordinates.xml": new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
|
||||
"v2/polygon-coord.xml": new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/polygon-coordinates.xml": new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multipoint-coord.xml": new OpenLayers.Geometry.MultiPoint([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/multipoint-coordinates.xml": new OpenLayers.Geometry.MultiPoint([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/multilinestring-coord.xml": new OpenLayers.Geometry.MultiLineString([
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(4, 5)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multilinestring-coordinates.xml": new OpenLayers.Geometry.MultiLineString([
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(4, 5)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multipolygon-coord.xml": new OpenLayers.Geometry.MultiPolygon([
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multipolygon-coordinates.xml": new OpenLayers.Geometry.MultiPolygon([
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/geometrycollection-coordinates.xml": new OpenLayers.Geometry.Collection([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/box-coord.xml": new OpenLayers.Bounds(1, 2, 3, 4),
|
||||
|
||||
"v2/box-coordinates.xml": new OpenLayers.Bounds(1, 2, 3, 4)
|
||||
|
||||
};
|
||||
|
||||
// cases for v3 use the same geometries
|
||||
OpenLayers.Util.extend(cases, {
|
||||
"v3/point.xml": cases["v2/point-coordinates.xml"],
|
||||
"v3/linestring.xml": cases["v2/linestring-coordinates.xml"],
|
||||
"v3/polygon.xml": cases["v2/polygon-coordinates.xml"],
|
||||
"v3/multipoint-singular.xml": cases["v2/multipoint-coordinates.xml"],
|
||||
"v3/multipoint-plural.xml": cases["v2/multipoint-coordinates.xml"],
|
||||
"v3/multilinestring-singular.xml": cases["v2/multilinestring-coordinates.xml"],
|
||||
"v3/multilinestring-plural.xml": cases["v2/multilinestring-coordinates.xml"],
|
||||
"v3/multipolygon-singular.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/multipolygon-plural.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/multisurface-singular.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/multisurface-plural.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/envelope.xml": cases["v2/box-coordinates.xml"]
|
||||
});
|
||||
605
tests/Format/GML/v2.html
Normal file
605
tests/Format/GML/v2.html
Normal file
File diff suppressed because one or more lines are too long
551
tests/Format/GML/v3.html
Normal file
551
tests/Format/GML/v3.html
Normal file
File diff suppressed because one or more lines are too long
@@ -27,7 +27,7 @@
|
||||
'<' + '/ol:root>';
|
||||
|
||||
function test_Format_XML_constructor(t) {
|
||||
t.plan(5);
|
||||
t.plan(13);
|
||||
|
||||
var options = {'foo': 'bar'};
|
||||
var format = new OpenLayers.Format.XML(options);
|
||||
@@ -38,6 +38,36 @@
|
||||
t.eq(typeof format.write, "function", "format has a write function");
|
||||
|
||||
t.ok(!window.ActiveXObject || format.xmldom, "browsers with activeX must have xmldom");
|
||||
|
||||
// test namespaces
|
||||
t.ok(format.namespaces instanceof Object, "format has namespace object");
|
||||
var namespaces = {"foo": "bar"};
|
||||
format = new OpenLayers.Format.XML({namespaces: namespaces});
|
||||
t.eq(format.namespaces, namespaces, "format.namespaces correctly set in constructor");
|
||||
|
||||
// test default prefix
|
||||
t.eq(format.defaultPrefix, null, "defaultPrefix is null by default");
|
||||
format = new OpenLayers.Format.XML({defaultPrefix: "foo"});
|
||||
t.eq(format.defaultPrefix, "foo", "defaultPrefix correctly set in constructor");
|
||||
|
||||
// test readers
|
||||
t.ok(format.readers instanceof Object, "format has readers object");
|
||||
var readers = {"foo": "bar"};
|
||||
format = new OpenLayers.Format.XML({readers: readers});
|
||||
t.eq(format.readers, readers, "format.readers correctly set in constructor");
|
||||
|
||||
// test readers
|
||||
t.ok(format.writers instanceof Object, "format has writers object");
|
||||
var writers = {"foo": "bar"};
|
||||
format = new OpenLayers.Format.XML({writers: writers});
|
||||
t.eq(format.writers, writers, "format.writers correctly set in constructor");
|
||||
}
|
||||
|
||||
function test_destroy(t) {
|
||||
t.plan(1);
|
||||
var format = new OpenLayers.Format.XML();
|
||||
format.destroy();
|
||||
t.eq(format.xmldom, null, "xmldom set to null for all browsers");
|
||||
}
|
||||
|
||||
function test_Format_XML_read(t) {
|
||||
@@ -260,6 +290,363 @@
|
||||
found = format.hasAttributeNS(nodes[0], taUri, "nothing");
|
||||
t.ok(found === false, "returns false for bad attribute");
|
||||
}
|
||||
|
||||
function test_namespaces(t) {
|
||||
t.plan(2);
|
||||
|
||||
var format = new OpenLayers.Format.XML({
|
||||
namespaces: {
|
||||
"def": "http://example.com/default",
|
||||
"foo": "http://example.com/foo",
|
||||
"bar": "http://example.com/bar"
|
||||
},
|
||||
defaultPrefix: "def"
|
||||
});
|
||||
|
||||
// test that prototype has not been altered
|
||||
t.eq(OpenLayers.Format.XML.prototype.namespaces, null,
|
||||
"setting namespaces at construction does not modify prototype");
|
||||
|
||||
// test that namespaceAlias has been set
|
||||
t.eq(format.namespaceAlias["http://example.com/foo"], "foo",
|
||||
"namespaceAlias mapping has been set");
|
||||
|
||||
}
|
||||
|
||||
function test_setNamespace(t) {
|
||||
t.plan(3);
|
||||
|
||||
var format = new OpenLayers.Format.XML();
|
||||
|
||||
// test that namespaces is an object
|
||||
t.ok(format.namespaces instanceof Object, "empty namespace object set");
|
||||
|
||||
format.setNamespace("foo", "http://example.com/foo");
|
||||
t.eq(format.namespaces["foo"], "http://example.com/foo", "alias -> uri mapping set");
|
||||
t.eq(format.namespaceAlias["http://example.com/foo"], "foo", "uri -> alias mapping set");
|
||||
|
||||
}
|
||||
|
||||
function test_readChildNodes(t) {
|
||||
|
||||
var text = "<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<container xmlns='http://example.com/foo'>" +
|
||||
"<marker name='my marker 1'>" +
|
||||
"<position>" +
|
||||
"<lon>-180</lon>" +
|
||||
"<lat>90</lat>" +
|
||||
"</position>" +
|
||||
"<detail>some text for first marker</detail>" +
|
||||
"<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/1'/>" +
|
||||
"</marker>" +
|
||||
"<marker name='my marker 2'>" +
|
||||
"<position>" +
|
||||
"<lon>180</lon>" +
|
||||
"<lat>-90</lat>" +
|
||||
"</position>" +
|
||||
"<detail>some text for second marker</detail>" +
|
||||
"<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/2'/>" +
|
||||
"</marker>" +
|
||||
"</container>";
|
||||
|
||||
var expect = [
|
||||
new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(-180, 90),
|
||||
{
|
||||
name: 'my marker 1',
|
||||
link: 'http://host/path/1',
|
||||
detail: 'some text for first marker'
|
||||
}
|
||||
),
|
||||
new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(180, -90),
|
||||
{
|
||||
name: 'my marker 2',
|
||||
link: 'http://host/path/2',
|
||||
detail: 'some text for second marker'
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
var format = new OpenLayers.Format.XML({
|
||||
defaultPrefix: "foo",
|
||||
namespaces: {
|
||||
"foo": "http://example.com/foo",
|
||||
"atom": "http://www.w3.org/2005/Atom"
|
||||
},
|
||||
readers: {
|
||||
"foo": {
|
||||
"container": function(node, obj) {
|
||||
var list = [];
|
||||
this.readChildNodes(node, list);
|
||||
obj.list = list;
|
||||
},
|
||||
"marker": function(node, list) {
|
||||
var feature = new OpenLayers.Feature.Vector();
|
||||
feature.attributes.name = node.getAttribute("name");
|
||||
this.readChildNodes(node, feature);
|
||||
list.push(feature);
|
||||
},
|
||||
"position": function(node, feature) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
feature.geometry = new OpenLayers.Geometry.Point(obj.x, obj.y);
|
||||
},
|
||||
"lon": function(node, obj) {
|
||||
obj.x = this.getChildValue(node);
|
||||
},
|
||||
"lat": function(node, obj) {
|
||||
obj.y = this.getChildValue(node);
|
||||
},
|
||||
"detail": function(node, feature) {
|
||||
feature.attributes.detail = this.getChildValue(node);
|
||||
}
|
||||
},
|
||||
"atom": {
|
||||
"link": function(node, feature) {
|
||||
feature.attributes.link = node.getAttribute("href");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// convert text to document node
|
||||
var doc = format.read(text);
|
||||
// read child nodes to get back some object
|
||||
var obj = format.readChildNodes(doc);
|
||||
// start comparing what we got to what we expect
|
||||
var got = obj.list;
|
||||
|
||||
t.plan(11);
|
||||
t.eq(got.length, expect.length, "correct number of items parsed");
|
||||
t.eq(got[0].geometry.x, expect[0].geometry.x, "correct x coord parsed for marker 1");
|
||||
t.eq(got[0].geometry.y, expect[0].geometry.y, "correct y coord parsed for marker 1");
|
||||
t.eq(got[0].attributes.name, expect[0].attributes.name, "correct name parsed for marker 1");
|
||||
t.eq(got[0].attributes.detail, expect[0].attributes.detail, "correct detail parsed for marker 1");
|
||||
t.eq(got[0].attributes.link, expect[0].attributes.link, "correct link parsed for marker 1");
|
||||
t.eq(got[1].geometry.x, expect[1].geometry.x, "correct x coord parsed for marker 2");
|
||||
t.eq(got[1].geometry.y, expect[1].geometry.y, "correct y coord parsed for marker 2");
|
||||
t.eq(got[1].attributes.name, expect[1].attributes.name, "correct name parsed for marker 2");
|
||||
t.eq(got[1].attributes.detail, expect[1].attributes.detail, "correct detail parsed for marker 2");
|
||||
t.eq(got[1].attributes.link, expect[1].attributes.link, "correct link parsed for marker 2");
|
||||
|
||||
}
|
||||
|
||||
function test_writeNode(t) {
|
||||
|
||||
var features = [
|
||||
new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(-180, 90),
|
||||
{
|
||||
name: 'my marker 1',
|
||||
link: 'http://host/path/1',
|
||||
detail: 'some text for first marker'
|
||||
}
|
||||
),
|
||||
new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(180, -90),
|
||||
{
|
||||
name: 'my marker 2',
|
||||
link: 'http://host/path/2',
|
||||
detail: 'some text for second marker'
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
var expect = "<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<container xmlns='http://example.com/foo'>" +
|
||||
"<marker name='my marker 1'>" +
|
||||
"<position>" +
|
||||
"<lon>-180</lon>" +
|
||||
"<lat>90</lat>" +
|
||||
"</position>" +
|
||||
"<detail>some text for first marker</detail>" +
|
||||
"<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/1'/>" +
|
||||
"</marker>" +
|
||||
"<marker name='my marker 2'>" +
|
||||
"<position>" +
|
||||
"<lon>180</lon>" +
|
||||
"<lat>-90</lat>" +
|
||||
"</position>" +
|
||||
"<detail>some text for second marker</detail>" +
|
||||
"<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/2'/>" +
|
||||
"</marker>" +
|
||||
"</container>";
|
||||
|
||||
var format = new OpenLayers.Format.XML({
|
||||
defaultPrefix: "foo",
|
||||
namespaces: {
|
||||
"foo": "http://example.com/foo",
|
||||
"atom": "http://www.w3.org/2005/Atom"
|
||||
},
|
||||
writers: {
|
||||
"foo": {
|
||||
"container": function(features) {
|
||||
var node = this.createElementNSPlus("container");
|
||||
var feature;
|
||||
for(var i=0; i<features.length; ++i) {
|
||||
feature = features[i];
|
||||
this.writeNode("marker", features[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"marker": function(feature) {
|
||||
var node = this.createElementNSPlus("marker", {
|
||||
attributes: {name: feature.attributes.name}
|
||||
});
|
||||
this.writeNode("position", feature.geometry, node);
|
||||
this.writeNode("detail", feature.attributes.detail, node);
|
||||
this.writeNode("atom:link", feature.attributes.link, node);
|
||||
return node;
|
||||
},
|
||||
"position": function(geometry) {
|
||||
var node = this.createElementNSPlus("position");
|
||||
this.writeNode("lon", geometry.x, node);
|
||||
this.writeNode("lat", geometry.y, node);
|
||||
return node;
|
||||
},
|
||||
"lon": function(x) {
|
||||
return this.createElementNSPlus("lon", {
|
||||
value: x
|
||||
});
|
||||
},
|
||||
"lat": function(y) {
|
||||
return this.createElementNSPlus("lat", {
|
||||
value: y
|
||||
});
|
||||
},
|
||||
"detail": function(text) {
|
||||
return this.createElementNSPlus("detail", {
|
||||
value: text
|
||||
});
|
||||
}
|
||||
},
|
||||
"atom": {
|
||||
"link": function(href) {
|
||||
return this.createElementNSPlus("atom:link", {
|
||||
attributes: {href: href}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
t.plan(1);
|
||||
// test that we get what we expect from writeNode
|
||||
var got = format.writeNode("container", features);
|
||||
t.xml_eq(got, expect, "features correctly written");
|
||||
}
|
||||
|
||||
function test_createElementNSPlus(t) {
|
||||
|
||||
var format = new OpenLayers.Format.XML({
|
||||
defaultPrefix: "def",
|
||||
namespaces: {
|
||||
"def": "http://example.com/default",
|
||||
"foo": "http://example.com/foo",
|
||||
"bar": "http://example.com/bar"
|
||||
}
|
||||
});
|
||||
|
||||
var cases = [
|
||||
{
|
||||
description: "unprefixed name with default options",
|
||||
node: format.createElementNSPlus("FooNode"),
|
||||
expect: "<def:FooNode xmlns:def='http://example.com/default'/>"
|
||||
}, {
|
||||
description: "def prefixed name with default options",
|
||||
node: format.createElementNSPlus("def:FooNode"),
|
||||
expect: "<def:FooNode xmlns:def='http://example.com/default'/>"
|
||||
}, {
|
||||
description: "foo prefixed name with default options",
|
||||
node: format.createElementNSPlus("foo:FooNode"),
|
||||
expect: "<foo:FooNode xmlns:foo='http://example.com/foo'/>"
|
||||
}, {
|
||||
description: "unprefixed name with uri option",
|
||||
node: format.createElementNSPlus("FooNode", {
|
||||
uri: "http://example.com/elsewhere"
|
||||
}),
|
||||
expect: "<FooNode xmlns='http://example.com/elsewhere'/>"
|
||||
}, {
|
||||
description: "foo prefixed name with uri option (overriding format.namespaces)",
|
||||
node: format.createElementNSPlus("foo:FooNode", {
|
||||
uri: "http://example.com/elsewhere"
|
||||
}),
|
||||
expect: "<foo:FooNode xmlns:foo='http://example.com/elsewhere'/>"
|
||||
}, {
|
||||
description: "foo prefixed name with attributes option",
|
||||
node: format.createElementNSPlus("foo:FooNode", {
|
||||
attributes: {
|
||||
"id": "123",
|
||||
"foo:attr1": "namespaced attribute 1",
|
||||
"bar:attr2": "namespaced attribute 2"
|
||||
}
|
||||
}),
|
||||
expect: "<foo:FooNode xmlns:foo='http://example.com/foo' xmlns:bar='http://example.com/bar' id='123' foo:attr1='namespaced attribute 1' bar:attr2='namespaced attribute 2'/>"
|
||||
}, {
|
||||
description: "foo prefixed name with attributes and value options",
|
||||
node: format.createElementNSPlus("foo:FooNode", {
|
||||
attributes: {"id": "123"},
|
||||
value: "text value"
|
||||
}),
|
||||
expect: "<foo:FooNode xmlns:foo='http://example.com/foo' id='123'>text value<" + "/foo:FooNode>"
|
||||
}
|
||||
];
|
||||
|
||||
t.plan(cases.length);
|
||||
var test;
|
||||
for(var i=0; i<cases.length; ++i) {
|
||||
test = cases[i];
|
||||
t.xml_eq(test.node, test.expect, test.description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_setAttributes(t) {
|
||||
|
||||
var format = new OpenLayers.Format.XML({
|
||||
defaultPrefix: "def",
|
||||
namespaces: {
|
||||
"def": "http://example.com/default",
|
||||
"foo": "http://example.com/foo",
|
||||
"bar": "http://example.com/bar"
|
||||
}
|
||||
});
|
||||
|
||||
var cases = [
|
||||
{
|
||||
description: "unprefixed attribute",
|
||||
node: format.createElementNSPlus("foo:Node"),
|
||||
attributes: {"id": "123"},
|
||||
expect: "<foo:Node xmlns:foo='http://example.com/foo' id='123'/>"
|
||||
}, {
|
||||
description: "foo prefixed attribute",
|
||||
node: format.createElementNSPlus("foo:Node"),
|
||||
attributes: {"foo:id": "123"},
|
||||
expect: "<foo:Node xmlns:foo='http://example.com/foo' foo:id='123'/>"
|
||||
}, {
|
||||
description: "foo prefixed attribute with def prefixed node",
|
||||
node: format.createElementNSPlus("def:Node"),
|
||||
attributes: {"foo:id": "123"},
|
||||
expect: "<def:Node xmlns:def='http://example.com/default' xmlns:foo='http://example.com/foo' foo:id='123'/>"
|
||||
}, {
|
||||
description: "multiple attributes",
|
||||
node: format.createElementNSPlus("def:Node"),
|
||||
attributes: {"id": "123", "foo": "bar"},
|
||||
expect: "<def:Node xmlns:def='http://example.com/default' id='123' foo='bar'/>"
|
||||
}
|
||||
];
|
||||
|
||||
t.plan(cases.length);
|
||||
var test;
|
||||
for(var i=0; i<cases.length; ++i) {
|
||||
test = cases[i];
|
||||
format.setAttributes(test.node, test.attributes);
|
||||
t.xml_eq(test.node, test.expect, test.description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -102,6 +102,35 @@
|
||||
};
|
||||
|
||||
var resp = protocol.read(readOptions);
|
||||
|
||||
OpenLayers.Request.GET = _get;
|
||||
}
|
||||
|
||||
function test_read_bbox(t) {
|
||||
t.plan(1);
|
||||
var protocol = new OpenLayers.Protocol.HTTP();
|
||||
|
||||
// fake XHR request object
|
||||
var request = {'status': 200};
|
||||
|
||||
var _get = OpenLayers.Request.GET;
|
||||
|
||||
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.BBOX,
|
||||
value: bounds,
|
||||
projection: "foo"
|
||||
});
|
||||
|
||||
OpenLayers.Request.GET = function(options) {
|
||||
t.eq(options.params['bbox'].toString(), bounds.toArray().toString(),
|
||||
'GET called with bbox filter in params');
|
||||
return request;
|
||||
};
|
||||
|
||||
var resp = protocol.read({filter: filter});
|
||||
|
||||
OpenLayers.Request.GET = _get;
|
||||
}
|
||||
|
||||
function test_parseFeatures(t) {
|
||||
@@ -217,6 +246,8 @@
|
||||
};
|
||||
|
||||
var resp = protocol.create(features, createOptions);
|
||||
|
||||
OpenLayers.Request.POST = _post;
|
||||
}
|
||||
|
||||
function test_update(t) {
|
||||
@@ -284,8 +315,10 @@
|
||||
};
|
||||
|
||||
var resp = protocol.update(feature, updateOptions);
|
||||
|
||||
|
||||
OpenLayers.Request.PUT = _put;
|
||||
}
|
||||
|
||||
function test_handleResponse(t) {
|
||||
t.plan(6);
|
||||
|
||||
@@ -404,6 +437,7 @@
|
||||
|
||||
var resp = protocol['delete'](feature, deleteOptions);
|
||||
|
||||
OpenLayers.Request.DELETE = _delete;
|
||||
}
|
||||
|
||||
function test_handleDelete(t) {
|
||||
|
||||
23
tests/Protocol/SQL.html
Normal file
23
tests/Protocol/SQL.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(3);
|
||||
var options = {tableName: 'my_features',
|
||||
databaseName: 'my_database_name'}
|
||||
var protocol = new OpenLayers.Protocol.SQL(options);
|
||||
|
||||
t.ok(protocol instanceof OpenLayers.Protocol.SQL,
|
||||
"new OpenLayers.Protocol.SQL returns object");
|
||||
|
||||
t.eq(protocol.tableName, options.tableName, "tableName property is set");
|
||||
t.eq(protocol.databaseName, options.databaseName, "databaseName property is set");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
473
tests/Protocol/SQL/Gears.html
Normal file
473
tests/Protocol/SQL/Gears.html
Normal file
@@ -0,0 +1,473 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(5);
|
||||
|
||||
t.eq(protocol.CLASS_NAME, "OpenLayers.Protocol.SQL.Gears",
|
||||
"ctor returns correct value");
|
||||
|
||||
t.eq(protocol.jsonParser.CLASS_NAME,
|
||||
"OpenLayers.Format.JSON",
|
||||
"ctor creates a JSON parser");
|
||||
|
||||
t.eq(protocol.wktParser.CLASS_NAME,
|
||||
"OpenLayers.Format.WKT",
|
||||
"ctor creates a WKT parser");
|
||||
|
||||
var str = protocol.FID_PREFIX + "foo_bar";
|
||||
t.ok(str.match(protocol.fidRegExp),
|
||||
"ctor creates correct regexp");
|
||||
|
||||
t.ok(typeof protocol.db == "object",
|
||||
"ctor creates a db object");
|
||||
|
||||
protocol.clear();
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_destroy(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(3);
|
||||
|
||||
protocol.destroy();
|
||||
|
||||
t.eq(protocol.db, null,
|
||||
"destroy nullifies db");
|
||||
t.eq(protocol.jsonParser, null,
|
||||
"destroy nullifies jsonParser");
|
||||
t.eq(protocol.wktParser, null,
|
||||
"destroy nullifies wktParser");
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
var protocolCallback, readCallback;
|
||||
var protocolOptions = {callback: protocolCallback};
|
||||
var readOptions = {callback: readCallback};
|
||||
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears(protocolOptions);
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
function okCallback(resp) {
|
||||
t.eq(resp.CLASS_NAME, "OpenLayers.Protocol.Response",
|
||||
"read calls correct callback with a response object");
|
||||
}
|
||||
|
||||
function failCallback(resp) {
|
||||
t.fail("read calls incorrect callback");
|
||||
}
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var resp;
|
||||
|
||||
// 2 tests
|
||||
protocolOptions.callback = okCallback;
|
||||
readOptions.callback = failCallback;
|
||||
resp = protocol.read();
|
||||
t.eq(resp.CLASS_NAME, "OpenLayers.Protocol.Response",
|
||||
"read returns a response object");
|
||||
|
||||
// 2 test
|
||||
protocolOptions.callback = failCallback;
|
||||
readOptions.callback = okCallback;
|
||||
resp = protocol.read(readOptions);
|
||||
t.eq(resp.CLASS_NAME, "OpenLayers.Protocol.Response",
|
||||
"read returns a response object");
|
||||
|
||||
protocol.clear();
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_unfreezeFeature(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(10);
|
||||
|
||||
var feature;
|
||||
var wkt, json, fid, state;
|
||||
|
||||
json = "{\"fake\":\"properties\"}";
|
||||
fid = "1000";
|
||||
state = OpenLayers.State.INSERT;
|
||||
|
||||
var row = {
|
||||
fieldByName: function(str) {
|
||||
if (str == "geometry") {
|
||||
return wkt;
|
||||
}
|
||||
if (str == "properties") {
|
||||
return json;
|
||||
}
|
||||
if (str == "fid") {
|
||||
return fid;
|
||||
}
|
||||
if (str == "state") {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 5 tests
|
||||
wkt = "POINT(1 2)";
|
||||
feature = protocol.unfreezeFeature(row);
|
||||
t.eq(feature.CLASS_NAME, "OpenLayers.Feature.Vector",
|
||||
"unfreezeFeature returns an OpenLayers.Feature.Vector");
|
||||
t.ok(feature.geometry.x == 1 && feature.geometry.y == 2,
|
||||
"unfreezeFeature returns a feature with correct geometry");
|
||||
t.eq(feature.attributes.fake, "properties",
|
||||
"unfreezeFeature returns a feature with correct attributes");
|
||||
t.eq(feature.fid, fid,
|
||||
"unfreezeFeature returns a feature with fid");
|
||||
t.eq(feature.state, state,
|
||||
"unfreezeFeature returns a feature with state");
|
||||
|
||||
// 5 tests
|
||||
wkt = protocol.NULL_GEOMETRY;
|
||||
state = protocol.NULL_FEATURE_STATE;
|
||||
feature = protocol.unfreezeFeature(row);
|
||||
t.eq(feature.CLASS_NAME, "OpenLayers.Feature.Vector",
|
||||
"unfreezeFeature returns an OpenLayers.Feature.Vector");
|
||||
t.eq(feature.geometry, null,
|
||||
"unfreezeFeature returns a feature with correct geometry");
|
||||
t.eq(feature.attributes.fake, "properties",
|
||||
"unfreezeFeature returns a feature with correct attributes");
|
||||
t.eq(feature.fid, fid,
|
||||
"unfreezeFeature returns a feature with fid");
|
||||
t.eq(feature.state, null,
|
||||
"unfreezeFeature returns a feature with state");
|
||||
|
||||
protocol.clear();
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_extractFidFromField(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var field, fid;
|
||||
|
||||
// fid is a string, field is not prefixed with FID_PREFIX
|
||||
// 1 test
|
||||
field = "10";
|
||||
res = protocol.extractFidFromField(field);
|
||||
t.eq(res, "10",
|
||||
"extractFidFromField returns expected string");
|
||||
|
||||
// fid is a string, field is prefixed with FID_PREFIX
|
||||
// 1 test
|
||||
field = protocol.FIX_PREFIX + "10";
|
||||
res = protocol.extractFidFromField(field);
|
||||
t.eq(res, protocol.FIX_PREFIX + "10",
|
||||
"extractFidFromField returns expected prefixed string");
|
||||
|
||||
// fid is a number, field is not prefixed with FIX_PREFIX
|
||||
// 1 test
|
||||
protocol.typeOfFid = "number";
|
||||
field = "10";
|
||||
res = protocol.extractFidFromField(field);
|
||||
t.eq(res, 10,
|
||||
"extractFidFromField returns expected number");
|
||||
|
||||
// fid is a number, field is prefixed with FIX_PREFIX
|
||||
// 1 test
|
||||
protocol.typeOfFid = "number";
|
||||
field = protocol.FID_PREFIX + "10";
|
||||
res = protocol.extractFidFromField(field);
|
||||
t.eq(res, protocol.FID_PREFIX + "10",
|
||||
"extractFidFromField returns expected prefixed string");
|
||||
}
|
||||
|
||||
function test_freezeFeature(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(8);
|
||||
|
||||
var feature, res;
|
||||
|
||||
// 4 tests
|
||||
feature = new OpenLayers.Feature.Vector();
|
||||
feature.geometry = new OpenLayers.Geometry.Point(1, 2);
|
||||
feature.attributes.fake = "properties";
|
||||
feature.fid = "1000";
|
||||
feature.state = OpenLayers.State.INSERT;
|
||||
res = protocol.freezeFeature(feature);
|
||||
t.eq(res[0], feature.fid,
|
||||
"freezeFeature returns correct fid");
|
||||
t.eq(res[1], "POINT(1 2)",
|
||||
"freezeFeature returns correct WKT");
|
||||
t.eq(res[2], "{\"fake\":\"properties\"}",
|
||||
"freezeFeature returns correct JSON");
|
||||
t.eq(res[3], feature.state,
|
||||
"freezeFeature returns correct feature state");
|
||||
|
||||
// 4 tests
|
||||
protocol.saveFeatureState = false;
|
||||
feature = new OpenLayers.Feature.Vector();
|
||||
feature.attributes.fake = "properties";
|
||||
feature.fid = "1000";
|
||||
feature.state = OpenLayers.State.INSERT;
|
||||
res = protocol.freezeFeature(feature);
|
||||
t.eq(res[0], feature.fid,
|
||||
"freezeFeature returns correct fid");
|
||||
t.eq(res[1], protocol.NULL_GEOMETRY,
|
||||
"freezeFeature returns expected null geom string");
|
||||
t.eq(res[2], "{\"fake\":\"properties\"}",
|
||||
"freezeFeature returns correct JSON");
|
||||
t.eq(res[3], protocol.NULL_FEATURE_STATE,
|
||||
"freezeFeature returns expected null feature state string");
|
||||
|
||||
protocol.clear();
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_create(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(8);
|
||||
|
||||
var resp;
|
||||
var scope = {"fake": "scope"};
|
||||
|
||||
var options = {
|
||||
callback: function(resp) {
|
||||
t.eq(resp.CLASS_NAME, "OpenLayers.Protocol.Response",
|
||||
"user callback is passed a response");
|
||||
t.eq(resp.requestType, "create",
|
||||
"user callback is passed correct request type in resp");
|
||||
t.ok(this == scope,
|
||||
"user callback called with correct scope");
|
||||
},
|
||||
scope: scope
|
||||
};
|
||||
|
||||
// 4 tests
|
||||
var feature = new OpenLayers.Feature.Vector();
|
||||
feature.fid = "1000";
|
||||
feature.attributes.fake = "properties";
|
||||
feature.state = OpenLayers.State.INSERT;
|
||||
resp = protocol.create([feature], options);
|
||||
t.eq(resp.CLASS_NAME, "OpenLayers.Protocol.Response",
|
||||
"create returns a response");
|
||||
|
||||
// check what we have in the DB
|
||||
// 4 tests
|
||||
resp = protocol.read({"noFeatureStateReset": true});
|
||||
t.eq(resp.features.length, 1,
|
||||
"create inserts feature in the DB");
|
||||
t.eq(resp.features[0].fid, feature.fid,
|
||||
"create inserts feature with correct fid");
|
||||
t.eq(resp.features[0].attributes.fake, feature.attributes.fake,
|
||||
"create inserts feature with correct attributes");
|
||||
t.eq(resp.features[0].state, feature.state,
|
||||
"create inserts feature with correct state");
|
||||
|
||||
protocol.clear();
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_createOrUpdate(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(5);
|
||||
|
||||
// 1 test
|
||||
var feature = new OpenLayers.Feature.Vector();
|
||||
feature.fid = "1000";
|
||||
feature.attributes.fake = "properties";
|
||||
feature.state = OpenLayers.State.INSERT;
|
||||
resp = protocol.createOrUpdate([feature]);
|
||||
t.eq(resp.CLASS_NAME, "OpenLayers.Protocol.Response",
|
||||
"createOrUpdate returns a response");
|
||||
|
||||
// check what we have in the DB
|
||||
// 4 tests
|
||||
resp = protocol.read({"noFeatureStateReset": true});
|
||||
t.eq(resp.features.length, 1,
|
||||
"createOrUpdate inserts feature in the DB");
|
||||
t.eq(resp.features[0].fid, feature.fid,
|
||||
"createOrUpdate inserts feature with correct fid");
|
||||
t.eq(resp.features[0].attributes.fake, feature.attributes.fake,
|
||||
"createOrUpdate inserts feature with correct attributes");
|
||||
t.eq(resp.features[0].state, feature.state,
|
||||
"createOrUpdate inserts feature with correct state");
|
||||
|
||||
protocol.clear();
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_delete(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(4);
|
||||
|
||||
function createOneAndDeleteOne(fid, deleteOptions) {
|
||||
var feature = new OpenLayers.Feature.Vector();
|
||||
feature.fid = fid;
|
||||
feature.attributes.fake = "properties";
|
||||
feature.state = OpenLayers.State.INSERT;
|
||||
var r = protocol.create([feature]);
|
||||
protocol["delete"](r.reqFeatures, deleteOptions);
|
||||
}
|
||||
|
||||
var resp, fid;
|
||||
|
||||
// 1 test
|
||||
fid = 1000;
|
||||
protocol.saveFeatureState = false;
|
||||
createOneAndDeleteOne(fid)
|
||||
resp = protocol.read();
|
||||
t.eq(resp.features.length, 0,
|
||||
"delete deletes feature if saveFeatureState is false");
|
||||
protocol.clear();
|
||||
|
||||
// 1 test
|
||||
fid = 1000;
|
||||
protocol.saveFeatureState = true;
|
||||
createOneAndDeleteOne(fid);
|
||||
resp = protocol.read();
|
||||
t.eq(resp.features.length, 1,
|
||||
"delete does not delete feature if saveFeatureState is true");
|
||||
protocol.clear();
|
||||
|
||||
// 1 test
|
||||
fid = "1000";
|
||||
protocol.saveFeatureState = true;
|
||||
createOneAndDeleteOne(fid);
|
||||
resp = protocol.read();
|
||||
t.eq(resp.features.length, 1,
|
||||
"delete does not delete feature if saveFeatureState is true");
|
||||
protocol.clear();
|
||||
|
||||
// 1 test
|
||||
fid = protocol.FID_PREFIX + "1000";
|
||||
protocol.saveFeatureState = true;
|
||||
createOneAndDeleteOne(fid, {dontDelete: true});
|
||||
resp = protocol.read();
|
||||
t.eq(resp.features.length, 0,
|
||||
"delete deletes feature if saveFeatureState is true and fid is prefixed");
|
||||
protocol.clear();
|
||||
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
function test_callUserCallback(t) {
|
||||
var protocol = new OpenLayers.Protocol.SQL.Gears();
|
||||
if (!protocol.supported()) {
|
||||
t.plan(0);
|
||||
return;
|
||||
}
|
||||
|
||||
t.plan(6);
|
||||
|
||||
var options, resp;
|
||||
var scope = {'fake': 'scope'};
|
||||
|
||||
// test commit callback
|
||||
// 1 tests
|
||||
options = {
|
||||
'callback': function() {
|
||||
t.ok(this == scope, 'callback called with correct scope');
|
||||
},
|
||||
'scope': scope
|
||||
};
|
||||
resp = {'requestType': 'create', 'last': true};
|
||||
protocol.callUserCallback(options, resp);
|
||||
// 0 test
|
||||
resp = {'requestType': 'create', 'last': false};
|
||||
protocol.callUserCallback(options, resp);
|
||||
|
||||
// test create callback
|
||||
// 2 tests
|
||||
options = {
|
||||
'create': {
|
||||
'callback': function(r) {
|
||||
t.ok(this == scope, 'callback called with correct scope');
|
||||
t.ok(r == resp, 'callback called with correct response');
|
||||
},
|
||||
'scope': scope
|
||||
}
|
||||
};
|
||||
resp = {'requestType': 'create'};
|
||||
protocol.callUserCallback(options, resp);
|
||||
|
||||
// test with both callbacks set
|
||||
// 3 tests
|
||||
options = {
|
||||
'create': {
|
||||
'callback': function(r) {
|
||||
t.ok(this == scope, 'callback called with correct scope');
|
||||
t.ok(r == resp, 'callback called with correct response');
|
||||
},
|
||||
'scope': scope
|
||||
},
|
||||
'callback': function() {
|
||||
t.ok(this == scope, 'callback called with correct scope');
|
||||
},
|
||||
'scope': scope
|
||||
};
|
||||
resp = {'requestType': 'create', 'last': true};
|
||||
protocol.callUserCallback(options, resp);
|
||||
|
||||
// no callback set
|
||||
// 0 test
|
||||
options = {
|
||||
'delete': {
|
||||
'callback': function(resp) {
|
||||
t.fail('callback should not get called');
|
||||
}
|
||||
}
|
||||
};
|
||||
resp = {'requestType': 'create'};
|
||||
protocol.callUserCallback(options, resp);
|
||||
|
||||
// cleanup
|
||||
protocol.destroy();
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -428,7 +428,8 @@
|
||||
'removeChild': function(elem) {
|
||||
gElemRemoved = elem;
|
||||
}
|
||||
}
|
||||
},
|
||||
'_style' : {backgroundGraphic: "foo"}
|
||||
};
|
||||
gBackElement = {
|
||||
'parentNode': {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
function test_issue(t) {
|
||||
setup();
|
||||
|
||||
t.plan(19);
|
||||
t.plan(22);
|
||||
var request, config;
|
||||
var proto = OpenLayers.Request.XMLHttpRequest.prototype;
|
||||
var issue = OpenLayers.Function.bind(OpenLayers.Request.issue,
|
||||
@@ -46,8 +46,43 @@
|
||||
t.eq(async, config.async, "open called with correct async");
|
||||
t.eq(user, config.user, "open called with correct user");
|
||||
t.eq(password, config.password, "open called with correct password");
|
||||
};
|
||||
request = issue(config);
|
||||
|
||||
// test that params are serialized as query string - 1 test
|
||||
config = {
|
||||
method: "GET",
|
||||
url: "http://example.com/",
|
||||
params: {"foo": "bar"}
|
||||
};
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
t.eq(url, config.url + "?foo=bar", "params serialized as query string");
|
||||
};
|
||||
request = issue(config);
|
||||
|
||||
// test that empty params object doesn't produce query string - 1 test
|
||||
config = {
|
||||
method: "GET",
|
||||
url: "http://example.com/",
|
||||
params: {}
|
||||
};
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
t.eq(url, config.url, "empty params doesn't produce query string");
|
||||
}
|
||||
request = issue(config);
|
||||
|
||||
// test that query string doesn't get two ? separators
|
||||
config = {
|
||||
method: "GET",
|
||||
url: "http://example.com/?existing=query",
|
||||
params: {"foo": "bar"}
|
||||
};
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
t.eq(url, config.url + "&foo=bar", "existing query string gets extended with &");
|
||||
}
|
||||
request = issue(config);
|
||||
|
||||
// reset open method
|
||||
proto.open = _open;
|
||||
|
||||
// test that headers are correctly set - 4 tests
|
||||
|
||||
166
tests/Strategy/BBOX.html
Normal file
166
tests/Strategy/BBOX.html
Normal file
@@ -0,0 +1,166 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(1);
|
||||
|
||||
var ratio = 4;
|
||||
|
||||
var s = new OpenLayers.Strategy.BBOX({ratio: ratio});
|
||||
t.eq(s.ratio, ratio, "ctor sets ratio");
|
||||
}
|
||||
|
||||
function test_activate(t) {
|
||||
t.plan(5);
|
||||
|
||||
var l = new OpenLayers.Layer.Vector();
|
||||
var s = new OpenLayers.Strategy.BBOX();
|
||||
s.setLayer(l);
|
||||
|
||||
t.eq(s.active, false, "not active after construction");
|
||||
|
||||
var activated = s.activate();
|
||||
t.eq(activated, true, "activate returns true");
|
||||
t.eq(s.active, true, "activated after activate");
|
||||
t.ok(l.events.listeners["moveend"][0].obj == s &&
|
||||
l.events.listeners["moveend"][0].func == s.update,
|
||||
"activates registers moveend listener");
|
||||
t.ok(l.events.listeners["refresh"][0].obj == s &&
|
||||
l.events.listeners["refresh"][0].func == s.update,
|
||||
"activates registers refresh listener");
|
||||
}
|
||||
|
||||
function test_update(t) {
|
||||
t.plan(6);
|
||||
|
||||
var s = new OpenLayers.Strategy.BBOX();
|
||||
|
||||
var invalidBoundsReturnValue;
|
||||
var bounds = new OpenLayers.Bounds(-100, -40, 100, 40);
|
||||
|
||||
s.invalidBounds = function(b) {
|
||||
t.ok(b == bounds,
|
||||
"update calls invalidBounds with correct arg");
|
||||
return invalidBoundsReturnValue;
|
||||
};
|
||||
s.calculateBounds = function(b) {
|
||||
t.ok(b == bounds,
|
||||
"update calls calculateBounds with correct arg");
|
||||
};
|
||||
s.triggerRead = function() {
|
||||
t.ok(true,
|
||||
"update calls triggerRead");
|
||||
};
|
||||
|
||||
s.setLayer({
|
||||
map: {
|
||||
getExtent: function() {
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 2 tests
|
||||
invalidBoundsReturnValue = true;
|
||||
s.update({force: true});
|
||||
|
||||
// 3 tests
|
||||
invalidBoundsReturnValue = true;
|
||||
s.update();
|
||||
|
||||
// 1 tests
|
||||
invalidBoundsReturnValue = false;
|
||||
s.update();
|
||||
}
|
||||
|
||||
function test_triggerRead(t) {
|
||||
t.plan(7);
|
||||
|
||||
var s = new OpenLayers.Strategy.BBOX();
|
||||
|
||||
var filter = {"fake": "filter"};
|
||||
|
||||
s.createFilter = function() {
|
||||
return filter;
|
||||
};
|
||||
|
||||
s.setLayer({
|
||||
protocol: {
|
||||
read: function(options) {
|
||||
t.ok(options.filter == filter,
|
||||
"protocol read called with correct filter");
|
||||
t.ok(options.callback == s.merge,
|
||||
"protocol read called with correct callback");
|
||||
t.ok(options.scope == s,
|
||||
"protocol read called with correct scope");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 3 tests
|
||||
s.triggerRead();
|
||||
|
||||
// 4 tests
|
||||
s.response = {
|
||||
priv: {
|
||||
abort: function() {
|
||||
t.ok(true,
|
||||
"triggerRead aborts previous read request");
|
||||
}
|
||||
}
|
||||
};
|
||||
s.triggerRead();
|
||||
}
|
||||
|
||||
function test_createFilter(t) {
|
||||
t.plan(3);
|
||||
|
||||
var s = new OpenLayers.Strategy.BBOX();
|
||||
|
||||
var f;
|
||||
|
||||
// 2 test
|
||||
s.setLayer({});
|
||||
f = s.createFilter();
|
||||
t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Spatial/) != -1,
|
||||
"createFilter returns a spatial filter object");
|
||||
t.eq(f.type, OpenLayers.Filter.Spatial.BBOX,
|
||||
"createFilter returns a BBOX-typed filter");
|
||||
|
||||
// 1 test
|
||||
s.setLayer({filter: {fake: "filter"}});
|
||||
f = s.createFilter();
|
||||
t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Logical/) != -1,
|
||||
"createFilter returns a logical filter object");
|
||||
}
|
||||
|
||||
function test_merge(t) {
|
||||
t.plan(2);
|
||||
|
||||
var s = new OpenLayers.Strategy.BBOX();
|
||||
|
||||
var features = ["fake", "feature", "array"];
|
||||
|
||||
s.setLayer({
|
||||
destroyFeatures: function() {
|
||||
t.ok(true,
|
||||
"merge calls destroyFeatures");
|
||||
},
|
||||
addFeatures: function(f) {
|
||||
t.ok(f == features,
|
||||
"merge calls addFeatures with the correct features");
|
||||
}
|
||||
});
|
||||
|
||||
// 2 tests
|
||||
s.merge({features: features});
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 400px; height: 200px" />
|
||||
</body>
|
||||
</html>
|
||||
108
tests/Strategy/Cluster.html
Normal file
108
tests/Strategy/Cluster.html
Normal file
@@ -0,0 +1,108 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_activate(t) {
|
||||
t.plan(2);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Cluster();
|
||||
t.eq(strategy.active, false, "not active after construction");
|
||||
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [strategy]
|
||||
});
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
|
||||
t.eq(strategy.active, true, "active after adding to map");
|
||||
}
|
||||
|
||||
function test_clusters(t) {
|
||||
t.plan(10);
|
||||
|
||||
function featuresEq(got, exp) {
|
||||
var eq = false;
|
||||
if(got instanceof Array && exp instanceof Array) {
|
||||
if(got.length === exp.length) {
|
||||
for(var i=0; i<got.length; ++i) {
|
||||
if(got[i] !== exp[i]) {
|
||||
console.log(got[i], exp[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
eq = (i == got.length);
|
||||
}
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Cluster();
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [strategy],
|
||||
isBaseLayer: true
|
||||
});
|
||||
var map = new OpenLayers.Map('map', {
|
||||
resolutions: [4, 2, 1],
|
||||
maxExtent: new OpenLayers.Bounds(-40, -40, 40, 40)
|
||||
});
|
||||
map.addLayer(layer);
|
||||
|
||||
// create features in a line, 1 unit apart
|
||||
var features = new Array(80);
|
||||
for(var i=0; i<80; ++i) {
|
||||
features[i] = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(-40 + i, 0)
|
||||
);
|
||||
}
|
||||
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
layer.addFeatures(features);
|
||||
|
||||
// resolution 4
|
||||
// threshold: 4 * 20 = 80 units
|
||||
// one cluster
|
||||
t.eq(layer.features.length, 1, "[4] layer has one cluster");
|
||||
t.ok(featuresEq(layer.features[0].cluster, features), "[4] cluster includes all features");
|
||||
|
||||
// resolution 2
|
||||
// threshold: 2 * 20 = 40 units
|
||||
// two clusters (41 and 39) - first cluster includes all features within 40 units of the first (0-40 or 41 features)
|
||||
map.zoomIn();
|
||||
t.eq(layer.features.length, 2, "[2] layer has two clusters");
|
||||
t.ok(featuresEq(layer.features[0].cluster, features.slice(0, 41)), "[2] first cluster includes first 41 features");
|
||||
t.ok(featuresEq(layer.features[1].cluster, features.slice(41, 80)), "[2] second cluster includes last 39 features");
|
||||
|
||||
// resolution 1
|
||||
// threshold: 1 * 20 = 20 units
|
||||
// four clusters (21, 21, 21, and 17)
|
||||
map.zoomIn();
|
||||
t.eq(layer.features.length, 4, "[1] layer has four clusters");
|
||||
t.ok(featuresEq(layer.features[0].cluster, features.slice(0, 21)), "[1] first cluster includes first 21 features");
|
||||
t.ok(featuresEq(layer.features[1].cluster, features.slice(21, 42)), "[2] second cluster includes second 21 features");
|
||||
t.ok(featuresEq(layer.features[2].cluster, features.slice(42, 63)), "[2] third cluster includes third 21 features");
|
||||
t.ok(featuresEq(layer.features[3].cluster, features.slice(63, 80)), "[2] fourth cluster includes last 17 features");
|
||||
}
|
||||
|
||||
function test_deactivate(t) {
|
||||
t.plan(2);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Cluster();
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [strategy]
|
||||
});
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
|
||||
t.eq(strategy.active, true, "active after adding to map");
|
||||
|
||||
map.removeLayer(layer);
|
||||
t.eq(strategy.active, false, "not active after removing from map");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 400px; height: 200px" />
|
||||
</body>
|
||||
</html>
|
||||
113
tests/Strategy/Paging.html
Normal file
113
tests/Strategy/Paging.html
Normal file
@@ -0,0 +1,113 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_activate(t) {
|
||||
t.plan(2);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Paging();
|
||||
t.eq(strategy.active, false, "not active after construction");
|
||||
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [strategy]
|
||||
});
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
|
||||
t.eq(strategy.active, true, "active after adding to map");
|
||||
}
|
||||
|
||||
function test_paging(t) {
|
||||
t.plan(18);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Paging();
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [strategy],
|
||||
drawFeature: function() {}
|
||||
});
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
|
||||
var features = new Array(25);
|
||||
for(var i=0; i<features.length; ++i) {
|
||||
features[i] = {destroy: function() {}};
|
||||
}
|
||||
|
||||
function featuresEq(got, exp) {
|
||||
var eq = false;
|
||||
if(got instanceof Array && exp instanceof Array) {
|
||||
if(got.length === exp.length) {
|
||||
for(var i=0; i<got.length; ++i) {
|
||||
if(got[i] !== exp[i]) {
|
||||
console.log(got[i], exp[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
eq = (i == got.length);
|
||||
}
|
||||
}
|
||||
return eq;
|
||||
}
|
||||
|
||||
var len = strategy.pageLength();
|
||||
t.eq(len, 10, "page length defaults to 10");
|
||||
|
||||
// add 25 features to the layer
|
||||
layer.addFeatures(features);
|
||||
t.eq(strategy.features.length, features.length, "strategy caches all features");
|
||||
t.eq(layer.features.length, len, "layer gets one page of features");
|
||||
t.ok(featuresEq(layer.features, features.slice(0, len)), "layer gets first page initially");
|
||||
t.eq(strategy.pageNum(), 0, "strategy reports 0 based page number");
|
||||
t.eq(strategy.pageCount(), Math.ceil(features.length / len), "strategy reports correct number of pages");
|
||||
|
||||
// load next page of features
|
||||
var changed = strategy.pageNext();
|
||||
t.eq(changed, true, "(1) strategy reports change");
|
||||
t.eq(strategy.pageNum(), 1, "second page");
|
||||
t.ok(featuresEq(layer.features, features.slice(len, 2*len)), "layer has second page of features");
|
||||
|
||||
// load next page of features (half page)
|
||||
changed = strategy.pageNext();
|
||||
t.eq(changed, true, "(2) strategy reports change");
|
||||
t.eq(strategy.pageNum(), 2, "third page");
|
||||
|
||||
// try to change forward again
|
||||
changed = strategy.pageNext();
|
||||
t.eq(changed, false, "strategy reports no change");
|
||||
t.eq(layer.features.length, features.length % len, "layer has partial page");
|
||||
t.ok(featuresEq(layer.features, features.slice(2*len, 3*len)), "layer has third page of features");
|
||||
t.eq(strategy.pageNum(), 2, "still on third page");
|
||||
|
||||
// change back a page
|
||||
changed = strategy.pagePrevious();
|
||||
t.eq(changed, true, "(3) strategy reports change");
|
||||
t.eq(strategy.pageNum(), 1, "back on second page");
|
||||
t.ok(featuresEq(layer.features, features.slice(len, 2*len)), "layer has second page of features again");
|
||||
|
||||
layer.destroy();
|
||||
|
||||
}
|
||||
|
||||
function test_deactivate(t) {
|
||||
t.plan(2);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Paging();
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [strategy]
|
||||
});
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
|
||||
t.eq(strategy.active, true, "active after adding to map");
|
||||
|
||||
map.removeLayer(layer);
|
||||
t.eq(strategy.active, false, "not active after removing from map");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 400px; height: 200px" />
|
||||
</body>
|
||||
</html>
|
||||
110
tests/geom_eq.js
Normal file
110
tests/geom_eq.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* File: xml_eq.js
|
||||
* Adds a xml_eq method to AnotherWay test objects.
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* Function assertEqual
|
||||
* Test two objects for equivalence (based on ==). Throw an exception
|
||||
* if not equivalent.
|
||||
*
|
||||
* Parameters:
|
||||
* got - {Object}
|
||||
* expected - {Object}
|
||||
* msg - {String} The message to be thrown. This message will be appended
|
||||
* with ": got {got} but expected {expected}" where got and expected are
|
||||
* replaced with string representations of the above arguments.
|
||||
*/
|
||||
function assertEqual(got, expected, msg) {
|
||||
if(got === undefined) {
|
||||
got = "undefined";
|
||||
} else if (got === null) {
|
||||
got = "null";
|
||||
}
|
||||
if(expected === undefined) {
|
||||
expected = "undefined";
|
||||
} else if (expected === null) {
|
||||
expected = "null";
|
||||
}
|
||||
if(got != expected) {
|
||||
throw msg + ": got '" + got + "' but expected '" + expected + "'";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function assertGeometryEqual
|
||||
* Test two geometries for equivalence. Geometries are considered
|
||||
* equivalent if they are of the same class, and given component
|
||||
* geometries, if all components are equivalent. Throws a message as
|
||||
* exception if not equivalent.
|
||||
*
|
||||
* Parameters:
|
||||
* got - {OpenLayers.Geometry}
|
||||
* expected - {OpenLayers.Geometry}
|
||||
* options - {Object} Optional object for configuring test options.
|
||||
*/
|
||||
function assertGeometryEqual(got, expected, options) {
|
||||
|
||||
var OpenLayers = Test.AnotherWay._g_test_iframe.OpenLayers;
|
||||
|
||||
// compare types
|
||||
assertEqual(typeof got, typeof expected, "Object types mismatch");
|
||||
|
||||
// compare classes
|
||||
assertEqual(got.CLASS_NAME, expected.CLASS_NAME, "Object class mismatch");
|
||||
|
||||
if(got instanceof OpenLayers.Geometry.Point) {
|
||||
// compare points
|
||||
assertEqual(got.x, expected.x, "x mismatch");
|
||||
assertEqual(got.y, expected.y, "y mismatch");
|
||||
assertEqual(got.z, expected.z, "z mismatch");
|
||||
} else {
|
||||
// compare components
|
||||
assertEqual(
|
||||
got.components.length, expected.components.length,
|
||||
"Component length mismatch for " + got.CLASS_NAME
|
||||
);
|
||||
for(var i=0; i<got.components.length; ++i) {
|
||||
try {
|
||||
assertGeometryEqual(
|
||||
got.components[i], expected.components[i], options
|
||||
);
|
||||
} catch(err) {
|
||||
throw "Bad component " + i + " for " + got.CLASS_NAME + ": " + err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: Test.AnotherWay._test_object_t.geom_eq
|
||||
* Test if two geometry objects are equivalent. Tests for same geometry
|
||||
* class, same number of components (if any), equivalent component
|
||||
* geometries, and same coordinates.
|
||||
*
|
||||
* (code)
|
||||
* t.geom_eq(got, expected, message);
|
||||
* (end)
|
||||
*
|
||||
* Parameters:
|
||||
* got - {OpenLayers.Geometry} Any geometry instance.
|
||||
* expected - {OpenLayers.Geometry} The expected geometry.
|
||||
* msg - {String} A message to print with test output.
|
||||
* options - {Object} Optional object for configuring test options.
|
||||
*/
|
||||
var proto = Test.AnotherWay._test_object_t.prototype;
|
||||
proto.geom_eq = function(got, expected, msg, options) {
|
||||
// test geometries for equivalence
|
||||
try {
|
||||
assertGeometryEqual(got, expected, options);
|
||||
this.ok(true, msg);
|
||||
} catch(err) {
|
||||
this.fail(msg + ": " + err);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -43,6 +43,8 @@
|
||||
<li>Format/GeoJSON.html</li>
|
||||
<li>Format/GeoRSS.html</li>
|
||||
<li>Format/GML.html</li>
|
||||
<li>Format/GML/v2.html</li>
|
||||
<li>Format/GML/v3.html</li>
|
||||
<li>Format/GPX.html</li>
|
||||
<li>Format/JSON.html</li>
|
||||
<li>Format/KML.html</li>
|
||||
@@ -115,6 +117,8 @@
|
||||
<li>Projection.html</li>
|
||||
<li>Protocol.html</li>
|
||||
<li>Protocol/HTTP.html</li>
|
||||
<li>Protocol/SQL.html</li>
|
||||
<li>Protocol/SQL/Gears.html</li>
|
||||
<li>Renderer.html</li>
|
||||
<li>Renderer/Canvas.html</li>
|
||||
<li>Renderer/Elements.html</li>
|
||||
@@ -124,7 +128,10 @@
|
||||
<li>Request/XMLHttpRequest.html</li>
|
||||
<li>Rule.html</li>
|
||||
<li>Strategy.html</li>
|
||||
<li>Strategy/Cluster.html</li>
|
||||
<li>Strategy/Fixed.html</li>
|
||||
<li>Strategy/Paging.html</li>
|
||||
<li>Strategy/BBOX.html</li>
|
||||
<li>Style.html</li>
|
||||
<li>StyleMap.html</li>
|
||||
<li>Tile.html</li>
|
||||
|
||||
@@ -2307,6 +2307,7 @@ onload=function()
|
||||
// -->
|
||||
</script>
|
||||
<script type="text/javascript" src="xml_eq.js"></script>
|
||||
<script type="text/javascript" src="geom_eq.js"></script>
|
||||
</head><body>
|
||||
|
||||
<div id="col1">
|
||||
|
||||
@@ -97,10 +97,13 @@
|
||||
* Parameters:
|
||||
* got - {DOMElement}
|
||||
* expected - {DOMElement}
|
||||
* options - {Object} Optional object for configuring test options. Set
|
||||
* 'prefix' property to true in order to compare element and attribute
|
||||
* prefixes (namespace uri always tested). By default, prefixes
|
||||
* are not tested.
|
||||
* options - {Object} Optional object for configuring test options.
|
||||
*
|
||||
* Valid options:
|
||||
* prefix - {Boolean} Compare element and attribute
|
||||
* prefixes (namespace uri always tested). Default is false.
|
||||
* includeWhiteSpace - {Boolean} Include whitespace only nodes when
|
||||
* comparing child nodes. Default is false.
|
||||
*/
|
||||
function assertElementNodesEqual(got, expected, options) {
|
||||
var testPrefix = (options && options.prefix === true);
|
||||
@@ -190,14 +193,17 @@
|
||||
}
|
||||
|
||||
// compare children
|
||||
var gotChildNodes = getChildNodes(got, options);
|
||||
var expChildNodes = getChildNodes(expected, options);
|
||||
|
||||
assertEqual(
|
||||
got.childNodes.length, expected.childNodes.length,
|
||||
gotChildNodes.length, expChildNodes.length,
|
||||
"Children length mismatch for " + got.nodeName
|
||||
);
|
||||
for(var j=0; j<got.childNodes.length; ++j) {
|
||||
for(var j=0; j<gotChildNodes.length; ++j) {
|
||||
try {
|
||||
assertElementNodesEqual(
|
||||
got.childNodes[j], expected.childNodes[j]
|
||||
gotChildNodes[j], expChildNodes[j], options
|
||||
);
|
||||
} catch(err) {
|
||||
throw "Bad child " + j + " for element " + got.nodeName + ": " + err;
|
||||
@@ -206,6 +212,50 @@
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function getChildNodes
|
||||
* Returns the child nodes of the specified nodes. By default this method
|
||||
* will ignore child text nodes which are made up of whitespace content.
|
||||
* The 'includeWhiteSpace' option is used to control this behaviour.
|
||||
*
|
||||
* Parameters:
|
||||
* node - {DOMElement}
|
||||
* options - {Object} Optional object for test configuration.
|
||||
*
|
||||
* Valid options:
|
||||
* includeWhiteSpace - {Boolean} Include whitespace only nodes when
|
||||
* comparing child nodes. Default is false.
|
||||
*
|
||||
* Returns:
|
||||
* {Array} of {DOMElement}
|
||||
*/
|
||||
function getChildNodes(node, options) {
|
||||
//check whitespace
|
||||
if (options && options.includeWhiteSpace) {
|
||||
return node.childNodes;
|
||||
}
|
||||
else {
|
||||
nodes = [];
|
||||
for (var i = 0; i < node.childNodes.length; i++ ) {
|
||||
var child = node.childNodes[i];
|
||||
if (child.nodeType == 1) {
|
||||
//element node, add it
|
||||
nodes.push(child);
|
||||
}
|
||||
else if (child.nodeType == 3) {
|
||||
//text node, add if non empty
|
||||
if (child.nodeValue &&
|
||||
child.nodeValue.replace(/^\s*(.*?)\s*$/, "$1") != "" ) {
|
||||
|
||||
nodes.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function: Test.AnotherWay._test_object_t.xml_eq
|
||||
@@ -221,10 +271,13 @@
|
||||
* got - {DOMElement | String} A DOM node or XML string to test.
|
||||
* expected - {DOMElement | String} The expected DOM node or XML string.
|
||||
* msg - {String} A message to print with test output.
|
||||
* options - {Object} Optional object for configuring test options. Set
|
||||
* 'prefix' property to true in order to compare element and attribute
|
||||
* prefixes (namespace uri always tested). By default, prefixes
|
||||
* are not tested.
|
||||
* options - {Object} Optional object for configuring test.
|
||||
*
|
||||
* Valid options:
|
||||
* prefix - {Boolean} Compare element and attribute
|
||||
* prefixes (namespace uri always tested). Default is false.
|
||||
* includeWhiteSpace - {Boolean} Include whitespace only nodes when
|
||||
* comparing child nodes. Default is false.
|
||||
*/
|
||||
var proto = Test.AnotherWay._test_object_t.prototype;
|
||||
proto.xml_eq = function(got, expected, msg, options) {
|
||||
@@ -255,4 +308,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user