function BaseFieldOverrideTest::testDefaultValueCallback
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php \Drupal\KernelTests\Core\Field\Entity\BaseFieldOverrideTest::testDefaultValueCallback()
- 10 core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php \Drupal\KernelTests\Core\Field\Entity\BaseFieldOverrideTest::testDefaultValueCallback()
- 11.x core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php \Drupal\KernelTests\Core\Field\Entity\BaseFieldOverrideTest::testDefaultValueCallback()
Test 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));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.