You are here

CourseObjectNodeTestCase.test in Course 7.2

File

tests/CourseObjectNodeTestCase.test
View source
<?php

/**
 * Description of CourseObjectNodeTestCase
 */
class CourseObjectNodeTestCase extends CourseTestCase {
  public static function getInfo() {

    // Note that getInfo() strings are not translated with t().
    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;
  }

  /**
   * Test content privacy for node based course objects.
   */
  function testContentAccess() {
    $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
      ->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.');
  }

  /**
   * Create a course object through the interface.
   *
   * @param stdClass $courseNode
   */
  function createCourseObjectUi($courseNode) {

    // Add a new course content object.
    $edit = array();
    $edit["more[object_type]"] = "course_content-course_test_content";
    $this
      ->drupalPost(NULL, $edit, t('Add object'));
    $this
      ->assertText(t('Course test content'));
  }

  /**
   * Test that an object's instance can be deleted.
   */
  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'));
  }

}

Classes

Namesort descending Description
CourseObjectNodeTestCase Description of CourseObjectNodeTestCase