function CourseEnrollmentTestCase::testCourseEnrollmentTimestamps in Course 8.3
Same name and namespace in other branches
- 8.2 tests/src/Functional/CourseEnrollmentTestCase.php \Drupal\Tests\course\Functional\CourseEnrollmentTestCase::testCourseEnrollmentTimestamps()
Test a manual course enrollment. Ensure that created and started timestamping works as expected.
File
- tests/
src/ Functional/ CourseEnrollmentTestCase.php, line 50
Class
- CourseEnrollmentTestCase
- Tests for Course enrollment
Namespace
Drupal\Tests\course\FunctionalCode
function testCourseEnrollmentTimestamps() {
$course = $this
->createCourse();
$course_enrollment = CourseEnrollment::create(array(
'cid' => $course
->id(),
'uid' => $this->student_user
->id(),
'type' => $course
->get('enrollment_type')->value,
));
$course_enrollment
->save();
$initial_created = $course_enrollment
->get('created')->value;
$this
->assertTrue($initial_created > 0, t('Enrollment creation date was set.'));
$this
->assertEqual($course_enrollment
->get('timestamp')->value, 0, t('Enrollment timestamp not set.'));
// Wait one second so we can confirm a time difference.
sleep(1);
$this
->drupalLogin($this->student_user);
$this
->drupalGet("course/{$course->id()}/take");
$new_enrollment = $course
->getEnrollment($this->student_user);
Drupal::entityTypeManager()
->getStorage('course_enrollment')
->resetCache();
$this
->assertEqual($initial_created, $new_enrollment
->get('created')->value, t('Enrollment creation date retained.'));
$this
->assertTrue($new_enrollment
->get('timestamp')->value > 0, t('Enrollment timestamp set.'));
}