You are here

public function CourseObjectManualTestCase::testCourseObjectManual in Course 7

Same name and namespace in other branches
  1. 8.3 modules/course_object_manual/tests/src/Functional/CourseObjectManualTestCase.php \CourseObjectManualTestCase::testCourseObjectManual()
  2. 8.2 modules/course_object_manual/tests/src/Functional/CourseObjectManualTestCase.php \CourseObjectManualTestCase::testCourseObjectManual()
  3. 7.2 modules/course_object_manual/course_object_manual.test \CourseObjectManualTestCase::testCourseObjectManual()

Test manual course object functionality.

File

modules/course_object_manual/course_object_manual.test, line 26

Class

CourseObjectManualTestCase
Tests for manual course objects.

Code

public function testCourseObjectManual() {
  $account = $this
    ->drupalCreateUser();

  // Set up a manual course object.
  $node = $this
    ->createCourseNode();
  $course = course_get_course($node);
  $co1 = course_get_course_object('course_object_manual', 'manual');
  $co1
    ->setCourse($course);
  $co1
    ->save();

  // Get the course object in the context of the user.
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $account);
  $this
    ->drupalLogin($account);
  course_enroll($node, $account);
  $this
    ->drupalGet($co1
    ->getUrl());
  $this
    ->assertText('Your instructor has not given you a pass/fail grade yet.');

  // Test fail.
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $account);
  $co1
    ->getFulfillment()
    ->setGrade(0)
    ->save();
  $this
    ->drupalGet($co1
    ->getUrl());
  $this
    ->assertText('Your instructor has marked you as failed.');

  // Test passing.
  $co1 = course_get_course_object_by_id($co1
    ->getId(), $account);
  $co1
    ->getFulfillment()
    ->setGrade(100)
    ->setComplete(1)
    ->save();
  $this
    ->drupalGet($co1
    ->getUrl());
  $this
    ->assertText('Your instructor has marked you as passed.');
}