summaryrefslogtreecommitdiff
path: root/includes/js/dojo/tests/rpc.js
blob: 09c8ef2a1b603f84b1f94b31f3b14d3876e3120c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
if(!dojo._hasResource["tests.rpc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["tests.rpc"] = true;
dojo.provide("tests.rpc");

dojo.require("dojo.rpc.RpcService");
dojo.require("dojo.rpc.JsonService");
dojo.require("dojo.rpc.JsonpService");

doh.register("tests.rpc", 
	[ 

		{
			name: "JsonRPC-EchoTest",
			timeout: 2000,
			setUp: function(){

				var testSmd = {
					serviceURL:"../../dojo/tests/resources/test_JsonRPCMediator.php",
					methods:[
						{
							name:"myecho",
							parameters:[
								{
									name:"somestring",
									type:"STRING"
								}
							]
						}
					]	
				}
			
				this.svc = new dojo.rpc.JsonService(testSmd);
			},
			runTest: function(){
				var d = new doh.Deferred();
				var td = this.svc.myecho("RPC TEST");

				if (window.location.protocol=="file:") {
					var err= new Error("This Test requires a webserver and PHP and will fail intentionally if loaded from file://");
					d.errback(err);
					return d;
				}

				td.addCallbacks(function(result) {
					if(result=="<P>RPC TEST</P>"){
						return true;
					}else{
						return new Error("JsonRpc-EchoTest test failed, resultant content didn't match");
					}
				}, function(result){
					return new Error(result);
				});

				td.addBoth(d, "callback");

				return d;
			}

		},

		{
			name: "JsonRPC-EmptyParamTest",
			timeout: 2000,
			setUp: function(){
				var testSmd={
					serviceURL:"../../dojo/tests/resources/test_JsonRPCMediator.php",
					methods:[ { name:"contentB" } ]	
				}
			
				this.svc = new dojo.rpc.JsonService(testSmd);
			},
			runTest: function(){
				var d = new doh.Deferred();
				var td = this.svc.contentB();

				if (window.location.protocol=="file:") {
					var err= new Error("This Test requires a webserver and PHP and will fail intentionally if loaded from file://");
					d.errback(err);
					return d;
				}

				td.addCallbacks(function(result){
					if(result=="<P>Content B</P>"){
						return true;
					}else{
						return new Error("JsonRpc-EmpytParamTest test failed, resultant content didn't match");
					}
				}, function(result){
					return new Error(result);
				});

				td.addBoth(d, "callback");

				return d;
			}
		},

		{
			name: "JsonRPC_SMD_Loading_test",
			setUp: function(){
				this.svc = new dojo.rpc.JsonService("../../dojo/tests/resources/testClass.smd");
			},
			runTest: function(){

				if (this.svc.objectName=="testClass") {
					return true;
				} else {
					return new Error("Error loading and/or parsing an smd file");
				}
			}
		},

		{
			name: "JsonP_test",
			timeout: 10000,
			setUp: function(){
				this.svc = new dojo.rpc.JsonpService(dojo.moduleUrl("dojo.tests.resources","yahoo_smd_v1.smd"), {appid: "foo"});
			},
			runTest: function(){
				var d = new doh.Deferred();

				if (window.location.protocol=="file:") {
					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
					d.errback(err);
					return d;
				}

				var td = this.svc.webSearch({query:"dojotoolkit"});

				td.addCallbacks(function(result){
					return true;
					if (result["ResultSet"]["Result"][0]["DisplayUrl"]=="dojotoolkit.org/") {
						return true;
					}else{
						return new Error("JsonRpc_SMD_Loading_Test failed, resultant content didn't match");
					}
				}, function(result){
					return new Error(result);
				});

				td.addBoth(d, "callback");

				return d;
			}
		}
	]
);



}