@@ -20,13 +20,19 @@ class OAuth2SummitTracksApiTest extends ProtectedApiTestCase
2020{
2121 use InsertSummitTestData;
2222
23- use InsertMemberTestData;
24-
2523 protected function setUp ():void
2624 {
2725 $ this ->setCurrentGroup (IGroup::TrackChairs);
2826 parent ::setUp ();
27+ self ::$ defaultMember = self ::$ member ;
2928 self ::insertSummitTestData ();
29+ self ::$ summit_permission_group ->addMember (self ::$ member );
30+ self ::$ em ->persist (self ::$ summit );
31+ self ::$ em ->persist (self ::$ summit_permission_group );
32+ self ::$ em ->flush ();
33+ self ::$ summit ->addTrackChair (self ::$ member , [ self ::$ defaultTrack ] );
34+ self ::$ em ->persist (self ::$ summit );
35+ self ::$ em ->flush ();
3036 }
3137
3238 protected function tearDown ():void
@@ -62,11 +68,125 @@ public function testGetAllTracksPerSummit(){
6268 $ content = $ response ->getContent ();
6369 $ this ->assertResponseStatus (200 );
6470 $ tracks = json_decode ($ content );
65- $ this ->assertTrue (! is_null ( $ tracks) );
66- $ this ->assertTrue ( $ tracks ->total == 1 );
71+ $ this ->assertNotNull ( $ tracks );
72+ $ this ->assertGreaterThan ( 0 , $ tracks ->total );
6773 return $ tracks ;
6874 }
6975
76+ public function testGetAllTracksPerSummitCSV (){
77+ $ params = [
78+ 'id ' => self ::$ summit ->getId (),
79+ ];
80+
81+ $ headers = [
82+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
83+ ];
84+
85+ $ response = $ this ->action (
86+ "GET " ,
87+ "OAuth2SummitTracksApiController@getAllBySummitCSV " ,
88+ $ params ,
89+ [],
90+ [],
91+ [],
92+ $ headers
93+ );
94+
95+ $ this ->assertResponseStatus (200 );
96+ $ content = $ response ->getContent ();
97+ $ this ->assertNotEmpty ($ content );
98+ }
99+
100+ public function testGetAllTracksPerSummitWithFilter (){
101+ $ params = [
102+ 'id ' => self ::$ summit ->getId (),
103+ 'filter ' => sprintf ('name=@%s ' , substr (self ::$ defaultTrack ->getTitle (), 0 , 5 )),
104+ ];
105+
106+ $ headers = [
107+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
108+ ];
109+
110+ $ response = $ this ->action (
111+ "GET " ,
112+ "OAuth2SummitTracksApiController@getAllBySummit " ,
113+ $ params ,
114+ [],
115+ [],
116+ [],
117+ $ headers
118+ );
119+
120+ $ content = $ response ->getContent ();
121+ $ this ->assertResponseStatus (200 );
122+ $ tracks = json_decode ($ content );
123+ $ this ->assertNotNull ($ tracks );
124+ }
125+
126+ public function testAddTrack (){
127+ $ params = [
128+ 'id ' => self ::$ summit ->getId (),
129+ ];
130+
131+ $ name = str_random (16 ).'_track ' ;
132+ $ data = [
133+ 'name ' => $ name ,
134+ 'description ' => 'test track description ' ,
135+ 'code ' => str_random (4 ),
136+ ];
137+
138+ $ headers = [
139+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
140+ "CONTENT_TYPE " => "application/json "
141+ ];
142+
143+ $ response = $ this ->action (
144+ "POST " ,
145+ "OAuth2SummitTracksApiController@addTrackBySummit " ,
146+ $ params ,
147+ [],
148+ [],
149+ [],
150+ $ headers ,
151+ json_encode ($ data )
152+ );
153+
154+ $ content = $ response ->getContent ();
155+ $ this ->assertResponseStatus (201 );
156+ $ track = json_decode ($ content );
157+ $ this ->assertNotNull ($ track );
158+ $ this ->assertEquals ($ name , $ track ->name );
159+ return $ track ;
160+ }
161+
162+ public function testGetTrackById (){
163+ $ params = [
164+ 'id ' => self ::$ summit ->getId (),
165+ 'track_id ' => self ::$ defaultTrack ->getId (),
166+ 'expand ' => 'track_groups,allowed_tags ' ,
167+ ];
168+
169+ $ headers = [
170+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
171+ ];
172+
173+ $ response = $ this ->action (
174+ "GET " ,
175+ "OAuth2SummitTracksApiController@getTrackBySummit " ,
176+ $ params ,
177+ [],
178+ [],
179+ [],
180+ $ headers
181+ );
182+
183+ $ content = $ response ->getContent ();
184+ $ this ->assertResponseStatus (200 );
185+ $ track = json_decode ($ content );
186+ $ this ->assertNotNull ($ track );
187+ $ this ->assertEquals (self ::$ defaultTrack ->getId (), $ track ->id );
188+ }
189+
70190 public function testUpdateProposedScheduleTransitionTime (){
71191
72192 $ params = [
@@ -97,15 +217,169 @@ public function testUpdateProposedScheduleTransitionTime(){
97217 $ content = $ response ->getContent ();
98218 $ this ->assertResponseStatus (201 );
99219 $ track = json_decode ($ content );
100- $ this ->assertTrue (! is_null ( $ track) );
220+ $ this ->assertNotNull ( $ track );
101221 }
102222
103- public function testAddSubTrack (){
223+ public function testDeleteNewTrack (){
224+ $ new_track = $ this ->testAddTrack ();
225+
226+ $ params = [
227+ 'id ' => self ::$ summit ->getId (),
228+ 'track_id ' => $ new_track ->id ,
229+ ];
230+
231+ $ headers = [
232+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
233+ ];
234+
235+ $ response = $ this ->action (
236+ "DELETE " ,
237+ "OAuth2SummitTracksApiController@deleteTrackBySummit " ,
238+ $ params ,
239+ [],
240+ [],
241+ [],
242+ $ headers
243+ );
244+
245+ $ this ->assertResponseStatus (204 );
246+ }
247+
248+ public function testGetTrackAllowedTags (){
249+ $ params = [
250+ 'id ' => self ::$ summit ->getId (),
251+ 'track_id ' => self ::$ defaultTrack ->getId (),
252+ ];
253+
254+ $ headers = [
255+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
256+ ];
257+
258+ $ response = $ this ->action (
259+ "GET " ,
260+ "OAuth2SummitTracksApiController@getTrackAllowedTagsBySummit " ,
261+ $ params ,
262+ [],
263+ [],
264+ [],
265+ $ headers
266+ );
267+
268+ $ content = $ response ->getContent ();
269+ $ this ->assertResponseStatus (200 );
270+ $ data = json_decode ($ content );
271+ $ this ->assertNotNull ($ data );
272+ }
273+
274+ public function testGetTrackExtraQuestions (){
275+ $ params = [
276+ 'id ' => self ::$ summit ->getId (),
277+ 'track_id ' => self ::$ defaultTrack ->getId (),
278+ ];
279+
280+ $ headers = [
281+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
282+ ];
283+
284+ $ response = $ this ->action (
285+ "GET " ,
286+ "OAuth2SummitTracksApiController@getTrackExtraQuestionsBySummit " ,
287+ $ params ,
288+ [],
289+ [],
290+ [],
291+ $ headers
292+ );
293+
294+ $ content = $ response ->getContent ();
295+ $ this ->assertResponseStatus (200 );
296+ $ data = json_decode ($ content );
297+ $ this ->assertNotNull ($ data );
298+ }
299+
300+ public function testAddTrackIconMissingFile (){
301+ $ params = [
302+ 'id ' => self ::$ summit ->getId (),
303+ 'track_id ' => self ::$ defaultTrack ->getId (),
304+ ];
305+
306+ $ headers = [
307+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
308+ ];
104309
310+ $ response = $ this ->action (
311+ "POST " ,
312+ "OAuth2SummitTracksApiController@addTrackIcon " ,
313+ $ params ,
314+ [],
315+ [],
316+ [],
317+ $ headers
318+ );
319+
320+ $ this ->assertResponseStatus (412 );
321+ }
322+
323+ public function testDeleteTrackIcon (){
105324 $ params = [
106325 'id ' => self ::$ summit ->getId (),
107326 'track_id ' => self ::$ defaultTrack ->getId (),
108- 'child_track_id ' => self ::$ defaultTrack ->getId ()
327+ ];
328+
329+ $ headers = [
330+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
331+ ];
332+
333+ $ response = $ this ->action (
334+ "DELETE " ,
335+ "OAuth2SummitTracksApiController@deleteTrackIcon " ,
336+ $ params ,
337+ [],
338+ [],
339+ [],
340+ $ headers
341+ );
342+
343+ $ this ->assertResponseStatus (204 );
344+ }
345+
346+ private function createTrackWithCode ($ code ){
347+ $ params = ['id ' => self ::$ summit ->getId ()];
348+
349+ $ data = [
350+ 'name ' => str_random (16 ).'_track ' ,
351+ 'description ' => 'test desc ' ,
352+ 'code ' => $ code ,
353+ ];
354+
355+ $ headers = [
356+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
357+ "CONTENT_TYPE " => "application/json "
358+ ];
359+
360+ $ response = $ this ->action (
361+ "POST " ,
362+ "OAuth2SummitTracksApiController@addTrackBySummit " ,
363+ $ params ,
364+ [],
365+ [],
366+ [],
367+ $ headers ,
368+ json_encode ($ data )
369+ );
370+
371+ $ this ->assertResponseStatus (201 );
372+ return json_decode ($ response ->getContent ());
373+ }
374+
375+ public function testAddSubTrack (){
376+ $ parent = $ this ->createTrackWithCode ('P ' . str_random (4 ));
377+ $ child = $ this ->createTrackWithCode ('C ' . str_random (4 ));
378+
379+ $ params = [
380+ 'id ' => self ::$ summit ->getId (),
381+ 'track_id ' => $ parent ->id ,
382+ 'child_track_id ' => $ child ->id ,
109383 ];
110384
111385 $ data = [
@@ -131,15 +405,17 @@ public function testAddSubTrack(){
131405 $ content = $ response ->getContent ();
132406 $ this ->assertResponseStatus (201 );
133407 $ track = json_decode ($ content );
134- $ this ->assertTrue (!is_null ($ track ));
408+ $ this ->assertNotNull ($ track );
409+ return ['parent_id ' => $ parent ->id , 'child_id ' => $ child ->id ];
135410 }
136411
137412 public function testRemoveSubTrack (){
413+ $ result = $ this ->testAddSubTrack ();
138414
139415 $ params = [
140- 'id ' => self ::$ summit ->getId (),
141- 'track_id ' => self :: $ defaultTrack -> getId () ,
142- 'child_track_id ' => self :: $ defaultTrack -> getId ()
416+ 'id ' => self ::$ summit ->getId (),
417+ 'track_id ' => $ result [ ' parent_id ' ] ,
418+ 'child_track_id ' => $ result [ ' child_id ' ],
143419 ];
144420
145421 $ headers = [
@@ -157,7 +433,6 @@ public function testRemoveSubTrack(){
157433 $ headers
158434 );
159435
160- $ content = $ response ->getContent ();
161436 $ this ->assertResponseStatus (204 );
162437 }
163- }
438+ }
0 commit comments