function CourseAccessTest::testDurationExpiration in Course 3.x
Test the enrollment duration. This does not test the enrollment end date being set correctly.
See also
CourseEnrollmentTest::testCourseDuration()
File
- tests/
src/ Functional/ CourseAccessTest.php, line 19
Class
- CourseAccessTest
- 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.');
}