@@ -466,7 +466,7 @@ public function test_chris_change($bdata): void {
466466 $ userbertaid = $ DB ->get_record ('user ' , ['firstname ' => 'Berta ' ])->id ;
467467 $ userchrisemail = $ DB ->get_record ('user ' , ['firstname ' => 'Chris ' ])->email ;
468468 $ userbertaemail = $ DB ->get_record ('user ' , ['firstname ' => 'Berta ' ])->email ;
469- $ activecohortprechange = $ DB ->get_records ('local_taskflow_unit_members ' , ['active ' => 1 , 'userid ' => $ userchrisid ]);
469+ $ activecohortprechange = $ DB ->get_record ('local_taskflow_unit_members ' , ['active ' => 1 , 'userid ' => $ userchrisid ]);
470470 $ activeassignmentsprechange = $ DB ->get_records ('local_taskflow_assignment ' , ['userid ' => $ userchrisid , 'active ' => 1 ]);
471471 // Chris one assignment of rule one.
472472 $ id = $ rule ['id ' ];
@@ -503,14 +503,15 @@ public function test_chris_change($bdata): void {
503503 time_mock::set_mock_time (strtotime ('+ 30 days ' , time ()));
504504 $ user = $ DB ->get_record ('user ' , ['firstname ' => 'Chris ' ]);
505505 profile_load_custom_fields ($ user );
506+ $ oldorgunitname = $ user ->profile ['orgunit ' ];
506507 $ user ->profile_field_orgunit = $ user ->profile ['orgunit ' ] . '\\' . $ secondcohort ->name ;
507508 $ user ->profile_field_Org2 = $ secondcohort ->name ;
508509 profile_save_data ($ user );
509510 \core \event \user_updated::create_from_userid ($ user ->id )->trigger ();
510511
511- $ activecohortpostchange = $ DB ->get_records ('local_taskflow_unit_members ' , ['active ' => 1 , 'userid ' => $ userchrisid ]);
512+ $ activecohortpostchange = $ DB ->get_record ('local_taskflow_unit_members ' , ['active ' => 1 , 'userid ' => $ userchrisid ]);
512513 $ inactiveassignmentspostchange = $ DB ->get_records ('local_taskflow_assignment ' , ['userid ' => $ userchrisid , 'active ' => 0 ]);
513- $ this ->assertNotSame ($ activecohortprechange , $ activecohortpostchange );
514+ $ this ->assertNotSame ($ activecohortprechange-> unitid , $ activecohortpostchange-> unitid );
514515 // Rule 1 assignment is inactive now for Chris.
515516 $ this ->assertCount (1 , $ inactiveassignmentspostchange );
516517 if (count ($ inactiveassignmentspostchange ) >= 1 ) {
@@ -557,5 +558,28 @@ public function test_chris_change($bdata): void {
557558 $ this ->assertSame ($ assignpost ->status , '0 ' );
558559 $ this ->assertSame ((int )$ assignpost ->ruleid , ($ secondrule ['id ' ]));
559560 }
561+
562+ // Come back to first cohort again.
563+ // We still have $assignpost variable from above.
564+ time_mock::set_mock_time (strtotime ('+ 30 days ' , time ()));
565+
566+ // We need to destroy all statics.
567+ $ plugingeneratortf ->teardown ();
568+
569+ $ user ->profile_field_orgunit = $ oldorgunitname ;
570+ $ user ->profile_field_Org2 = '' ;
571+ profile_save_data ($ user );
572+ \core \event \user_updated::create_from_userid ($ user ->id )->trigger ();
573+
574+ time_mock::set_mock_time (strtotime ('+ 6 minutes ' , time ()));
575+ $ plugingeneratortf ->runtaskswithintime ($ cronlock , $ lock , time ());
576+
577+ // Make sure we are in the same cohort again.
578+ $ activecohortpostchange = $ DB ->get_record ('local_taskflow_unit_members ' , ['active ' => 1 , 'userid ' => $ userchrisid ]);
579+ $ this ->assertSame ($ activecohortprechange ->unitid , $ activecohortpostchange ->unitid );
580+
581+ // Get assignment again.
582+ $ assignment = $ DB ->get_record ('local_taskflow_assignment ' , ['id ' => $ assignpost ->id ]);
583+ $ this ->assertSame ((int )$ assignment ->status , assignment_status_facade::get_status_identifier ('assigned ' ));
560584 }
561585}
0 commit comments