@@ -827,6 +827,76 @@ class TestAssignmentsPresenter extends Tester\TestCase
827827 Assert::null ($ newLink ->getExercise ());
828828 }
829829
830+ public function testSyncWithExercisePartial ()
831+ {
832+ PresenterTestHelper::loginDefaultAdmin ($ this ->container );
833+ $ user = PresenterTestHelper::getUser ($ this ->container );
834+
835+ /** @var RuntimeEnvironment $environment */
836+ $ environment = $ this ->runtimeEnvironments ->findAll ()[0 ];
837+ /** @var HardwareGroup $hwGroup */
838+ $ hwGroup = $ this ->hardwareGroups ->findAll ()[0 ];
839+ /** @var Group $group */
840+ $ group = $ this ->presenter ->groups ->findAll ()[0 ];
841+
842+ $ limits = "
843+ memory: 42,
844+ wall-time: 33
845+ " ;
846+
847+ $ newLimits = "
848+ memory: 33,
849+ wall-time: 44
850+ " ;
851+
852+ $ exercises = array_filter (
853+ $ this ->presenter ->exercises ->findAll (),
854+ function (Exercise $ e ) {
855+ return !$ e ->getFileLinks ()->isEmpty (); // select the exercise with file links
856+ }
857+ );
858+ Assert::count (1 , $ exercises );
859+ /** @var Exercise $exercise */
860+ $ exercise = array_pop ($ exercises );
861+
862+ $ exerciseLimits = new ExerciseLimits ($ environment , $ hwGroup , $ limits , $ user );
863+ $ this ->em ->persist ($ exerciseLimits );
864+
865+ $ exercise ->addExerciseLimits ($ exerciseLimits );
866+ $ assignment = Assignment::assignToGroup ($ exercise , $ group );
867+ $ this ->em ->persist ($ assignment );
868+ $ this ->em ->flush ();
869+
870+ $ newExerciseLimits = new ExerciseLimits ($ environment , $ hwGroup , $ newLimits , $ user );
871+ $ this ->em ->persist ($ newExerciseLimits );
872+ $ exercise ->clearExerciseLimits ();
873+ $ exercise ->addExerciseLimits ($ newExerciseLimits );
874+
875+ $ exercise ->getFileLinks ()->removeElement ($ exercise ->getFileLinks ()->first ());
876+ Assert::count (1 , $ exercise ->getFileLinks ());
877+ $ link = $ exercise ->getFileLinks ()->first ();
878+ $ link ->setKey ("NEW " );
879+ $ link ->setRequiredRole (Roles::SUPERVISOR_ROLE );
880+ $ this ->em ->persist ($ link );
881+ $ this ->em ->persist ($ exercise );
882+ $ this ->em ->flush ();
883+
884+ $ request = new Nette \Application \Request (
885+ 'V1:Assignments ' ,
886+ 'POST ' ,
887+ ['action ' => 'syncWithExercise ' , 'id ' => $ assignment ->getId ()],
888+ ['syncOptions ' => ['limits ' ]]
889+ );
890+ $ response = $ this ->presenter ->run ($ request );
891+ Assert::type (Nette \Application \Responses \JsonResponse::class, $ response );
892+ $ payload = $ response ->getPayload ();
893+ $ data = $ payload ["payload " ];
894+
895+ Assert::same ($ assignment ->getId (), $ data ["id " ]);
896+ Assert::same ($ newExerciseLimits , $ assignment ->getLimitsByEnvironmentAndHwGroup ($ environment , $ hwGroup ));
897+ Assert::count (2 , $ assignment ->getFileLinks ());
898+ }
899+
830900 public function testRemove ()
831901 {
832902 $ token = PresenterTestHelper::loginDefaultAdmin ($ this ->container );
0 commit comments