You are here

public function CourseGradeTest::testCourseFinalGrade in Course 3.x

Test that the final grade is calculated correctly.

File

tests/src/Functional/CourseGradeTest.php, line 15

Class

CourseGradeTest
Tests for Course grade.

Namespace

Drupal\Tests\course\Functional

Code

public function testCourseFinalGrade() {
  $course = $this
    ->createCourse();

  // Create a graded course object.
  $co1 = $this
    ->createCourseObject($course, TRUE);
  $course
    ->enroll($this->student_user);

  // Set grade result.
  $co1
    ->getFulfillment($this->student_user)
    ->set('grade_result', 80)
    ->save();

  // Track object not included in final grade.
  $co1
    ->set('grade_include', 0)
    ->save();
  $co1
    ->getCourse()
    ->resetCache();
  $co1
    ->getCourse()
    ->getEnrollment($this->student_user)
    ->track();
  $this
    ->assertNotEqual($co1
    ->getCourse()
    ->getEnrollment($this->student_user)
    ->get('grade_result')
    ->getString(), 80, 'Course grade was not given from course object');

  // Track object included in final grade.
  $co1
    ->set('grade_include', 1)
    ->save();
  $co1
    ->getCourse()
    ->resetCache();
  $co1
    ->getCourse()
    ->getEnrollment($this->student_user)
    ->track();
  $this
    ->assertEqual($co1
    ->getCourse()
    ->getEnrollment($this->student_user)
    ->get('grade_result')
    ->getString(), 80, 'Course grade was given from course object');
}