You are here

function CourseAccessTestCase::testDurationExpiration in Course 8.2

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

Test the enrollment duration. This does not test the enrollment end date being set correctly.

See also

CourseEnrollmentTestCase::testCourseDuration()

File

tests/src/Functional/CourseAccessTestCase.php, line 18

Class

CourseAccessTestCase
Tests for conditional event-based access to course objects.

Namespace

Drupal\Tests\course\Functional

Code

function testDurationExpiration() {
  $course = $this
    ->createCourse();

  // Set duration to 30 days.
  $course
    ->set('duration', 86400 * 30);
  $course
    ->save();
  $course
    ->enroll($this->student_user);
  $this
    ->assertTrue($course
    ->access('take', $this->student_user));

  // Expire the duration.
  $enroll = $course
    ->getEnrollment($this->student_user);
  $enroll
    ->set('enroll_end', 1);
  $enroll
    ->save();
  \Drupal::entityTypeManager()
    ->getAccessControlHandler('course')
    ->resetCache();
  $this
    ->assertFalse($course
    ->access('take', $this->student_user), 'User cannot access course with expired enrollment.');
}