You are here

function CourseObjectNodeTestCase::testContentAccess in Course 7

Same name and namespace in other branches
  1. 6 tests/CourseObjectNodeTestCase.test \CourseObjectNodeTestCase::testContentAccess()
  2. 7.2 tests/CourseObjectNodeTestCase.test \CourseObjectNodeTestCase::testContentAccess()

Test content privacy for node based course objects.

File

tests/CourseObjectNodeTestCase.test, line 28

Class

CourseObjectNodeTestCase
Description of CourseObjectNodeTestCase

Code

function testContentAccess() {
  $user = $this
    ->drupalLogin($this->student_user);
  $courseNode = $this
    ->createCourseNode();
  $course = course_get_course($courseNode);

  // Create the course object
  $co1 = course_get_course_object('course_content', 'course_test_content');
  $co1
    ->setOption('private', 1);
  $co1
    ->setCourse($course);
  $co1
    ->setUser($this->admin_user);
  $co1
    ->save();
  node_access_rebuild();
  $co1
    ->setUser($this->student_user);
  course_enroll($courseNode, $user);
  $this
    ->drupalGet("node/" . $co1
    ->getInstanceId());
  $this
    ->assertResponse(403, 'Check that node is protected outside the course.');
  $co1
    ->grant();
  $this
    ->drupalGet("node/" . $co1
    ->getInstanceId());
  $this
    ->assertResponse(200, 'Check that node is accessible when user enters course object.');
  $co1
    ->revoke();
  $this
    ->drupalGet("node/" . $co1
    ->getInstanceId());
  $this
    ->assertResponse(403, 'Check that node is protected outside the course, after revoke.');
}