<?php

require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'course') . '/tests/CourseTestCase.test';

/**
 * Description of CourseFulfillmentObjectTestCase
 */
class CourseObjectFulfillmentTestCase extends CourseTestCase {

  public static function getInfo() {
    // Note that getInfo() strings are not translated with t().
    return array(
      'name' => 'Course object fulfillments',
      'description' => 'Ensure that Course object fulfillments function properly.',
      'group' => 'Course',
    );
  }

  /**
   * Test fulfillment of CourseObjects with an enrolled/unenrolled user
   */
  function testCourseContentObjectFulfillment() {
    $this->learner = $this->drupalCreateUser();

    // Add the course object to the course.
    $courseNode = $this->createCourseNode();
    $course = course_get_course($courseNode);
    $co1 = course_get_course_object('course_test', 'course_test_object');
    $co1->setCourse($course);
    $co1->save();

    // Satisfy the object outside of the course.
    $co1->getFulfillment()->setComplete(TRUE)->save();

    // Reload because something happened in the DB.
    $co1_1 = course_get_course_object_by_id($co1->getId(), $this->learner);
    $this->assertFalse($co1_1->getFulfillment()->isComplete(), 'Check that the object is not fulfilled.');

    // Enroll the user in the course.
    course_enroll($courseNode, $this->learner);

    // Satisfy the object inside of the course.
    $co1_1->getFulfillment()->setComplete(TRUE)->save();

    // Reload because something happened in the DB.
    $co1_2 = course_get_course_object_by_id($co1_1->getId(), $this->learner);
    $this->assertTrue($co1_2->getFulfillment()->isComplete(), 'Check that the object is fulfilled.');
  }

}
