You are here

function CourseObjectAccessTestCase::testCourseSkippableRequiredObjectsWorkflow in Course 7.2

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

Test an outline with skippable required objects.

File

tests/CourseObjectAccessTestCase.test, line 101

Class

CourseObjectAccessTestCase
Tests for course object access.

Code

function testCourseSkippableRequiredObjectsWorkflow() {

  // 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);
  $co = array_values($course
    ->getObjects());
  course_enroll($courseNode, $user);

  // Set all required, but make the second one skippable.
  $co[0]
    ->setOption('required', 1);
  $co[1]
    ->setOption('required', 1);
  $co[1]
    ->setOption('skippable', 1)
    ->save();
  $co[2]
    ->setOption('required', 1);
  $co[3]
    ->setOption('required', 1);

  // We should not be able to bypass the first object.
  $this
    ->assertTrue($co[0]
    ->access('take', $user), 'User can access first object.');
  $this
    ->assertFalse($co[1]
    ->access('take', $user), 'User is blocked from second object.');

  // Complete the first object.
  $co[0]
    ->getFulfillment($user)
    ->setComplete(1)
    ->save();
  $this
    ->assertTrue($co[1]
    ->access('take', $user), 'User can access second object.');

  // Now that the user can access the second object, because it is required,
  // and skippable, they should be able to access the third object.
  $this
    ->assertTrue($co[2]
    ->access('take', $user), 'User can access third object.');

  // However because the third object is required, they cannot acess the
  // fourth.
  $this
    ->assertFalse($co[3]
    ->access('take', $user), 'User is blocked from fourth object.');

  // Complete all the required, but not skippable objects.
  $co[2]
    ->getFulfillment($user)
    ->setComplete(1)
    ->save();
  $co[3]
    ->getFulfillment($user)
    ->setComplete(1)
    ->save();

  // Even though all required, non-skippable objects were completed, the
  // course is not complete. The skippable object must still be completed.
  $this
    ->assertFalse($course
    ->getTracker($user)
    ->getOption('complete'), 'Check that course is not complete.');
  $co[1]
    ->getFulfillment($user)
    ->setComplete(1)
    ->save();
  $this
    ->assertTrue($course
    ->getTracker($user)
    ->getOption('complete'), 'Check that course is complete.');
}