PreviewLinkEntityTest.php in Preview Link 2.0.x
File
tests/src/Kernel/PreviewLinkEntityTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\preview_link\Kernel;
use Drupal\entity_test\Entity\EntityTestRevPub;
use Drupal\preview_link\Entity\PreviewLink;
class PreviewLinkEntityTest extends PreviewLinkBase {
public static $modules = [
'preview_link',
'preview_link_test',
'entity_test',
];
public function testGetEntities() : void {
$previewLink = PreviewLink::create();
$entity = EntityTestRevPub::create();
$previewLink->entities = [
$entity,
];
$this
->assertCount(1, $previewLink
->getEntities());
}
public function testSetEntities() : void {
$previewLink = PreviewLink::create();
$entity = EntityTestRevPub::create();
$previewLink
->setEntities([
$entity,
]);
$this
->assertCount(1, $previewLink->entities
->referencedEntities());
$previewLink
->setEntities([
$entity,
]);
$this
->assertCount(1, $previewLink->entities
->referencedEntities());
}
public function testAddEntity() : void {
$previewLink = PreviewLink::create();
$entity = EntityTestRevPub::create();
$this
->assertCount(0, $previewLink->entities
->referencedEntities());
$previewLink
->addEntity($entity);
$this
->assertCount(1, $previewLink->entities
->referencedEntities());
}
public function testDefaultSettings() : void {
$definition = \Drupal::entityTypeManager()
->getDefinition('preview_link');
$baseFields = PreviewLink::baseFieldDefinitions($definition);
$settings = $baseFields['entities']
->getSettings();
$this
->assertTrue($settings['exclude_entity_types']);
$this
->assertEquals([], $settings['entity_type_ids']);
$this
->assertEquals([
'handler' => 'preview_link',
'handler_settings' => [],
], $settings['entity_test_mulrevpub']);
}
}