You are here

function CourseEnrollmentTest::testCourseDuration in Course 3.x

Test for course duration being set properly on enrollment.

File

tests/src/Functional/CourseEnrollmentTest.php, line 78

Class

CourseEnrollmentTest
Tests for Course enrollment

Namespace

Drupal\Tests\course\Functional

Code

function testCourseDuration() {
  $course = $this
    ->createCourse([
    'duration' => 30,
  ]);
  $course
    ->save();
  $enroll = $course
    ->getEnrollment($this->student_user);
  $this
    ->assertFalse($enroll, 'Check that enrollment does not exist.');
  $this
    ->drupalLogin($this->student_user);
  $this
    ->drupalGet("course/{$course->id()}/take");
  Drupal::entityTypeManager()
    ->getStorage('course_enrollment')
    ->resetCache();
  $enroll = $course
    ->getEnrollment($this->student_user);
  $this
    ->assertTrue($enroll
    ->get('enroll_end')->value > \Drupal::time()
    ->getRequestTime(), 'Duration end got set with course start.');
}