| | 11 | |
|---|
| | 12 | // 4 tests |
|---|
| | 13 | t.eq(a.url, "foo", "constructor sets url"); |
|---|
| | 14 | t.eq(a.options.url, a.url, "constructor copies url to options.url"); |
|---|
| | 15 | t.eq(a.params, {}, "constructor sets params"); |
|---|
| | 16 | t.eq(a.options.params, undefined, "constructor do not copy params to options.params"); |
|---|
| | 17 | |
|---|
| | 18 | var params = {hello: "world"}; |
|---|
| 16 | | t.eq(a.url, "foo", "constructor set url."); |
|---|
| 17 | | t.eq(a.options.url, a.url, "constructor copy url to options.url."); |
|---|
| 18 | | t.eq(a.params, {}, "constructor set params."); |
|---|
| 19 | | t.eq(a.options.params, undefined, |
|---|
| 20 | | "constructor do not copy params to options.params."); |
|---|
| 21 | | |
|---|
| 22 | | t.eq(b.url, "bar", "constructor set url."); |
|---|
| 23 | | t.eq(b.options.url, b.url, "constructor copy url to options.url."); |
|---|
| 24 | | t.eq(b.params, {hello: "world"}, "constructor set params."); |
|---|
| 25 | | t.eq(b.options.params, b.params, |
|---|
| 26 | | "constructor copy param to options.params."); |
|---|
| | 24 | // 4 tests |
|---|
| | 25 | t.eq(b.url, "bar", "constructor sets url"); |
|---|
| | 26 | t.eq(b.options.url, b.url, "constructor copies url to options.url"); |
|---|
| | 27 | t.eq(b.params, params, "constructor sets params"); |
|---|
| | 28 | t.eq(b.options.params, b.params, "constructor copies params to options.params"); |
|---|
| 36 | | t.eq(protocol.options, null, "destroy nullify options"); |
|---|
| 37 | | t.eq(protocol.params, null, "destroy nullify params"); |
|---|
| 38 | | t.eq(protocol.headers, null, "destroy nullify headers"); |
|---|
| | 38 | t.eq(protocol.options, null, "destroy nullifies options"); |
|---|
| | 39 | t.eq(protocol.params, null, "destroy nullifies params"); |
|---|
| | 40 | t.eq(protocol.headers, null, "destroy nullifies headers"); |
|---|
| 42 | | t.plan(0); |
|---|
| 43 | | // TBD |
|---|
| | 44 | t.plan(9); |
|---|
| | 45 | var protocol = new OpenLayers.Protocol.HTTP({ |
|---|
| | 46 | 'url': 'foo_url', |
|---|
| | 47 | 'params': {'k': 'foo_param'} |
|---|
| | 48 | }); |
|---|
| | 49 | |
|---|
| | 50 | // fake XHR request object |
|---|
| | 51 | var request = {'status': 200}; |
|---|
| | 52 | |
|---|
| | 53 | var url = 'bar_url'; |
|---|
| | 54 | var params = {'k': 'bar_param'}; |
|---|
| | 55 | var headers = {'k': 'bar_header'}; |
|---|
| | 56 | var scope = {'hello': 'world'}; |
|---|
| | 57 | var callback = function(resp) { |
|---|
| | 58 | // 4 tests |
|---|
| | 59 | t.ok(this == scope, |
|---|
| | 60 | 'callback is called with the correct scope'); |
|---|
| | 61 | t.eq(resp.CLASS_NAME, 'OpenLayers.Protocol.Response', |
|---|
| | 62 | 'callback is passed a Response object'); |
|---|
| | 63 | t.ok(resp.priv == request, |
|---|
| | 64 | 'callback is passed the request in the Response object'); |
|---|
| | 65 | t.eq(resp.code, OpenLayers.Protocol.Response.SUCCESS, |
|---|
| | 66 | 'callback is passed the correct code in the Response object'); |
|---|
| | 67 | }; |
|---|
| | 68 | |
|---|
| | 69 | var _get = OpenLayers.Request.GET; |
|---|
| | 70 | |
|---|
| | 71 | OpenLayers.Request.GET = function(options) { |
|---|
| | 72 | // 5 tests |
|---|
| | 73 | t.eq(options.url, url, 'protocol url overriden by read url'); |
|---|
| | 74 | t.eq(options.params['k'], params['k'], 'protocol params overriden by read params'); |
|---|
| | 75 | t.eq(options.headers['k'], headers['k'], 'protocol headers correctly sets'); |
|---|
| | 76 | t.ok(typeof options.callback == 'function', 'read passes a callback function to Request.GET'); |
|---|
| | 77 | t.ok(options.scope == protocol, 'read passed correct scope to Request.GET'); |
|---|
| | 78 | // call callback |
|---|
| | 79 | options.callback.call(options.scope, request); |
|---|
| | 80 | }; |
|---|
| | 81 | protocol.read({ |
|---|
| | 82 | 'url': url, 'params': params, 'headers': headers, 'callback': callback, 'scope': scope |
|---|
| | 83 | }); |
|---|
| | 84 | |
|---|
| | 85 | // cleanup |
|---|
| | 86 | protocol.destroy(); |
|---|
| | 87 | OpenLayers.Request.GET = _get; |
|---|