public function BaseFieldOverrideTest::testDefaultValueCallback in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php \Drupal\KernelTests\Core\Field\Entity\BaseFieldOverrideTest::testDefaultValueCallback()
Tests the default value callback.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Field/ Entity/ BaseFieldOverrideTest.php, line 73
Class
- BaseFieldOverrideTest
- @coversDefaultClass \Drupal\Core\Field\Entity\BaseFieldOverride @group Field
Namespace
Drupal\KernelTests\Core\Field\EntityCode
public function testDefaultValueCallback() {
$base_field = BaseFieldDefinition::create('entity_reference')
->setName('Test Field')
->setTargetEntityTypeId('entity_test')
->setDefaultValueCallback(static::class . '::defaultValueCallbackPrimitive');
$base_field_override = BaseFieldOverride::createFromBaseFieldDefinition($base_field, 'test_bundle');
$entity = EntityTest::create([]);
$this
->assertEquals([
[
'target_id' => 99,
],
], $base_field
->getDefaultValue($entity));
$this
->assertEquals([
[
'target_id' => 99,
],
], $base_field_override
->getDefaultValue($entity));
}