Namespace
Drupal\KernelTests\Core\Entity
File
core/tests/Drupal/KernelTests/Core/Entity/BaseFieldOverrideValidationTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\KernelTests\Core\Entity;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\entity_test\Entity\EntityTestBundle;
use Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
class BaseFieldOverrideValidationTest extends ConfigEntityValidationTestBase {
use ContentTypeCreationTrait;
protected static $modules = [
'entity_test',
'field',
'node',
'text',
'user',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig('node');
$this
->createContentType([
'type' => 'one',
]);
$this
->createContentType([
'type' => 'another',
]);
EntityTestBundle::create([
'id' => 'one',
])
->save();
EntityTestBundle::create([
'id' => 'another',
])
->save();
$fields = $this->container
->get('entity_field.manager')
->getBaseFieldDefinitions('node');
$this->entity = BaseFieldOverride::createFromBaseFieldDefinition($fields['uuid'], 'one');
$this->entity
->save();
}
public function testTargetBundleMustExist() : void {
$this->entity
->set('bundle', 'nope');
$this
->assertValidationErrors([
'' => "The 'bundle' property cannot be changed.",
'bundle' => "The 'nope' bundle does not exist on the 'node' entity type.",
]);
}
public function testImmutableProperties(array $valid_values = []) : void {
$this->entity
->set('settings', []);
parent::testImmutableProperties([
'entity_type' => 'entity_test_with_bundle',
'bundle' => 'another',
'field_type' => 'string',
]);
}
public function testFieldTypePluginIsValidated() : void {
$this->entity = $this->entity
->createDuplicate()
->set('field_type', 'invalid');
$this
->assertValidationErrors([
'field_type' => "The 'invalid' plugin does not exist.",
]);
}
}
Classes