You are here

CourseObjectManualTest.php in Course 3.x

File

modules/course_object_manual/tests/src/Functional/CourseObjectManualTest.php
View source
<?php

namespace Drupal\Tests\course_object_manual\Functional;

use Drupal\course\Entity\CourseObject;
use Drupal\Tests\course\Functional\CourseObjectTest;
use function course_get_course_object_by_id;

/**
 * Tests quizzes in courses.
 *
 * @group course_object_manual
 */
class CourseObjectManualTest extends CourseObjectTest {
  protected static $modules = [
    'course_object_manual',
  ];

  /**
   * Test manual course object functionality.
   */
  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.');
  }

}

Classes

Namesort descending Description
CourseObjectManualTest Tests quizzes in courses.