function CourseEnrollmentTest::testCourseEnrollment in Course 3.x
Test for enrollment access and timestamping.
File
- tests/
src/ Functional/ CourseEnrollmentTest.php, line 21
Class
- CourseEnrollmentTest
- Tests for Course enrollment
Namespace
Drupal\Tests\course\FunctionalCode
function testCourseEnrollment() {
$course = $this
->createCourse();
$result = $course
->access('enroll', $this->student_user);
$this
->assertTrue($result, 'Check that the user is allowed to self enroll into this course.');
$result = $course
->access('take', $this->student_user);
$this
->assertFalse($result, 'Check that the user cannot enroll in the course.');
$course
->enroll($this->student_user);
$result = $course
->access('take', $this->student_user);
$this
->assertTrue($result, 'Check that the user can take the course.');
$enroll = $course
->getEnrollment($this->student_user);
$this
->assertTrue($enroll
->id() > 0, 'Enrollment was created.');
$this
->assertTrue($enroll
->get('created')->value > 0, 'Enrollment has a creation timestamp.');
//$this->assertFalse($enroll->timestamp > 0, 'Check that user has not started course.');
// Take the course
$this
->drupalLogin($this->student_user);
$this
->drupalGet("course/{$course->id()}/take");
// The enrollment has changed.
Drupal::entityTypeManager()
->getStorage('course_enrollment')
->resetCache();
$enroll = $course
->getEnrollment($this->student_user);
$this
->assertTrue($enroll
->get('timestamp')->value > 0, 'Check for start of course timestamp.');
}