public function NodeFieldOverridesTest::testFieldOverrides in Drupal 8
Same name and namespace in other branches
- 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($config
->get('default_value_callback'), 'Drupal\\node\\Entity\\Node::getDefaultEntityOwner');
/** @var \Drupal\node\NodeInterface $node */
$node = Node::create([
'type' => 'ponies',
]);
$owner = $node
->getOwner();
$this
->assertInstanceOf(UserInterface::class, $owner);
$this
->assertEqual($owner
->id(), $this->user
->id());
}