You are here

public function CourseObjectCertificateTest::testCourseObjectCertificate in Course 3.x

Test manual course object functionality.

File

modules/course_certificate/tests/src/Functional/CourseObjectCertificateTest.php, line 31

Class

CourseObjectCertificateTest
Tests certificates in courses.

Namespace

Drupal\Tests\certificate\Functional

Code

public function testCourseObjectCertificate() {

  // Create a map a certificate.
  $certificate_template = CertificateTemplate::create([
    'title' => 'Test certificate',
    'type' => 'certificate',
  ]);
  $certificate_template
    ->save();
  $settings = Drupal::configFactory()
    ->getEditable('certificate.settings');
  $maps = $settings
    ->get('maps');
  $maps['manual']['manual'] = $certificate_template
    ->id();
  $settings
    ->set('maps', $maps)
    ->save();

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

  // Take the course.
  $course
    ->enroll($this->student_user);
  $this
    ->drupalLogin($this->student_user);
  $this
    ->drupalGet($course
    ->getUrl()
    ->toString());
  $this
    ->clickLink('Complete');

  // Check the course landing page link.
  $this
    ->assertLink('Download certificate');
}