You are here

function CourseObjectAccessTestCase::testCourseObjectOptionalWorkflow in Course 6

Same name and namespace in other branches
  1. 7.2 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testCourseObjectOptionalWorkflow()
  2. 7 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testCourseObjectOptionalWorkflow()

Test an outline with both required and optional objects.

File

tests/CourseObjectAccessTestCase.test, line 65

Class

CourseObjectAccessTestCase
Tests for course object access.

Code

function testCourseObjectOptionalWorkflow() {

  // 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();
  course_enrol($courseNode, $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()
    ->setComplete(1);
  $this
    ->assertTrue($co[2]
    ->access('take', $user) && $co[3]
    ->access('take', $user), 'User granted access to remaining optional objects.');
}