@@ -59,7 +59,7 @@ public function testAddAllowedLocation2Track()
5959 ];
6060
6161 $ payload = [
62- 'location_id ' => self ::$ mainVenue ->getId ()
62+ 'location_id ' => self ::$ venue_rooms [ 0 ] ->getId ()
6363 ];
6464
6565 $ response = $ this ->action (
@@ -97,7 +97,7 @@ public function testAddTimeFrame()
9797 ];
9898
9999 $ payload = [
100- 'day ' => \DateTime:: createFromFormat ( ' Ymd H:i:s ' , ' 20230518 00:00:00 ' )->getTimestamp (),
100+ 'day ' => ( clone self :: $ summit -> getBeginDate ())-> add ( new \ DateInterval ( " P2D " ) )->getTimestamp (),
101101 ];
102102
103103 $ response = $ this ->action (
@@ -115,7 +115,7 @@ public function testAddTimeFrame()
115115 $ this ->assertResponseStatus (201 );
116116 $ time_frame = json_decode ($ content );
117117 $ this ->assertTrue (!is_null ($ time_frame ));
118- $ this ->assertTrue ($ time_frame ->day == $ payload [ ' day ' ] );
118+ $ this ->assertTrue (! is_null ( $ time_frame ->day ) );
119119 return $ time_frame ;
120120 }
121121
@@ -135,7 +135,7 @@ public function testAddTimeFrameTwice()
135135 ];
136136
137137 $ payload = [
138- 'day ' => \DateTime:: createFromFormat ( ' Ymd H:i:s ' , ' 20230518 00:00:00 ' )->getTimestamp (),
138+ 'day ' => ( clone self :: $ summit -> getBeginDate ())-> add ( new \ DateInterval ( " P2D " ) )->getTimestamp (),
139139 ];
140140
141141 $ response = $ this ->action (
@@ -153,7 +153,7 @@ public function testAddTimeFrameTwice()
153153 $ this ->assertResponseStatus (201 );
154154 $ time_frame = json_decode ($ content );
155155 $ this ->assertTrue (!is_null ($ time_frame ));
156- $ this ->assertTrue ($ time_frame ->day == $ payload [ ' day ' ] );
156+ $ this ->assertTrue (! is_null ( $ time_frame ->day ) );
157157
158158 $ response = $ this ->action (
159159 "POST " ,
@@ -197,7 +197,7 @@ public function testGetAllByTrack()
197197 $ this ->assertResponseStatus (200 );
198198 $ page = json_decode ($ content );
199199 $ this ->assertTrue (!is_null ($ page ));
200- $ this ->assertTrue ($ page ->total > 1 );
200+ $ this ->assertTrue ($ page ->total >= 1 );
201201 }
202202
203203 public function testAddTimeFrameAndThenGetIt ()
@@ -259,7 +259,223 @@ public function testGetAllTimeFramesByAllowedLocation(){
259259 $ this ->assertResponseStatus (200 );
260260 $ page = json_decode ($ content );
261261 $ this ->assertTrue (!is_null ($ page ));
262- $ this ->assertTrue ($ page ->total > 1 );
262+ $ this ->assertTrue ($ page ->total >= 1 );
263+ }
264+
265+ public function testGetAllowedLocationById ()
266+ {
267+ $ allowed_location = $ this ->testAddAllowedLocation2Track ();
268+
269+ $ params = [
270+ 'id ' => self ::$ summit ->getId (),
271+ 'track_id ' => self ::$ defaultTrack ->getId (),
272+ 'location_id ' => $ allowed_location ->id ,
273+ ];
274+
275+ $ headers = [
276+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
277+ "CONTENT_TYPE " => "application/json "
278+ ];
279+
280+ $ response = $ this ->action (
281+ "GET " ,
282+ "OAuth2SummitProposedScheduleAllowedLocationApiController@getAllowedLocationFromTrack " ,
283+ $ params ,
284+ [],
285+ [],
286+ [],
287+ $ headers
288+ );
289+
290+ $ content = $ response ->getContent ();
291+ $ this ->assertResponseStatus (200 );
292+ $ fetched = json_decode ($ content );
293+ $ this ->assertTrue (!is_null ($ fetched ));
294+ $ this ->assertTrue ($ fetched ->id == $ allowed_location ->id );
295+ }
296+
297+ public function testRemoveAllowedLocationFromTrack ()
298+ {
299+ $ allowed_location = $ this ->testAddAllowedLocation2Track ();
300+
301+ $ params = [
302+ 'id ' => self ::$ summit ->getId (),
303+ 'track_id ' => self ::$ defaultTrack ->getId (),
304+ 'location_id ' => $ allowed_location ->id ,
305+ ];
306+
307+ $ headers = [
308+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
309+ "CONTENT_TYPE " => "application/json "
310+ ];
311+
312+ $ response = $ this ->action (
313+ "DELETE " ,
314+ "OAuth2SummitProposedScheduleAllowedLocationApiController@removeAllowedLocationFromTrack " ,
315+ $ params ,
316+ [],
317+ [],
318+ [],
319+ $ headers
320+ );
321+
322+ $ this ->assertResponseStatus (204 );
323+ }
324+
325+ public function testRemoveAllAllowedLocationsFromTrack ()
326+ {
327+ // add two allowed locations
328+ $ this ->testAddAllowedLocation2Track ();
329+
330+ $ params = [
331+ 'id ' => self ::$ summit ->getId (),
332+ 'track_id ' => self ::$ defaultTrack ->getId (),
333+ ];
334+
335+ $ headers = [
336+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
337+ "CONTENT_TYPE " => "application/json "
338+ ];
339+
340+ $ response = $ this ->action (
341+ "DELETE " ,
342+ "OAuth2SummitProposedScheduleAllowedLocationApiController@removeAllAllowedLocationFromTrack " ,
343+ $ params ,
344+ [],
345+ [],
346+ [],
347+ $ headers
348+ );
349+
350+ $ this ->assertResponseStatus (204 );
351+
352+ // verify all removed
353+ $ response = $ this ->action (
354+ "GET " ,
355+ "OAuth2SummitProposedScheduleAllowedLocationApiController@getAllAllowedLocationByTrack " ,
356+ $ params ,
357+ [],
358+ [],
359+ [],
360+ $ headers
361+ );
362+
363+ $ content = $ response ->getContent ();
364+ $ this ->assertResponseStatus (200 );
365+ $ page = json_decode ($ content );
366+ $ this ->assertTrue ($ page ->total == 0 );
367+ }
368+
369+ public function testRemoveTimeFrameFromAllowedLocation ()
370+ {
371+ $ time_frame = $ this ->testAddTimeFrame ();
372+
373+ $ params = [
374+ 'id ' => self ::$ summit ->getId (),
375+ 'track_id ' => self ::$ defaultTrack ->getId (),
376+ 'location_id ' => $ time_frame ->allowed_location_id ,
377+ 'time_frame_id ' => $ time_frame ->id ,
378+ ];
379+
380+ $ headers = [
381+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
382+ "CONTENT_TYPE " => "application/json "
383+ ];
384+
385+ $ response = $ this ->action (
386+ "DELETE " ,
387+ "OAuth2SummitProposedScheduleAllowedLocationApiController@removeTimeFrameFromAllowedLocation " ,
388+ $ params ,
389+ [],
390+ [],
391+ [],
392+ $ headers
393+ );
394+
395+ $ this ->assertResponseStatus (204 );
396+ }
397+
398+ public function testRemoveAllTimeFramesFromAllowedLocation ()
399+ {
400+ $ time_frame = $ this ->testAddTimeFrame ();
401+
402+ $ params = [
403+ 'id ' => self ::$ summit ->getId (),
404+ 'track_id ' => self ::$ defaultTrack ->getId (),
405+ 'location_id ' => $ time_frame ->allowed_location_id ,
406+ ];
407+
408+ $ headers = [
409+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
410+ "CONTENT_TYPE " => "application/json "
411+ ];
412+
413+ $ response = $ this ->action (
414+ "DELETE " ,
415+ "OAuth2SummitProposedScheduleAllowedLocationApiController@removeAllTimeFrameFromAllowedLocation " ,
416+ $ params ,
417+ [],
418+ [],
419+ [],
420+ $ headers
421+ );
422+
423+ $ this ->assertResponseStatus (204 );
424+
425+ // verify all removed
426+ $ response = $ this ->action (
427+ "GET " ,
428+ "OAuth2SummitProposedScheduleAllowedLocationApiController@getAllTimeFrameFromAllowedLocation " ,
429+ $ params ,
430+ [],
431+ [],
432+ [],
433+ $ headers
434+ );
435+
436+ $ content = $ response ->getContent ();
437+ $ this ->assertResponseStatus (200 );
438+ $ page = json_decode ($ content );
439+ $ this ->assertTrue ($ page ->total == 0 );
440+ }
441+
442+ public function testUpdateTimeFrame ()
443+ {
444+ $ time_frame = $ this ->testAddTimeFrame ();
445+
446+ $ params = [
447+ 'id ' => self ::$ summit ->getId (),
448+ 'track_id ' => self ::$ defaultTrack ->getId (),
449+ 'location_id ' => $ time_frame ->allowed_location_id ,
450+ 'time_frame_id ' => $ time_frame ->id ,
451+ ];
452+
453+ $ headers = [
454+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
455+ "CONTENT_TYPE " => "application/json "
456+ ];
457+
458+ $ new_day = (clone self ::$ summit ->getBeginDate ())->add (new \DateInterval ("P5D " ))->getTimestamp ();
459+
460+ $ payload = [
461+ 'day ' => $ new_day ,
462+ ];
463+
464+ $ response = $ this ->action (
465+ "PUT " ,
466+ "OAuth2SummitProposedScheduleAllowedLocationApiController@updateTimeFrameFromAllowedLocation " ,
467+ $ params ,
468+ [],
469+ [],
470+ [],
471+ $ headers ,
472+ json_encode ($ payload )
473+ );
474+
475+ $ content = $ response ->getContent ();
476+ $ this ->assertResponseStatus (201 );
477+ $ updated = json_decode ($ content );
478+ $ this ->assertTrue (!is_null ($ updated ));
263479 }
264480
265481}
0 commit comments