function CertificateTest::testCertificateTemplates in Certificate 4.x
Test the token replacement inside of certificates.
File
- tests/
src/ Functional/ CertificateTest.php, line 157
Class
- CertificateTest
- Tests for Certificate.
Namespace
Drupal\Tests\certificate\FunctionalCode
function testCertificateTemplates() {
$activity = Drupal::entityTypeManager()
->getStorage($this->content_type)
->create();
$activity
->set('name', 'My test certifiable type');
$activity
->save();
// We give them the permission because we have to preview it here.
$account = $this
->createUser([
'administer certificate',
'view certificate_test_entity',
], 'certified2', FALSE, [
'mail' => 'certified@example.com',
]);
$firstletter = $account
->getAccountName()[0];
$this
->drupalLogin($account);
$this->landscape_certificate
->set('certificate_body', 'activity title: [certificate_test_entity:name] user name: [user:name]')
->save();
// Set globals
$config = \Drupal::configFactory()
->getEditable('certificate.settings');
$config
->set('maps', [
'firstletter' => [
$firstletter => $this->landscape_certificate
->id(),
],
]);
// Turn off snapshots because we have to award a different certificate.
$config
->set('snapshots', 0);
$config
->save();
$this
->drupalGet("certificate_test_entity/{$activity->id()}/certificate", array(
'query' => array(
'certificate_ok' => 1,
'preview' => TRUE,
),
));
$this
->assertText("activity title: {$activity->label()} user name: {$account->getAccountName()}", "Saw certificate body.");
}