You are here

public function CourseObjectAccessTimeTestCase::testCourseObjectRestrictByRelease in Course 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/CourseObjectAccessTimeTestCase.php \Drupal\Tests\course\Functional\CourseObjectAccessTimeTestCase::testCourseObjectRestrictByRelease()

Test course object open date.

File

tests/src/Functional/CourseObjectAccessTimeTestCase.php, line 15

Class

CourseObjectAccessTimeTestCase
Tests for course object access based on time.

Namespace

Drupal\Tests\course\Functional

Code

public function testCourseObjectRestrictByRelease() {
  $now = \Drupal::time()
    ->getRequestTime();
  $course = $this
    ->createCourse();
  $options = array();

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

  // 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', $this->student_user), 'Check that user cannot take not released object.');
  $this
    ->assertTrue($o1
    ->access('see', $this->student_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', $this->student_user), 'Check that object is hidden if hidden is checked and object is not released.');
}