function CourseObjectAccessTest::testCourseObjectOptionalWorkflow in Course 3.x
Test an outline with both required and optional objects.
File
- tests/
src/ Functional/ CourseObjectAccessTest.php, line 67
Class
- CourseObjectAccessTest
- Tests for course object access.
Namespace
Drupal\Tests\course\FunctionalCode
function testCourseObjectOptionalWorkflow() {
// Create a course with 4 objects.
$course = $this
->createCourse();
for ($i = 1; $i <= 4; $i++) {
$temp = $this
->createCourseObject($course);
$temp
->setOption('weight', $i)
->save();
}
// Use the student user.
$user = $this->student_user;
$co = array_values($course
->getObjects());
$course
->enroll($user);
// Set all optional except the second object.
$co[0]
->setOption('required', 0);
$co[1]
->setOption('required', 1);
$co[2]
->setOption('required', 0);
$co[3]
->setOption('required', 0);
$this
->assertFalse($co[2]
->access('take', $user) || $co[3]
->access('take', $user), 'User is blocked by second required object to get to fourth optional object.');
$this
->assertTrue($co[0]
->access('take', $user), 'User has access to first optional object.');
$this
->assertTrue($co[1]
->access('take', $user), 'User has access to second required object.');
// Complete the only required object.
$co[1]
->getFulfillment($user)
->setComplete(1)
->save();
$this
->assertTrue($co[2]
->access('take', $user) && $co[3]
->access('take', $user), 'User granted access to remaining optional objects.');
}