Namespace
Drupal\Tests\ctools_entity_mask\Kernel
File
-
modules/ctools_entity_mask/tests/src/Kernel/EntityMaskTest.php
View source
<?php
namespace Drupal\Tests\ctools_entity_mask\Kernel;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\entity_mask_test\Entity\BlockContent;
use Drupal\KernelTests\KernelTestBase;
class EntityMaskTest extends KernelTestBase {
protected static $modules = [
'block',
'block_content',
'ctools_entity_mask',
'entity_mask_test',
'field',
'field_ui',
'file',
'image',
'link',
'system',
'text',
'user',
];
protected function setUp() : void {
parent::setUp();
$this->installConfig([
'block_content',
'entity_mask_test',
]);
$this->installEntitySchema('fake_block_content');
}
public function testFields() {
$block = BlockContent::create([
'type' => 'basic',
]);
$this->assertTrue($block->hasField('body'));
$this->assertTrue($block->hasField('field_link'));
$this->assertTrue($block->hasField('field_image'));
}
public function testViewDisplays() {
$view_modes = $this->container
->get('entity_display.repository')
->getAllViewModes();
$this->assertSame($view_modes['block_content'], $view_modes['fake_block_content']);
$storage = $this->container
->get('entity_type.manager')
->getStorage('entity_view_display');
$display = $storage->create([
'targetEntityType' => 'fake_block_content',
'bundle' => 'basic',
'mode' => 'default',
'status' => TRUE,
]);
$this->assertTrue($display->isNew());
$components = $display->getComponents();
$this->assertArrayHasKey('body', $components);
$this->assertArrayHasKey('field_link', $components);
$this->assertArrayHasKey('field_image', $components);
}
public function testFormDisplays() {
EntityFormMode::create([
'id' => 'block_content.foobar',
'label' => $this->randomString(),
'targetEntityType' => 'block_content',
])
->save();
$form_modes = $this->container
->get('entity_display.repository')
->getAllFormModes();
$this->assertSame($form_modes['block_content'], $form_modes['fake_block_content']);
$storage = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display');
$display = $storage->create([
'targetEntityType' => 'fake_block_content',
'bundle' => 'basic',
'mode' => 'default',
'status' => TRUE,
]);
$this->assertTrue($display->isNew());
$components = $display->getComponents();
$this->assertArrayHasKey('body', $components);
$this->assertArrayHasKey('field_link', $components);
$this->assertArrayHasKey('field_image', $components);
}
public function testNoTables() {
$entity_type = $this->container
->get('entity_type.manager')
->getDefinition('fake_block_content');
$this->assertNull($entity_type->getBaseTable());
$this->assertNull($entity_type->getDataTable());
$this->assertNull($entity_type->getRevisionTable());
$this->assertNull($entity_type->getRevisionDataTable());
}
public function testNotExposedToFieldUI() {
$entity_type = $this->container
->get('entity_type.manager')
->getDefinition('fake_block_content');
$this->assertNull($entity_type->get('field_ui_base_route'));
}
public function testSerialization() {
$body = $this->getRandomGenerator()
->paragraphs(2);
$link = 'https://www.drupal.org/project/ctools';
$block = BlockContent::create([
'type' => 'basic',
'body' => $body,
'field_link' => $link,
]);
$block = serialize($block);
$block = unserialize($block);
$this->assertSame($body, $block->body->value);
$this->assertSame($link, $block->field_link->uri);
}
public function testIsNew() {
$block = BlockContent::create([
'type' => 'basic',
]);
$this->assertTrue($block->isNew());
$block->save();
$this->assertFalse($block->isNew());
}
public function testId() {
$block = BlockContent::create([
'type' => 'basic',
]);
$this->assertSame($block->id(), $block->uuid());
$block->save();
$this->assertSame($block->id(), $block->uuid());
}
public function testLoad() {
$block = BlockContent::create([
'type' => 'basic',
]);
$block->save();
$storage = $this->container
->get('entity_type.manager')
->getStorage('fake_block_content');
$id = $block->id();
$this->assertNull($storage->load($id));
$this->assertEmpty($storage->loadMultiple([
$id,
]));
}
public function testDelete() {
$block = BlockContent::create([
'type' => 'basic',
]);
$block->save();
$id = $block->id();
$this->assertNotEmpty($id);
$block->delete();
}
public function testSave() {
$body = $this->getRandomGenerator()
->paragraphs(2);
$link = 'https://www.drupal.org/project/ctools';
$block = BlockContent::create([
'type' => 'basic',
'body' => $body,
'field_link' => $link,
]);
$this->assertSame($body, $block->body->value);
$this->assertSame($link, $block->field_link->uri);
}
}
Classes
| Title |
Deprecated |
Summary |
| EntityMaskTest |
|
Basic test of entity type masking. |