EntityDescriptionTest.php in Lightning Core 8.3
File
tests/src/Kernel/EntityDescriptionTest.php
View source
<?php
namespace Drupal\Tests\lightning_core\Kernel;
use Drupal\Core\Entity\EntityDescriptionInterface;
use Drupal\KernelTests\KernelTestBase;
class EntityDescriptionTest extends KernelTestBase {
public static $modules = [
'lightning_core',
'user',
];
public function provider() {
return [
[
'entity_form_mode',
],
[
'entity_view_mode',
],
[
'user_role',
],
];
}
public function testEntityDescription($entity_type_id, array $values = [], $form_operation = 'default') {
$entity = $this->container
->get('entity_type.manager')
->getStorage($entity_type_id)
->create($values);
$this
->assertInstanceOf(EntityDescriptionInterface::class, $entity);
$description = $this
->randomString(32);
$this
->assertEmpty($entity
->getDescription());
$entity
->setDescription($description);
$this
->assertEquals($description, $entity
->getDescription());
if ($entity
->getEntityType()
->getFormClass($form_operation)) {
$form = $this->container
->get('entity.form_builder')
->getForm($entity, $form_operation);
$this
->assertInternalType('array', $form['description']);
$this
->assertEquals($description, $form['description']['#default_value']);
}
}
}