function NodeOwnerTest::testUnsavedNodeOwner
Same name in other branches
- 8.9.x core/modules/node/tests/src/Kernel/NodeOwnerTest.php \Drupal\Tests\node\Kernel\NodeOwnerTest::testUnsavedNodeOwner()
- 10 core/modules/node/tests/src/Kernel/NodeOwnerTest.php \Drupal\Tests\node\Kernel\NodeOwnerTest::testUnsavedNodeOwner()
- 11.x 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 85
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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.