You are here

public function CourseObjectManualTest::testCourseObjectManual in Course 3.x

Test manual course object functionality.

File

modules/course_object_manual/tests/src/Functional/CourseObjectManualTest.php, line 21

Class

CourseObjectManualTest
Tests quizzes in courses.

Namespace

Drupal\Tests\course_object_manual\Functional

Code

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

  // Set up a manual course object.
  $course = $this
    ->createCourse();
  $co1 = CourseObject::create([
    'object_type' => 'manual',
  ]);
  $co1
    ->setCourse($course);
  $co1
    ->save();

  // Take the course.
  $course
    ->enroll($account);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($co1
    ->getUrl());
  $this
    ->assertText('Your instructor has not given you a pass/fail grade yet.');

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

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