@@ -1014,4 +1014,40 @@ public function test_archiving() {
1014
1014
['component ' => 'enrol_programs ' , 'instance ' => $ allocation1x1 ->id , 'eventtype ' => calendar::EVENTTYPE_START ]);
1015
1015
$ this ->assertFalse ($ event );
1016
1016
}
1017
- }
1017
+
1018
+ /**
1019
+ * Tests that manual events are not deleted by fixing program events
1020
+ *
1021
+ * @see https://github.com/open-lms-open-source/moodle-enrol_programs/issues/11 Issue
1022
+ */
1023
+ public function test_manual_calendar_events_not_deleted_by_fix_program_events () {
1024
+ global $ DB , $ USER ;
1025
+ $ this ->setAdminUser ();
1026
+
1027
+ $ event = new \stdClass ();
1028
+ $ event ->userid = $ USER ->id ;
1029
+ $ event ->timestart = 0 ;
1030
+ $ event ->name = 'test ' ;
1031
+
1032
+ // Manually created events have modulename 0 and component as null.
1033
+ $ event ->modulename = 0 ;
1034
+ $ event ->component = null ;
1035
+
1036
+ \calendar_event::create ($ event );
1037
+
1038
+ $ events = $ DB ->get_records ('event ' );
1039
+ $ this ->assertCount (1 , $ events );
1040
+ $ event = current ($ events );
1041
+ $ this ->assertNull ($ event ->component );
1042
+ $ this ->assertEquals (0 , $ event ->modulename );
1043
+
1044
+ // Run fix events, as if cron would run it.
1045
+ calendar::fix_program_events (null );
1046
+
1047
+ // Ensure calendar event that was created is left untouched.
1048
+ $ events = $ DB ->get_records ('event ' );
1049
+ $ eventids = array_column ($ events , 'id ' );
1050
+ $ this ->assertTrue (in_array ($ event ->id , $ eventids ));
1051
+ }
1052
+ }
1053
+
0 commit comments