View source
<?php
class CourseGradeTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course grading',
'description' => 'Ensure that Course grading functions normally.',
'group' => 'Course',
);
}
public function testCourseFinalGrade() {
$courseNode = $this
->createCourseNode();
$co1 = $this
->createCourseObject($courseNode, TRUE);
$course = course_get_course($courseNode);
$courseObjects = $course
->getObjects();
$co1 = reset($courseObjects);
course_enroll($courseNode, $this->student_user);
$co1
->getFulfillment($this->student_user)
->setOption('grade_result', 80)
->save();
$co1
->setOption('grade_include', FALSE)
->save();
$co1
->getCourse()
->getTracker($this->student_user)
->track();
$this
->assertNotEqual($co1
->getCourse()
->getTracker($this->student_user)
->getOption('grade_result'), 80, 'Course grade was not given from course object');
$co1
->setOption('grade_include', TRUE)
->save();
$co1
->getCourse()
->getTracker($this->student_user)
->track();
$this
->assertEqual($co1
->getCourse()
->getTracker($this->student_user)
->getOption('grade_result'), 80, 'Course grade was given from course object');
}
public function testCourseGradeAccess() {
$courseNode = $this
->createCourseNode();
$this
->createCourseObject($courseNode, TRUE);
$this
->createCourseObject($courseNode);
$course = course_get_course($courseNode);
$courseObjects = array_values($course
->getObjects());
$co1 = $courseObjects[0];
$co2 = $courseObjects[1];
$co1
->setOption('grade_include', TRUE)
->save();
$co2
->addOptions(array(
'plugins' => array(
'access' => array(
'grade' => array(
'course_grade_range' => array(
'low' => 80,
'high' => 90,
),
),
),
),
))
->save();
course_enroll($courseNode, $this->student_user);
$course
->getObjects()[1]
->getFulfillment($this->student_user)
->setOption('grade_result', 79)
->setComplete(1)
->save();
$course
->getTracker($this->student_user)
->track();
$this
->assertFalse($co2
->access('take', $this->student_user), 'User cannot take course object with lower grade.');
$course
->getObjects()[1]
->getFulfillment($this->student_user)
->setOption('grade_result', 91)
->setComplete(1)
->save();
$course
->getTracker($this->student_user)
->track();
$this
->assertFalse($co2
->access('take', $this->student_user), 'User cannot take course object with higher grade.');
$course
->getObjects()[1]
->getFulfillment($this->student_user)
->setOption('grade_result', 80)
->setComplete(1)
->save();
$course
->getTracker($this->student_user)
->track();
$this
->assertTrue($co2
->access('take', $this->student_user), 'User can take course object with required grade.');
}
}