function CourseAccessTestCase::testReleaseExpiration in Course 7
Same name and namespace in other branches
- 6 tests/CourseAccessTestCase.test \CourseAccessTestCase::testReleaseExpiration()
- 7.2 tests/CourseAccessTestCase.test \CourseAccessTestCase::testReleaseExpiration()
Test the open/close date functionality.
File
- tests/
CourseAccessTestCase.test, line 42
Class
- CourseAccessTestCase
- Tests for conditional event-based access to course objects.
Code
function testReleaseExpiration() {
global $user;
$courseNode = $this
->createCourseNode();
// Make sure user can get in with no open/close set.
$result = course_enroll_access($courseNode, $user, TRUE);
$this
->assertTrue($result['success'], 'User can enroll in course past start date.');
// Test a course that is not yet open.
$courseNode->course['open'] = REQUEST_TIME + 30;
node_save($courseNode);
$result = course_enroll_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot enroll in not yet open course.');
// Test an opened course that is closed.
$courseNode->course['open'] = REQUEST_TIME - 60;
$courseNode->course['close'] = REQUEST_TIME - 30;
node_save($courseNode);
$result = course_enroll_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot enroll in expired course.');
// Enroll the user. User should still not be able to take course if it is
// expired.
course_enroll($courseNode, $user);
$result = course_take_course_access($courseNode, $user, TRUE);
$this
->assertFalse($result['success'], 'User cannot take expired course.');
}