CourseWorkflowTestCase.test in Course 7.2
File
tests/CourseWorkflowTestCase.test
View source
<?php
class CourseWorkflowTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course workflow',
'description' => 'Ensure that the Course workflow functions properly.',
'group' => 'Course',
);
}
function testObjectAdvancement() {
$this->student_user = $this
->drupalCreateUser();
$courseNode = $this
->createCourseNode();
$course = course_get_course($courseNode);
$co1 = course_get_course_object('course_test', 'course_test_object');
$co1
->setCourse($course);
$co1
->setOption('title', 'Course object 1');
$co1
->save();
$co2 = course_get_course_object('course_test', 'course_test_object');
$co2
->setCourse($course);
$co2
->setOption('title', 'Course object 2');
$co2
->save();
$course = course_get_course($courseNode);
$this
->drupalGet("node/{$courseNode->nid}/course-complete");
$this
->assertResponse(403, 'Cannot see completion page');
$this
->drupalLogin($this->student_user);
course_enroll($courseNode, $this->student_user);
$this
->drupalGet("node/{$courseNode->nid}/course-complete");
$this
->assertResponse(200, 'Can see completion page');
$this
->assertText('This course is not complete.');
$this
->drupalGet("node/{$courseNode->nid}/takecourse");
$this
->assertLink('Course object 1');
$this
->assertNoLink('Course object 2');
$this
->assertNoLink('Next');
$this
->clickLink('Course object 1');
$this
->assertText(t('I am a test course object with the title !title', array(
'!title' => $co1
->getOption('title'),
)));
$course = course_get_course($courseNode);
$objects = array_values($course
->getObjects());
$objects[0]
->getFulfillment($this->student_user)
->setComplete(1)
->save();
$this
->drupalGet("node/{$courseNode->nid}/takecourse");
$this
->assertLink('Course object 2');
$this
->assertLink('Next');
$this
->clickLink('Course object 2');
$this
->assertText(t('I am a test course object with the title !title', array(
'!title' => $co2
->getOption('title'),
)));
$this
->clickLink('Course object 1');
$this
->assertText(t('I am a test course object with the title !title', array(
'!title' => $co1
->getOption('title'),
)));
$this
->clickLink('Next');
$this
->assertText(t('I am a test course object with the title !title', array(
'!title' => $co2
->getOption('title'),
)));
$course = course_get_course($courseNode);
$objects = array_values($course
->getObjects());
$objects[1]
->getFulfillment($this->student_user)
->setComplete(1)
->save();
$this
->drupalGet("node/{$courseNode->nid}/takecourse");
$this
->assertLink('Complete');
$this
->clickLink('Complete');
$this
->assertText('You have completed the course.');
}
}