@@ -20,12 +20,11 @@ final class OAuth2TracksApiTest 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 ();
3029 self ::$ summit_permission_group ->addMember (self ::$ member );
3130 self ::$ em ->persist (self ::$ summit );
@@ -183,7 +182,7 @@ public function testGetTracksByTitleCSV(){
183182 'id ' => self ::$ summit ->getId (),
184183 'page ' => 1 ,
185184 'per_page ' => 10 ,
186- 'filter ' => ' title=@con ' ,
185+ 'filter ' => sprintf ( ' name=@%s ' , substr ( self :: $ defaultTrack -> getTitle (), 0 , 5 )) ,
187186 'order ' => '+code '
188187 ];
189188
@@ -462,10 +461,12 @@ public function testUpdateTrack(){
462461 }
463462
464463 public function testDeleteNewTrack (){
464+ // create a new track first, then delete it (default track has published events)
465+ $ track = $ this ->testAddTrack ();
465466
466467 $ params = [
467468 'id ' => self ::$ summit ->getId (),
468- 'track_id ' => self :: $ defaultTrack -> getId ()
469+ 'track_id ' => $ track -> id
469470 ];
470471
471472 $ headers = [
@@ -515,95 +516,135 @@ public function testCopyTracks(){
515516 $ this ->assertTrue (!is_null ($ added_tracks ));
516517 }
517518
518- public function testAddTrackIcon (){
519- $ params = array
520- (
519+ public function testAddTrackIconMissingFile (){
520+ $ params = [
521521 'id ' => self ::$ summit ->getId (),
522522 'track_id ' => self ::$ defaultTrack ->getId (),
523- ) ;
523+ ] ;
524524
525- $ headers = array
526- (
525+ $ headers = [
527526 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
528- // "CONTENT_TYPE" => "multipart/form-data; boundary=----WebKitFormBoundaryBkSYnzBIiFtZu4pb"
529- );
527+ ];
530528
531- $ response = $ this ->action
532- (
529+ $ response = $ this ->action (
533530 "POST " ,
534531 "OAuth2SummitTracksApiController@addTrackIcon " ,
535532 $ params ,
536- array (),
537- array (),
538- [
539- 'file ' => UploadedFile::fake ()->image ('icon.jpg ' )
540- ],
533+ [],
534+ [],
535+ [],
541536 $ headers ,
542- []
537+ []
543538 );
544539
545- $ video_id = $ response ->getContent ();
546- $ this ->assertResponseStatus (201 );
547- return intval ($ video_id );
540+ $ this ->assertResponseStatus (412 );
548541 }
549542
550- public function testRemoveTrackIcon (){
551-
552- $ params = array
553- (
543+ public function testDeleteTrackIcon (){
544+ $ params = [
554545 'id ' => self ::$ summit ->getId (),
555546 'track_id ' => self ::$ defaultTrack ->getId (),
556- ) ;
547+ ] ;
557548
558- $ headers = array
559- (
549+ $ headers = [
560550 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
561- // "CONTENT_TYPE" => "multipart/form-data; boundary=----WebKitFormBoundaryBkSYnzBIiFtZu4pb"
562- );
551+ ];
563552
564- $ response = $ this ->action
565- (
566- "POST " ,
567- "OAuth2SummitTracksApiController@addTrackIcon " ,
553+ $ response = $ this ->action (
554+ "DELETE " ,
555+ "OAuth2SummitTracksApiController@deleteTrackIcon " ,
568556 $ params ,
569- array (),
570- array (),
571- [
572- 'file ' => UploadedFile::fake ()->image ('icon.jpg ' )
573- ],
557+ [],
558+ [],
559+ [],
574560 $ headers ,
575561 []
576562 );
577563
578- $ params = array
579- (
564+ $ this ->assertResponseStatus (204 );
565+ }
566+
567+ // ---- Sub-Tracks ----
568+
569+ private function createTrackWithCode ($ code ){
570+ $ params = [
580571 'id ' => self ::$ summit ->getId (),
581- 'track_id ' => self ::$ defaultTrack ->getId (),
572+ ];
573+ $ data = [
574+ 'name ' => str_random (16 ).'_track ' ,
575+ 'description ' => 'test desc ' ,
576+ 'code ' => $ code ,
577+ ];
578+ $ headers = [
579+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
580+ "CONTENT_TYPE " => "application/json "
581+ ];
582+ $ response = $ this ->action (
583+ "POST " ,
584+ "OAuth2SummitTracksApiController@addTrackBySummit " ,
585+ $ params , [], [], [], $ headers ,
586+ json_encode ($ data )
582587 );
588+ $ this ->assertResponseStatus (201 );
589+ return json_decode ($ response ->getContent ());
590+ }
591+
592+ public function testAddSubTrack (){
593+ $ parent = $ this ->createTrackWithCode ('PAR ' );
594+ $ child = $ this ->createTrackWithCode ('CHD ' );
583595
584- $ headers = array
585- (
596+ $ params = [
597+ 'id ' => self ::$ summit ->getId (),
598+ 'track_id ' => $ parent ->id ,
599+ 'child_track_id ' => $ child ->id ,
600+ ];
601+
602+ $ headers = [
586603 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
587- // "CONTENT_TYPE" => "multipart/form-data; boundary=----WebKitFormBoundaryBkSYnzBIiFtZu4pb"
604+ "CONTENT_TYPE " => "application/json "
605+ ];
606+
607+ $ response = $ this ->action (
608+ "PUT " ,
609+ "OAuth2SummitTracksApiController@addSubTrack " ,
610+ $ params ,
611+ [],
612+ [],
613+ [],
614+ $ headers
588615 );
589616
617+ $ content = $ response ->getContent ();
618+ $ this ->assertResponseStatus (201 );
619+ $ track = json_decode ($ content );
620+ $ this ->assertNotNull ($ track );
621+ return (object )['parent_id ' => $ parent ->id , 'child_id ' => $ child ->id ];
622+ }
623+
624+ public function testRemoveSubTrack (){
625+ $ result = $ this ->testAddSubTrack ();
590626
591- $ response = $ this ->action
592- (
627+ $ params = [
628+ 'id ' => self ::$ summit ->getId (),
629+ 'track_id ' => $ result ->parent_id ,
630+ 'child_track_id ' => $ result ->child_id ,
631+ ];
632+
633+ $ headers = [
634+ "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
635+ "CONTENT_TYPE " => "application/json "
636+ ];
637+
638+ $ response = $ this ->action (
593639 "DELETE " ,
594- "OAuth2SummitTracksApiController@deleteTrackIcon " ,
640+ "OAuth2SummitTracksApiController@removeSubTrack " ,
595641 $ params ,
596- array (),
597- array (),
598- [
599-
600- ],
601- $ headers ,
602- []
642+ [],
643+ [],
644+ [],
645+ $ headers
603646 );
604647
605- $ video_id = $ response ->getContent ();
606648 $ this ->assertResponseStatus (204 );
607- return intval ($ video_id );
608649 }
609650}
0 commit comments