public function NodeFieldOverridesTest::testFieldOverrides in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Kernel/NodeFieldOverridesTest.php \Drupal\Tests\node\Kernel\NodeFieldOverridesTest::testFieldOverrides()
- 9 core/modules/node/tests/src/Kernel/NodeFieldOverridesTest.php \Drupal\Tests\node\Kernel\NodeFieldOverridesTest::testFieldOverrides()
Tests that field overrides work as expected.
File
- core/
modules/ node/ tests/ src/ Kernel/ NodeFieldOverridesTest.php, line 45
Class
- NodeFieldOverridesTest
- Tests node field overrides.
Namespace
Drupal\Tests\node\KernelCode
public function testFieldOverrides() {
if (!NodeType::load('ponies')) {
NodeType::create([
'name' => 'Ponies',
'type' => 'ponies',
])
->save();
}
$override = BaseFieldOverride::loadByName('node', 'ponies', 'uid');
if ($override) {
$override
->delete();
}
$uid_field = \Drupal::service('entity_field.manager')
->getBaseFieldDefinitions('node')['uid'];
$config = $uid_field
->getConfig('ponies');
$config
->save();
$this
->assertEquals('Drupal\\node\\Entity\\Node::getDefaultEntityOwner', $config
->get('default_value_callback'));
/** @var \Drupal\node\NodeInterface $node */
$node = Node::create([
'type' => 'ponies',
]);
$owner = $node
->getOwner();
$this
->assertInstanceOf(UserInterface::class, $owner);
$this
->assertEquals($this->user
->id(), $owner
->id());
}