[OpenLayers-Commits] r7352 - sandbox/vector-behavior/tests/Protocol
commits at openlayers.org
commits at openlayers.org
Wed Jun 11 11:13:30 EDT 2008
Author: elemoine
Date: 2008-06-11 11:13:30 -0400 (Wed, 11 Jun 2008)
New Revision: 7352
Modified:
sandbox/vector-behavior/tests/Protocol/HTTP.html
Log:
improve HTTP protocol test coverage
Modified: sandbox/vector-behavior/tests/Protocol/HTTP.html
===================================================================
--- sandbox/vector-behavior/tests/Protocol/HTTP.html 2008-06-11 14:19:11 UTC (rev 7351)
+++ sandbox/vector-behavior/tests/Protocol/HTTP.html 2008-06-11 15:13:30 UTC (rev 7352)
@@ -8,22 +8,24 @@
var a = new OpenLayers.Protocol.HTTP({
url: "foo"
});
+
+ // 4 tests
+ t.eq(a.url, "foo", "constructor sets url");
+ t.eq(a.options.url, a.url, "constructor copies url to options.url");
+ t.eq(a.params, {}, "constructor sets params");
+ t.eq(a.options.params, undefined, "constructor do not copy params to options.params");
+
+ var params = {hello: "world"};
var b = new OpenLayers.Protocol.HTTP({
url: "bar",
- params: {hello: "world"}
+ params: params
});
- t.eq(a.url, "foo", "constructor set url.");
- t.eq(a.options.url, a.url, "constructor copy url to options.url.");
- t.eq(a.params, {}, "constructor set params.");
- t.eq(a.options.params, undefined,
- "constructor do not copy params to options.params.");
-
- t.eq(b.url, "bar", "constructor set url.");
- t.eq(b.options.url, b.url, "constructor copy url to options.url.");
- t.eq(b.params, {hello: "world"}, "constructor set params.");
- t.eq(b.options.params, b.params,
- "constructor copy param to options.params.");
+ // 4 tests
+ t.eq(b.url, "bar", "constructor sets url");
+ t.eq(b.options.url, b.url, "constructor copies url to options.url");
+ t.eq(b.params, params, "constructor sets params");
+ t.eq(b.options.params, b.params, "constructor copies params to options.params");
}
function test_Protocol_HTTP_destroy(t) {
@@ -33,14 +35,56 @@
params: {hello: "world"}
});
protocol.destroy();
- t.eq(protocol.options, null, "destroy nullify options");
- t.eq(protocol.params, null, "destroy nullify params");
- t.eq(protocol.headers, null, "destroy nullify headers");
+ t.eq(protocol.options, null, "destroy nullifies options");
+ t.eq(protocol.params, null, "destroy nullifies params");
+ t.eq(protocol.headers, null, "destroy nullifies headers");
}
function test_Protocol_HTTP_read(t) {
- t.plan(0);
- // TBD
+ t.plan(9);
+ var protocol = new OpenLayers.Protocol.HTTP({
+ 'url': 'foo_url',
+ 'params': {'k': 'foo_param'}
+ });
+
+ // fake XHR request object
+ var request = {'status': 200};
+
+ var url = 'bar_url';
+ var params = {'k': 'bar_param'};
+ var headers = {'k': 'bar_header'};
+ var scope = {'hello': 'world'};
+ var callback = function(resp) {
+ // 4 tests
+ t.ok(this == scope,
+ 'callback is called with the correct scope');
+ t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response',
+ 'callback is passed a Response object');
+ t.ok(resp.priv == request,
+ 'callback is passed the request in the Response object');
+ t.eq(resp.code, OpenLayers.Protocol.Response.SUCCESS,
+ 'callback is passed the correct code in the Response object');
+ };
+
+ var _get = OpenLayers.Request.GET;
+
+ OpenLayers.Request.GET = function(options) {
+ // 5 tests
+ t.eq(options.url, url, 'protocol url overriden by read url');
+ t.eq(options.params['k'], params['k'], 'protocol params overriden by read params');
+ t.eq(options.headers['k'], headers['k'], 'protocol headers correctly sets');
+ t.ok(typeof options.callback == 'function', 'read passes a callback function to Request.GET');
+ t.ok(options.scope == protocol, 'read passed correct scope to Request.GET');
+ // call callback
+ options.callback.call(options.scope, request);
+ };
+ protocol.read({
+ 'url': url, 'params': params, 'headers': headers, 'callback': callback, 'scope': scope
+ });
+
+ // cleanup
+ protocol.destroy();
+ OpenLayers.Request.GET = _get;
}
</script>
More information about the Commits
mailing list