CourseObjectCertificateTest.php in Course 3.x
Namespace
Drupal\Tests\certificate\FunctionalFile
modules/course_certificate/tests/src/Functional/CourseObjectCertificateTest.phpView source
<?php
namespace Drupal\Tests\certificate\Functional;
use Drupal;
use Drupal\certificate\Entity\CertificateTemplate;
use Drupal\Core\Config\Testing\ConfigSchemaChecker;
use Drupal\course\Entity\CourseObject;
use Drupal\Tests\course\Functional\CourseObjectTest;
/**
* Tests certificates in courses.
*
* @group course_object_certificate
*/
class CourseObjectCertificateTest extends CourseObjectTest {
protected static $modules = [
'course_certificate',
];
/**
* @var bool
* @see ConfigSchemaChecker
*
* @todo Printable has schema issues.
*/
protected $strictConfigSchema = FALSE;
/**
* Test manual course object functionality.
*/
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');
}
}
Classes
Name | Description |
---|---|
CourseObjectCertificateTest | Tests certificates in courses. |