comparison core/modules/node/tests/src/Kernel/NodeOwnerTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
4 4
5 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; 5 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
6 use Drupal\language\Entity\ConfigurableLanguage; 6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\node\Entity\Node; 7 use Drupal\node\Entity\Node;
8 use Drupal\node\Entity\NodeType; 8 use Drupal\node\Entity\NodeType;
9 use Drupal\user\Entity\User;
9 10
10 /** 11 /**
11 * Tests node owner functionality. 12 * Tests node owner functionality.
12 * 13 *
13 * @group Entity 14 * @group Entity
73 $this->assertEqual(0, $english->getOwnerId()); 74 $this->assertEqual(0, $english->getOwnerId());
74 $this->assertEqual(0, $german->getOwnerId()); 75 $this->assertEqual(0, $german->getOwnerId());
75 $this->assertEqual(0, $italian->getOwnerId()); 76 $this->assertEqual(0, $italian->getOwnerId());
76 } 77 }
77 78
79 /**
80 * Test an unsaved node owner.
81 */
82 public function testUnsavedNodeOwner() {
83 $user = User::create([
84 'name' => 'foo',
85 ]);
86 $node = Node::create([
87 'type' => 'page',
88 'title' => $this->randomMachineName(),
89 ]);
90 // Set the node owner while the user is unsaved and then immediately save
91 // the user and node.
92 $node->setOwner($user);
93 $user->save();
94 $node->save();
95
96 // The ID assigned to the newly saved user will now be the owner ID of the
97 // node.
98 $this->assertEquals($user->id(), $node->getOwnerId());
99 }
100
101 /**
102 * Tests the legacy method used as the default entity owner.
103 *
104 * @group legacy
105 * @expectedDeprecation The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.
106 */
107 public function testGetCurrentUserId() {
108 $this->assertEquals(['0'], Node::getCurrentUserId());
109 }
110
78 } 111 }