CourseAccessTestCase.test in Course 6
File
tests/CourseAccessTestCase.test
View source
<?php
require_once drupal_get_path('module', 'course') . '/tests/CourseTestCase.test';
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_enrol($courseNode, $user);
$enroll = course_enrolment_load($courseNode, $user);
$enroll->enrol_end = 1;
course_enrolment_save($enroll);
$result = course_take_course_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot access course with expired enrollment.');
}
function testReleaseExpiration() {
global $user;
$courseNode = $this
->createCourseNode();
$result = course_enrol_access($courseNode, $user, TRUE);
$this
->assertTrue($result['success'], 'User can enroll in course past start date.');
$courseNode->course['open'] = time() + 30;
node_save($courseNode);
$result = course_enrol_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot enroll in not yet open course.');
$courseNode->course['open'] = time() - 60;
$courseNode->course['close'] = time() - 30;
node_save($courseNode);
$result = course_enrol_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot enroll in expired course.');
course_enrol($courseNode, $user);
$result = course_take_course_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot take expired course.');
}
}