CourseEnrollmentTestCase.test in Course 6
File
tests/CourseEnrollmentTestCase.test
View source
<?php
require_once drupal_get_path('module', 'course') . '/tests/CourseTestCase.test';
class CourseEnrollmentTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course enrollment',
'description' => 'Ensure that Course enrollment and access control functions properly.',
'group' => 'Course',
);
}
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.');
course_take_course($courseNode);
$enroll = course_enrolment_load($courseNode, $user);
$this
->assertTrue($enroll->timestamp > 0, 'Check for start of course timestamp.');
}
function testCourseDuration() {
global $user;
$courseNode = $this
->createCourseNode();
$courseNode->course['duration'] = 30;
node_save($courseNode);
$enroll = course_enrolment_load($courseNode, $user);
$this
->assertFalse($enroll, 'Check that enrollment does not exist.');
course_take_course($courseNode);
$enroll = course_enrolment_load($courseNode, $user);
$this
->assertTrue($enroll->enrol_end > time(), 'Duration end got set with course start.');
}
}