View source
<?php
require_once drupal_get_path('module', 'course') . '/tests/CourseTestCase.test';
class CourseContextTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course context',
'description' => 'Ensure that Course context functions normally.',
'group' => 'Course',
);
}
function testDetermineContext() {
$courseNode = $this
->createCourseNode();
$co1 = $this
->createCourseObject($courseNode);
$co1
->setInstanceId(1234)
->save();
$find_co1 = course_get_course_object('course_test', 'course_test_object', 1234);
$this
->assertEqual($co1
->getId(), $find_co1
->getId(), 'Found the same course object.');
$find_course1 = course_determine_context('course_test', 'course_test_object', 1234);
$this
->assertEqual($find_course1->nid, $courseNode->nid, 'Context came back to the same course.');
}
function testMultiContext() {
$courseNode1 = $this
->createCourseNode();
$courseNode2 = $this
->createCourseNode();
$co1 = $this
->createCourseObject($courseNode1);
$co1
->setInstanceId(1234)
->save();
$co2 = $this
->createCourseObject($courseNode2);
$co2
->setInstanceId(1234)
->save();
$co1
->takeCourseObject();
$foundCourseNode1 = course_determine_context('course_test', 'course_test_object', 1234);
$this
->assertEqual($courseNode1->nid, $foundCourseNode1->nid, 'Found the right course context, pass 1.');
$co2
->takeCourseObject();
$foundCourseNode2 = course_determine_context('course_test', 'course_test_object', 1234);
$this
->assertEqual($courseNode2->nid, $foundCourseNode2->nid, 'Found the right course context, pass 2.');
$co1
->takeCourseObject();
$foundCourseNode1 = course_determine_context('course_test', 'course_test_object', 1234);
$this
->assertEqual($courseNode1->nid, $foundCourseNode1->nid, 'Found the right course context, pass 3.');
}
}