function CourseAccessTestCase::testDurationExpiration in Course 8.3
Same name and namespace in other branches
- 8.2 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\FunctionalCode
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.');
}