function CourseObjectCommerceTest::testUbercartEnrollment in Course 3.x
File
- modules/
course_commerce/ tests/ src/ Functional/ CourseCommerceTest.php, line 24
Class
- CourseObjectCommerceTest
- Test class for Ubercart integration with Course.
Namespace
Drupal\Tests\course_commerce\FunctionalCode
function testUbercartEnrollment() {
global $user;
$this
->setCourseTestToProduct();
// Create a product node.
$courseNode = $this
->createCourseNode(array(
'sell_price' => 5,
'unique_hash' => uniqid(),
));
$result = course_access_course('enroll', $courseNode);
$this
->assertFalse($result['success'], 'User prevented from enrolling into paid course.');
$result = course_access_course('enroll', $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_access_course('enroll', $courseNode, $user, TRUE);
$this
->assertTrue($result['success'], 'User granted access to enroll into course.');
$result = course_access_course('take', $courseNode);
$this
->assertTrue($result['success'], 'User granted access to take course.');
}