You are here

function CourseObjectUbercartTestCase::testUbercartEnrollment in Course 6

Same name and namespace in other branches
  1. 8.3 modules/course_uc/course_uc.test \CourseObjectUbercartTestCase::testUbercartEnrollment()
  2. 8.2 modules/course_uc/course_uc.test \CourseObjectUbercartTestCase::testUbercartEnrollment()
  3. 7.2 modules/course_uc/course_uc.test \CourseObjectUbercartTestCase::testUbercartEnrollment()
  4. 7 modules/course_uc/course_uc.test \CourseObjectUbercartTestCase::testUbercartEnrollment()

File

modules/course_uc/course_uc.test, line 36

Class

CourseObjectUbercartTestCase
Test class for dealing with adding and removing elements from the course outline.

Code

function testUbercartEnrollment() {
  global $user;
  module_load_include('inc', 'uc_product', 'uc_product.admin');

  // Mark our course_test content type as a product.
  $form = array();
  $form_state = array();
  $form_state['values']['name'] = 'course_test';
  $form_state['values']['description'] = 'course_test';
  $form_state['values']['pcid'] = 'course_test';
  $form['pcid']['#type'] = '';
  uc_product_class_form_submit($form, $form_state);

  // Create a product node.
  $courseNode = $this
    ->createCourseNode();
  $courseNode->sell_price = 5;
  node_save($courseNode);
  $result = course_enrol_access($courseNode);
  $this
    ->assertFalse($result['success'], 'User prevented from enrolling into paid course.');
  $result = course_enrol_access($courseNode);
  $this
    ->assertFalse($result['success'], 'User prevented from taking paid course.');
  $order = uc_order_new($user->uid);
  uc_order_product_save($order->order_id, $courseNode);
  uc_order_update_status($order->order_id, 'pending');
  uc_order_update_status($order->order_id, 'completed');

  // Check newly granted access to course.
  $result = course_enrol_access($courseNode, $user, TRUE);
  $this
    ->assertTrue($result['success'], 'User granted access to enroll into course.');
  $result = course_take_course_access($courseNode);
  $this
    ->assertTrue($result['success'], 'User granted access to take course.');
}