You are here

public function CourseObjectAccessTimeTestCase::testCourseObjectRestrictByRelease in Course 7.2

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

Test course object open date.

File

tests/CourseObjectAccessTimeTestCase.test, line 20

Class

CourseObjectAccessTimeTestCase
Tests for course object access based on time.

Code

public function testCourseObjectRestrictByRelease() {
  $now = REQUEST_TIME;
  $courseNode = $this
    ->createCourseNode();
  $options = array();
  global $user;

  // Test restricting by release.
  $o1 = $this
    ->createCourseObject($courseNode);

  // Set the release to 100 seconds in the future.
  $options['plugins']['access']['timing']['release'] = gmdate('c', $now + 100);
  $o1
    ->addOptions($options)
    ->save();
  $this
    ->assertFalse($o1
    ->access('take', $user), 'Check that user cannot take not released object.');
  $this
    ->assertTrue($o1
    ->access('see', $user), 'Check that user can still see not released object.');

  // Set the hide until release option.
  $options['plugins']['access']['timing']['release_hidden'] = 1;
  $o1
    ->addOptions($options)
    ->save();
  $this
    ->assertFalse($o1
    ->access('see', $user), 'Check that object is hidden if hidden is checked and object is not released.');
}