You are here

function CourseEnrollmentTestCase::testCourseEnrollment in Course 6

Same name and namespace in other branches
  1. 7.2 tests/CourseEnrollmentTestCase.test \CourseEnrollmentTestCase::testCourseEnrollment()
  2. 7 tests/CourseEnrollmentTestCase.test \CourseEnrollmentTestCase::testCourseEnrollment()

Test for enrollment access and timestamping.

File

tests/CourseEnrollmentTestCase.test, line 22

Class

CourseEnrollmentTestCase
Tests for Course enrollment

Code

function testCourseEnrollment() {
  global $user;
  $courseNode = $this
    ->createCourseNode();
  $result = course_enrol_access($courseNode);
  $this
    ->assertTrue($result['success'], 'Check that the user is allowed to self enroll into this course.');
  $result = course_take_course_access($courseNode);
  $this
    ->assertTrue($result['success'], 'Check that the user can take the course.');
  course_enrol($courseNode, $user);
  $enroll = course_enrolment_load($courseNode, $user);
  $this
    ->assertTrue($enroll->eid > 0, 'Enrollment was created.');
  $this
    ->assertTrue($enroll->created > 0, 'Enrollment has a creation timestamp.');
  $this
    ->assertFalse($enroll->timestamp > 0, 'Check that user has not started course.');

  // Take the course
  course_take_course($courseNode);
  $enroll = course_enrolment_load($courseNode, $user);
  $this
    ->assertTrue($enroll->timestamp > 0, 'Check for start of course timestamp.');
}