You are here

CourseAccessTestCase.test in Course 7.2

Same filename and directory in other branches
  1. 6 tests/CourseAccessTestCase.test
  2. 7 tests/CourseAccessTestCase.test

File

tests/CourseAccessTestCase.test
View source
<?php

/**
 * Tests for conditional event-based access to course objects.
 */
class CourseAccessTestCase extends CourseTestCase {
  public static function getInfo() {

    // Note that getInfo() strings are not translated with t().
    return array(
      'name' => 'Course access',
      'description' => 'Ensure that Course access control functions properly.',
      'group' => 'Course',
    );
  }

  /**
   * Test the enrollment duration. This does not test the enrollment end date
   * being set correctly.
   *
   * @see CourseEnrollmentTestCase::testCourseDuration()
   */
  function testDurationExpiration() {
    global $user;
    $courseNode = $this
      ->createCourseNode();

    // Set expiration to 30 days.
    $courseNode->course['duration'] = 30;
    node_save($courseNode);
    course_enroll($courseNode, $user);

    // Expire the duration.
    $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.');
  }

  /**
   * Test the open/close date functionality.
   */
  function testReleaseExpiration() {
    global $user;
    $courseNode = $this
      ->createCourseNode();

    // Make sure user can get in with no open/close set.
    $result = course_access_course('enroll', $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_access_course('enroll', $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_access_course('enroll', $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_access_course('take', $courseNode, $user, TRUE);
    $this
      ->assertFalse($result['success'], 'User cannot take expired course.');
  }

}

Classes

Namesort descending Description
CourseAccessTestCase Tests for conditional event-based access to course objects.