diff --git a/core/modules/node/src/Tests/NodeEditFormTest.php b/core/modules/node/src/Tests/NodeEditFormTest.php index ee72090..79fa5ea 100644 --- a/core/modules/node/src/Tests/NodeEditFormTest.php +++ b/core/modules/node/src/Tests/NodeEditFormTest.php @@ -135,7 +135,7 @@ public function testNodeEditAuthoredBy() { $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $this->assertIdentical($node->getOwnerId(), $this->adminUser->id(), 'Node authored by admin user.'); - $this->checkVariousAuthoredByValues($node); + $this->checkVariousAuthoredByValues($node, 'uid[0][target_id]'); // Check that normal users cannot change the authored by information. $this->drupalLogin($this->webUser); @@ -144,7 +144,7 @@ public function testNodeEditAuthoredBy() { // Now test with the Autcomplete (Tags) field widget. /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */ - $form_display = \Drupal::entityManager()->getStorage('entity_form_display')->load('node.article.default'); + $form_display = \Drupal::entityManager()->getStorage('entity_form_display')->load('node.page.default'); $widget = $form_display->getComponent('uid'); $widget['type'] = 'entity_reference_autocomplete_tags'; $widget['settings'] = [ @@ -163,7 +163,7 @@ public function testNodeEditAuthoredBy() { $node = $this->nodeStorage->load($node->id()); $this->assertIdentical($this->webUser->id(), $node->getOwner()->id()); - $this->checkVariousAuthoredByValues($node); + $this->checkVariousAuthoredByValues($node, 'uid[target_id]'); // Hide the 'authored by' field from the form. $form_display->removeComponent('uid')->save(); @@ -178,18 +178,23 @@ public function testNodeEditAuthoredBy() { /** * Checks that the "authored by" works correctly with various values. + * + * @param \Drupal\node\NodeInterface $node + * A node object. + * @param string $form_element_name + * The name of the form element to populate. */ - protected function checkVariousAuthoredByValues(NodeInterface $node) { + protected function checkVariousAuthoredByValues(NodeInterface $node, $form_element_name) { // Try to change the 'authored by' field to an invalid user name. $edit = array( - 'uid[0][target_id]' => 'invalid-name', + $form_element_name => 'invalid-name', ); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $this->assertRaw(t('There are no entities matching "%name".', array('%name' => 'invalid-name'))); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). - $edit['uid[0][target_id]'] = ''; + $edit[$form_element_name] = ''; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $this->nodeStorage->resetCache(array($node->id())); $node = $this->nodeStorage->load($node->id()); @@ -201,7 +206,7 @@ protected function checkVariousAuthoredByValues(NodeInterface $node) { // Change the authored by field to another user's name (that is not // logged in). - $edit['uid[0][target_id]'] = $this->webUser->getUsername(); + $edit[$form_element_name] = $this->webUser->getUsername(); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $this->nodeStorage->resetCache(array($node->id())); $node = $this->nodeStorage->load($node->id());