@@ -26,16 +26,17 @@ public function setUp()
26
26
}
27
27
28
28
/** Invoke the JSON web API */
29
- private function _callJsonApi ()
29
+ private function _callJsonApi ($ sessionUser = null )
30
30
{
31
- $ this ->dispatchUrI ($ this ->webroot .'api/json ' );
32
- return json_decode ($ this ->response -> getBody ());
31
+ $ this ->dispatchUrI ($ this ->webroot .'api/json ' , $ sessionUser );
32
+ return json_decode ($ this ->getBody ());
33
33
}
34
34
35
35
/** Make sure we got a good response from a web API call */
36
36
private function _assertStatusOk ($ resp )
37
37
{
38
38
$ this ->assertNotEquals ($ resp , false );
39
+ $ this ->assertEquals ($ resp ->message , '' );
39
40
$ this ->assertEquals ($ resp ->stat , 'ok ' );
40
41
$ this ->assertEquals ($ resp ->code , 0 );
41
42
$ this ->assertTrue (isset ($ resp ->data ));
@@ -184,4 +185,30 @@ public function testUserApikeyDefault()
184
185
185
186
$ this ->assertEquals ($ resp ->data ->apikey , $ apiKey );
186
187
}
188
+
189
+ /** Test that we can authenticate to the web API using the user session */
190
+ public function testSessionAuthentication ()
191
+ {
192
+ $ usersFile = $ this ->loadData ('User ' , 'default ' );
193
+ $ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
194
+
195
+ $ this ->resetAll ();
196
+ $ this ->params = array ();
197
+ $ this ->params ['method ' ] = 'midas.user.folders ' ;
198
+ $ this ->params ['useSession ' ] = 'true ' ;
199
+ $ this ->request ->setMethod ('POST ' );
200
+ $ resp = $ this ->_callJsonApi ($ userDao );
201
+ $ this ->_assertStatusOk ($ resp );
202
+
203
+ // We should see the user's folders
204
+ $ this ->assertEquals (count ($ resp ->data ), 2 );
205
+
206
+ foreach ($ resp ->data as $ folder )
207
+ {
208
+ $ this ->assertEquals ($ folder ->_model , 'Folder ' );
209
+ $ this ->assertEquals ($ folder ->parent_id , 1000 );
210
+ }
211
+ $ this ->assertEquals ($ resp ->data [0 ]->name , 'User 1 name Folder 2 ' );
212
+ $ this ->assertEquals ($ resp ->data [1 ]->name , 'User 1 name Folder 3 ' );
213
+ }
187
214
}
0 commit comments