You are here

public function CourseObjectAccessTimeTestCase::testCourseObjectDuration in Course 7.2

Same name and namespace in other branches
  1. 6 tests/CourseObjectAccessTimeTestCase.test \CourseObjectAccessTimeTestCase::testCourseObjectDuration()
  2. 7 tests/CourseObjectAccessTimeTestCase.test \CourseObjectAccessTimeTestCase::testCourseObjectDuration()

Check that user cannot access course object outside of duration period.

File

tests/CourseObjectAccessTimeTestCase.test, line 68

Class

CourseObjectAccessTimeTestCase
Tests for course object access based on time.

Code

public function testCourseObjectDuration() {
  global $user;
  $now = REQUEST_TIME;
  $courseNode = $this
    ->createCourseNode();
  $options = array();
  course_enroll($courseNode, $user);
  $o3 = $this
    ->createCourseObject($courseNode);

  // Start the course object 5 minutes ago.
  $o3
    ->getFulfillment($user)
    ->setOption('date_started', $now - 300)
    ->save();
  $this
    ->assertTrue($o3
    ->access('take', $user), 'Check that user can access course object without duration.');

  // Set the duration to 1 minute.
  $options['plugins']['access']['timing']['duration'] = 60;
  $o3
    ->addOptions($options)
    ->save();
  $this
    ->assertFalse($o3
    ->access('take', $user), 'Check that user cannot access course object when duration has passed.');

  // Extend the duration to 10 minutes.
  $options['plugins']['access']['timing']['duration'] = 600;
  $o3
    ->addOptions($options)
    ->save();
  $this
    ->assertTrue($o3
    ->access('take', $user), 'Check that user can access course object when duration has been extended.');
}