You are here

public function CourseObjectAccessTimeTest::testCourseObjectRestrictByRelease in Course 3.x

Test course object open date.

File

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

Class

CourseObjectAccessTimeTest
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.');
}