public function NodeOwnerTest::testUnsavedNodeOwner in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Kernel/NodeOwnerTest.php \Drupal\Tests\node\Kernel\NodeOwnerTest::testUnsavedNodeOwner()
- 9 core/modules/node/tests/src/Kernel/NodeOwnerTest.php \Drupal\Tests\node\Kernel\NodeOwnerTest::testUnsavedNodeOwner()
Tests an unsaved node owner.
File
- core/
modules/ node/ tests/ src/ Kernel/ NodeOwnerTest.php, line 82
Class
- NodeOwnerTest
- Tests node owner functionality.
Namespace
Drupal\Tests\node\KernelCode
public function testUnsavedNodeOwner() {
$user = User::create([
'name' => 'foo',
]);
$node = Node::create([
'type' => 'page',
'title' => $this
->randomMachineName(),
]);
// Set the node owner while the user is unsaved and then immediately save
// the user and node.
$node
->setOwner($user);
$user
->save();
$node
->save();
// The ID assigned to the newly saved user will now be the owner ID of the
// node.
$this
->assertEquals($user
->id(), $node
->getOwnerId());
}