You are here

CourseObjectFulfillmentTestCase.test in Course 7.2

Same filename and directory in other branches
  1. 7 tests/CourseObjectFulfillmentTestCase.test

File

tests/CourseObjectFulfillmentTestCase.test
View source
<?php

/**
 * 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($this->learner)
      ->setComplete(TRUE)
      ->save();
    $this
      ->assertFalse($co1
      ->getFulfillment($this->learner)
      ->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
      ->getFulfillment($this->learner)
      ->setOption('test_value', 'findMe123')
      ->setComplete(TRUE)
      ->save();
    $co1
      ->getFulfillment($this->learner)
      ->setOption('test_value_undef', 'findMe123')
      ->setComplete(TRUE)
      ->save();
    $this
      ->assertEqual($co1
      ->getFulfillment($this->learner)
      ->getOption('test_value'), 'findMe123', 'Check that defined fulfillment data was saved.');
    $this
      ->assertNotEqual($co1
      ->getFulfillment($this->learner)
      ->getOption('test_value_undef'), 'findMe123', 'Check that undefined fulfillment data was not saved.');
    $this
      ->assertTrue($co1
      ->getFulfillment($this->learner)
      ->isComplete(), 'Check that the object is fulfilled.');
  }

}

Classes

Namesort descending Description
CourseObjectFulfillmentTestCase Description of CourseFulfillmentObjectTestCase