function CourseObjectAccessTestCase::testHiddenCourseObjects in Course 7
Same name and namespace in other branches
- 6 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testHiddenCourseObjects()
- 7.2 tests/CourseObjectAccessTestCase.test \CourseObjectAccessTestCase::testHiddenCourseObjects()
Test hidden course objects do not show up in the course outline but block completion.
File
- tests/
CourseObjectAccessTestCase.test, line 154
Class
- CourseObjectAccessTestCase
- Tests for course object access.
Code
function testHiddenCourseObjects() {
// 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 in the outline.
$this
->assertTrue($o1
->access('see', $user));
// Make object hidden.
$o1
->setOption('hidden', 1)
->save();
$this
->assertFalse($o1
->access('see', $user));
$this
->assertFalse($o1
->access('take', $user));
$this
->assertFalse($o1
->access('view', $user));
$this
->drupalGet("node/{$courseNode->nid}/takecourse");
$this
->drupalGet("node/{$courseNode->nid}/course-object/{$o_optional->coid}");
$this
->assertNoLink(t('Next'));
$this
->drupalGet("node/{$courseNode->nid}/course-object/{$o1->coid}");
$this
->assertResponse(403, t('Hidden object is not accessible.'));
// Check that the course is not complete without completing the hidden object.
$report = course_report_load($courseNode, $user);
$this
->assertFalse($report->complete);
}