function CourseObjectAccessTestCase::testCourseObjectLinearWorkflow in Course 6
Same name and namespace in other branches
- 7.2 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testCourseObjectLinearWorkflow()
- 7 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testCourseObjectLinearWorkflow()
Test sequential object access.
File
- tests/
CourseObjectAccessTestCase.test, line 22
Class
- CourseObjectAccessTestCase
- Tests for course object access.
Code
function testCourseObjectLinearWorkflow() {
// Create a course with 4 objects.
$courseNode = $this
->createCourseNode();
for ($i = 1; $i <= 4; $i++) {
$temp = $this
->createCourseObject($courseNode);
$temp
->setOption('weight', $i)
->save();
}
// Use the student user.
$user = $this->student_user;
$course = course_get_course($courseNode, $user, TRUE);
$co = $course
->getObjects();
// Student should not be able to access the first object.
$this
->assertFalse($co[0]
->access('take', $user), 'Check that object 1 is not accessible.');
// (until they are enrolled)
course_enrol($courseNode, $user);
// User should be able to access first object, but no others.
$this
->assertTrue($co[0]
->access('take', $user), 'Check that object 1 is accessible after enrollment.');
$this
->assertFalse($co[1]
->access('take', $user), 'Check that object 2 is not accessible.');
$this
->assertFalse($co[2]
->access('take', $user), 'Check that object 3 is not accessible.');
$this
->assertFalse($co[3]
->access('take', $user), 'Check that object 4 is not accessible.');
// Set 1st object to complete.
$co[0]
->getFulfillment()
->setComplete(1)
->save();
$this
->assertTrue($co[1]
->access('take', $user), 'Check that object 2 is accessible after object 1 is complete.');
$this
->assertFalse($co[2]
->access('take', $user), 'Check that object 3 is not accessible after object 1 is complete.');
$this
->assertFalse($co[3]
->access('take', $user), 'Check that object 4 is not accessible after object 1 is complete.');
// Complete the rest of the course objects.
$co[1]
->getFulfillment()
->setComplete(1)
->save();
$co[2]
->getFulfillment()
->setComplete(1)
->save();
$co[3]
->getFulfillment()
->setComplete(1)
->save();
$this
->assertTrue($course
->getTracker()
->getOption('complete'), 'Check that course is complete.');
}