ContentEntityStorageBaseTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Entity/ContentEntityStorageBaseTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\KernelTests\KernelTestBase;
class ContentEntityStorageBaseTest extends KernelTestBase {
protected static $modules = [
'entity_test',
'user',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
}
public function testCreate($bundle) {
$storage = $this->container
->get('entity_type.manager')
->getStorage('entity_test');
$entity = $storage
->create([
'type' => $bundle,
]);
$this
->assertEquals('test_bundle', $entity
->bundle());
}
public function providerTestCreate() {
return [
[
'scalar' => 'test_bundle',
],
[
'array keyed by delta' => [
0 => [
'value' => 'test_bundle',
],
],
],
[
'array keyed by main property name' => [
'value' => 'test_bundle',
],
],
];
}
public function testReCreate() {
$storage = $this->container
->get('entity_type.manager')
->getStorage('entity_test');
$values = $storage
->create([
'type' => 'test_bundle',
])
->toArray();
$entity = $storage
->create($values);
$this
->assertEquals('test_bundle', $entity
->bundle());
}
}