OpignoCertificateTest.php in Opigno certificate 3.x
File
tests/src/Kernel/OpignoCertificateTest.php
View source
<?php
namespace Drupal\Tests\opigno_certificate\Kernel;
use Drupal\Core\Session\AccountInterface;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
class OpignoCertificateTest extends EntityKernelTestBase {
public static $modules = [
'opigno_certificate',
'opigno_certificate_config_test',
'options',
];
protected $entityTypeManager;
protected function setUp() {
parent::setUp();
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this
->installConfig([
'opigno_certificate_config_test',
]);
$this
->installEntitySchema('opigno_certificate');
}
public function testCreate() {
$opigno_certificate = $this->entityTypeManager
->getStorage('opigno_certificate')
->create([
'bundle' => 'opigno_certificate',
'label' => $this
->randomString(),
]);
$this
->assertTrue($opigno_certificate, 'Default certificate was created successfully.');
$this
->assertEquals(SAVED_NEW, $opigno_certificate
->save(), 'Default certificate was saved successfully.');
$template_certificate = $this->entityTypeManager
->getStorage('opigno_certificate')
->create([
'bundle' => 'template',
'label' => $this
->randomString(),
]);
$this
->assertTrue($template_certificate, 'Template type certificate was created successfully.');
$this
->assertEquals(SAVED_NEW, $template_certificate
->save(), 'Template type certificate was saved successfully.');
}
protected function setCurrentUser(AccountInterface $account) {
$this->container
->get('current_user')
->setAccount($account);
}
protected function getCurrentUser() {
return $this->container
->get('current_user')
->getAccount();
}
}