public function CourseGradeTestCase::testCourseGradeAccess in Course 6
Same name and namespace in other branches
- 7.2 tests/CourseGradeTestCase.test \CourseGradeTestCase::testCourseGradeAccess()
- 7 tests/CourseGradeTestCase.test \CourseGradeTestCase::testCourseGradeAccess()
Test that the course grade access plugin functions properly.
File
- tests/
CourseGradeTestCase.test, line 50
Class
- CourseGradeTestCase
- Tests for Course enrollment
Code
public function testCourseGradeAccess() {
$courseNode = $this
->createCourseNode();
// Create a graded course objects.
$this
->createCourseObject($courseNode, TRUE);
// Add a non-graded course object.
$this
->createCourseObject($courseNode);
// Reload the course from DB.
$course = course_get_course($courseNode, NULL, TRUE);
$courseObjects = $course
->getObjects();
$co1 = $courseObjects[0];
$co2 = $courseObjects[1];
// Set object 1 to be included in the course grade.
$co1
->setOption('grade_include', TRUE);
// Set object 2 to require a course grade of 80.
$co2
->addOptions(array(
'plugins' => array(
'access' => array(
'grade' => array(
'course_grade' => 80,
),
),
),
));
// Complete but don't hit the grade requirement.
$co1
->getFulfillment()
->setOption('grade_result', 79)
->setComplete(1);
$course
->getTracker()
->track();
$this
->assertFalse($co2
->access('take'), 'User cannot take course object with lower grade.');
// Hit the grade requirement.
$co1
->getFulfillment()
->setOption('grade_result', 80)
->setComplete(1);
$course
->getTracker()
->track();
$this
->assertTrue($co2
->access('take'), 'User can take course object with required grade.');
}