You are here

public function CourseObjectAccessTimeTestCase::testCourseObjectRestrictByExpiration in Course 7

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

Test course object expiration date.

File

tests/CourseObjectAccessTimeTestCase.test, line 43

Class

CourseObjectAccessTimeTestCase
Tests for course object access based on time.

Code

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

  // Test restricting by expiration.
  $o2 = $this
    ->createCourseObject($courseNode);

  // Set the expiration to 10 seconds ago.
  $options['plugins']['access']['timing']['expiration'] = gmdate('c', $now - 100);
  $o2
    ->addOptions($options)
    ->save();
  $this
    ->assertFalse($o2
    ->access('take'), 'Check that user cannot take expired course object.');
  $this
    ->assertTrue($o2
    ->access('see'), 'Check that user can see expired course object.');

  // Set the hide when expired option.
  $options['plugins']['access']['timing']['expiration_hidden'] = 1;
  $o2
    ->addOptions($options)
    ->save();
  $this
    ->assertFalse($o2
    ->access('see'), 'Check that object is hidden if hidden is checked and object is expired.');
}