CourseObjectNodeTestCase.test in Course 7.2
File
tests/CourseObjectNodeTestCase.test
View source
<?php
class CourseObjectNodeTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Node-based course objects',
'description' => 'Ensure that node based Course objects function properly.',
'group' => 'Course',
);
}
public function getModules() {
$modules = parent::getModules();
$modules[] = 'course_content';
$modules[] = 'content_access';
$modules[] = 'acl';
return $modules;
}
function testContentAccess() {
$courseNode = $this
->createCourseNode();
$course = course_get_course($courseNode);
$co1 = course_get_course_object('course_content', 'course_test_content');
$co1
->setOption('private', 1);
$co1
->setCourse($course);
$co1
->save();
node_access_rebuild();
$this
->drupalLogin($this->student_user);
course_enroll($courseNode, $this->student_user);
$this
->drupalGet("node/" . $co1
->getInstanceId());
$this
->assertResponse(403, 'Check that node is protected outside the course.');
$co1
->getFulfillment($this->student_user)
->grant();
$this
->drupalGet("node/" . $co1
->getInstanceId());
$this
->assertResponse(200, 'Check that node is accessible when user enters course object.');
$co1
->getFulfillment($this->student_user)
->revoke();
$this
->drupalGet("node/" . $co1
->getInstanceId());
$this
->assertResponse(403, 'Check that node is protected outside the course, after revoke.');
}
function createCourseObjectUi($courseNode) {
$edit = array();
$edit["more[object_type]"] = "course_content-course_test_content";
$this
->drupalPost(NULL, $edit, t('Add object'));
$this
->assertText(t('Course test content'));
}
function testObjectInstanceDeletion() {
$courseNode = $this
->createCourseNode();
$this
->drupalGet("node/{$courseNode->nid}/course-outline");
$this
->createCourseObjectUi($courseNode, t('Course test content'));
$this
->drupalPost(NULL, array(), t('Save outline'));
$this
->clickLink(t('Settings'));
$this
->drupalPost(NULL, array(
'delete_instance' => 1,
), t('Delete'));
$this
->assertText('Object will be removed from outline, and related instance(s) will be deleted');
$this
->drupalPost(NULL, array(), t('Save outline'));
}
}