You are here

function CourseEnrollmentTestCase::testCourseDuration in Course 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/CourseEnrollmentTestCase.php \Drupal\Tests\course\Functional\CourseEnrollmentTestCase::testCourseDuration()

Test for course duration being set properly on enrollment.

File

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

Class

CourseEnrollmentTestCase
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.');
}