~fabiocbalbuquerque/sahana-agasti/web-services

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
include(dirname(__FILE__).'/../../bootstrap/functional.php');

/**
 * @see apps/frontend/lib/packages/agWebservicesPackage/config/routing.yml
 * @see apps/frontend/lib/packages/agWebservicesPackage/data/fixtures.yml
 */

$browser = new sfTestFunctional(new sfBrowser());

$browser->
  info(sprintf('Testing routes - without authentication'))->
  get('/webservices/')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'index')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    checkElement('#web_service', 'Web Services')->
    checkElement('#staff_link', 'Staff')->
    checkElement('#organizations_link', 'Organizations')->
    end()->
  get('/webservices/index')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'index')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    checkElement('#web_service', 'Web Services')->
    checkElement('#staff_link', 'Staff')->
    checkElement('#organizations_link', 'Organizations')->
    end()->
    
  get('/webservices/list/staff')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'list')->
    isParameter('datapoint', 'staff')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    checkElement('#columns h2', 'Staff Listing')->
    checkElement('thead tr th', 'Id')->
    end()->
    
  get('/webservices/list/organizations')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'list')->
    isParameter('datapoint', 'organizations')->
    end()->    
  with('response')->begin()->
    isStatusCode(200)->
    checkElement('#columns h2', 'Organizations Listing')->
    checkElement('thead tr th', 'Id')->
    end()->
    
  info(sprintf('Accessing route /webservices/list with a wrong datapoint'))->
  get('/webservices/list/person')->
  with('response')->begin()->
    isStatusCode(404)->
    end()->
    
  info(sprintf('Staff in XML - valid token'))->
  get('/webservices/staff.xml/agasti')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'agasti')->
    isParameter('datapoint', 'staff')->
    isParameter('sf_format', 'xml')->
    isFormat('xml')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    isValid()->
    isHeader('Content-type', 'text/xml; charset=utf-8')->
    checkElement('entity[type="staff"]', true)->
    end()->
    
  info(sprintf('Organizations in XML - valid token'))->
  get('/webservices/organizations.xml/agasti')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'agasti')->
    isParameter('datapoint', 'organizations')->
    isParameter('sf_format', 'xml')->
    isFormat('xml')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    isValid()->
    isHeader('Content-type', 'text/xml; charset=utf-8')->
    checkElement('entity[type="organizations"]', true)->
    end()->
    
  info(sprintf('Staff in JSON - valid token'))->
  get('/webservices/staff.json/agasti')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'agasti')->
    isParameter('datapoint', 'staff')->
    isParameter('sf_format', 'json')->
    isFormat('json')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    isHeader('Content-type', 'application/json')->
    matches('/"type"\:"staff"/')->
    matches('/"id"\:"\d+"/')->
    matches('/"person_id"\:"\d+"/')->
    end()->
    
  info(sprintf('Organizations in JSON - valid token'))->
  get('/webservices/organizations.json/agasti')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'agasti')->
    isParameter('datapoint', 'organizations')->
    isParameter('sf_format', 'json')->
    isFormat('json')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    isHeader('Content-type', 'application/json')->
    matches('/"type"\:"organizations"/')->
    matches('/"id"\:"\d+"/')->
  	matches('/"entity_id"\:"\d+"/')->
    end()->
    
  info(sprintf('Try to reach datapoint with invalid token'))->
  get('/webservices/organizations.json/invalid_token')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'invalid_token')->
    isParameter('datapoint', 'organizations')->
    isParameter('sf_format', 'json')->
    isFormat('json')->
    end()->
  with('response')->begin()->
    isStatusCode(404)->
    end()->
    
  info(sprintf('Try to reach datapoint with inactive client'))->
  get('/webservices/organizations.json/inactive_client')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'inactive_client')->
    isParameter('datapoint', 'organizations')->
    isParameter('sf_format', 'json')->
    isFormat('json')->
    end()->
  with('response')->begin()->
    isStatusCode(404)->
    end()->

  info(sprintf('Filter data through query params'))->
  get('/webservices/staff.json/agasti/is_available=1&limit=10&person=1&order=staff')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'agasti')->
    isParameter('datapoint', 'staff')->
    isParameter('sf_format', 'json')->
    isParameter('url_param', 'is_available=1&limit=10&person=1&order=staff')->
    isFormat('json')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    matches('/"type"\:"staff"/')->
    matches('/"id"\:"\d+"/')->
    matches('/"person_id"\:"1"/')->
    matches('/"is_available"\:true/')->
    end()->

  info(sprintf('Filter data through query params - no results'))->
  get('/webservices/staff.xml/agasti/limit=0&is_available=0&person=1&order=staff')->
  with('request')->begin()->
    isParameter('module', 'agWebservices')->
    isParameter('action', 'get')->
    isParameter('token', 'agasti')->
    isParameter('datapoint', 'staff')->
    isParameter('sf_format', 'xml')->
    isParameter('url_param', 'limit=0&is_available=0&person=1&order=staff')->
    isFormat('xml')->
    end()->
  with('response')->begin()->
    isStatusCode(200)->
    isValid()->
    isHeader('Content-type', 'text/xml; charset=utf-8')->
    checkElement('results', true)->
    end()
;