You are here

public function CourseObjectAccessTimeTestCase::testCourseObjectDuration in Course 6

Same name and namespace in other branches
  1. 7.2 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() {
  $now = time();
  $courseNode = $this
    ->createCourseNode();
  $options = array();
  course_enrol($courseNode);
  $o3 = $this
    ->createCourseObject($courseNode);

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

  // Set the duration to 1 minute.
  $options['plugins']['access']['timing']['duration'] = 60;
  $o3
    ->addOptions($options);
  $this
    ->assertFalse($o3
    ->access('take'), '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);
  $this
    ->assertTrue($o3
    ->access('take'), 'Check that user can access course object when duration has been extended.');
}