Unenroll a user for a test case.

Unenroll a user for a test case.

by lee kirkland -
Number of replies: 0

I am making a test case for a plugin I'm working on, and one of the test cases it needs to be able to check to see if a user is no longer enrolled in a course. In order to do this, I need to be able to unenroll a user I have just enrolled in a course, to simulate an accidental enrollment by someone. 

        //enrol the user and also suspend them.

        $this->getDataGenerator()->enrol_user( $this->users_['userUnErol']->id, $this->course_->id,null,'manual',0,0,ENROL_USER_SUSPENDED);

The above is what I have currently but it is still reporting the user has submit privileges so I have to assume the user was not unenrolled from the course. What is the call to unenroll a user once they have been enrolled into a course? Or how do I unenroll a person? 


This is the code to determine if the learner is still enrolled in a course. 

        public function IsEnrolled($courseId,$userId){       

            $context = context_course::instance($courseId);

            return is_enrolled($context, $userId, 'mod/assignment:submit', false);

        }

This is the test case to ensure the item comes back false like it should. 

        //should return back false, because the user has been suspended.

        $this->assertFalse($check->IsEnrolled($this->course_->id ,$this->users_['userUnErol']->id));

This should come back false, since I want the user unenrolled from the course. I'm not so much looking as to how to code the program as looking for a way to unenroll a user once they have been enrolled, so I can run a test to make sure the program is truly returning the right results when a learner has been unenrolled. I can seem to find this API any where in moodle documents, so if someone has a link where it details every call I can make using the getDataGenerator() that would be extremely helpful for my test case programming. 


Let me know, because this is holding up the programming portion, because I need to ensure I am truly getting the right results in a testing environment. 


Average of ratings: -