function CourseObjectAccessTestCase::testDisabledCourseObjects in Course 7.2
Same name and namespace in other branches
- 6 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testDisabledCourseObjects()
- 7 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testDisabledCourseObjects()
Test disabled course objects do not show up in the course outline and do not block completion.
File
- tests/
CourseObjectAccessTestCase.test, line 194
Class
- CourseObjectAccessTestCase
- Tests for course object access.
Code
function testDisabledCourseObjects() {
// Create a course.
$courseNode = $this
->createCourseNode();
// Use the student user.
$user = $this->student_user;
$this
->drupalLogin($user);
// Create an optional object so we can test the "Next" button.
$o_optional = $this
->createCourseObject($courseNode);
$o_optional
->setOption('required', FALSE)
->save();
$o1 = $this
->createCourseObject($courseNode);
$o1
->setOption('required', TRUE)
->save();
// By default, should be visible.
$this
->assertTrue($o1
->access('see', $user));
// Make object disabled.
$o1
->setOption('enabled', 0)
->save();
$this
->assertFalse($o1
->access('see', $user));
$this
->assertFalse($o1
->access('view', $user));
$this
->assertFalse($o1
->access('take', $user));
$this
->drupalGet("node/{$courseNode->nid}/takecourse");
// Completion link.
$this
->clickLink(t('Next'));
$this
->assertNoResponse(403, t('Did not get access denied.'));
$this
->drupalGet("node/{$courseNode->nid}/course-object/{$o1->coid}");
$this
->assertResponse(403, t('Disabled object is not accessible.'));
// Check that the course is complete even without completing the disabled
// object.
$report = course_report_load($courseNode, $user);
$this
->assertTrue($report->complete);
// Set the disabled object to be at the beginning of the course.
$o1
->setOption('weight', -100)
->save();
// Try with a new user.
$this->student_user = $this
->drupalCreateUser(array(
'access content',
));
$this
->drupalLogin($this->student_user);
$this
->drupalGet("node/{$courseNode->nid}/takecourse");
$this
->drupalGet("node/{$courseNode->nid}/course-object/{$o1->coid}");
$this
->assertResponse(403, t('Disabled first object is not accessible.'));
$this
->drupalGet("node/{$courseNode->nid}/course-object/{$o_optional->coid}");
$this
->assertResponse(200, t('Second object is accessible.'));
}