View source
<?php
class CourseAccessTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course access',
'description' => 'Ensure that Course access control functions properly.',
'group' => 'Course',
);
}
function testDurationExpiration() {
global $user;
$courseNode = $this
->createCourseNode();
$courseNode->course['duration'] = 30;
node_save($courseNode);
course_enroll($courseNode, $user);
$enroll = course_enrollment_load($courseNode, $user);
$enroll->enroll_end = 1;
course_enrollment_save($enroll);
$result = course_access_course('take', $courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot access course with expired enrollment.');
}
function testReleaseExpiration() {
global $user;
$courseNode = $this
->createCourseNode();
$result = course_access_course('enroll', $courseNode, $user, TRUE);
$this
->assertTrue($result['success'], 'User can enroll in course past start date.');
$courseNode->course['open'] = REQUEST_TIME + 30;
node_save($courseNode);
$result = course_access_course('enroll', $courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot enroll in not yet open course.');
$courseNode->course['open'] = REQUEST_TIME - 60;
$courseNode->course['close'] = REQUEST_TIME - 30;
node_save($courseNode);
$result = course_access_course('enroll', $courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot enroll in expired course.');
course_enroll($courseNode, $user);
$result = course_access_course('take', $courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot take expired course.');
}
}