class NodeFieldOverridesTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Kernel/NodeFieldOverridesTest.php \Drupal\Tests\node\Kernel\NodeFieldOverridesTest
- 9 core/modules/node/tests/src/Kernel/NodeFieldOverridesTest.php \Drupal\Tests\node\Kernel\NodeFieldOverridesTest
Tests node field overrides.
@group node
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
- class \Drupal\Tests\node\Kernel\NodeFieldOverridesTest
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses UserCreationTrait
Expanded class hierarchy of NodeFieldOverridesTest
File
- core/
modules/ node/ tests/ src/ Kernel/ NodeFieldOverridesTest.php, line 16
Namespace
Drupal\Tests\node\KernelView source
class NodeFieldOverridesTest extends EntityKernelTestBase {
/**
* Current logged in user.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'user',
'system',
'field',
'node',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'user',
]);
$this->user = $this
->createUser();
\Drupal::service('current_user')
->setAccount($this->user);
}
/**
* Tests that field overrides work as expected.
*/
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());
}
}