コード例 #1
0
ファイル: NodeEditFormTest.php プロジェクト: ddrozdik/dmaps
 /**
  * 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, $form_element_name)
 {
     // Try to change the 'authored by' field to an invalid user name.
     $edit = array($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[$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());
     $uid = $node->getOwnerId();
     // Most SQL database drivers stringify fetches but entities are not
     // necessarily stored in a SQL database. At the same time, NULL/FALSE/""
     // won't do.
     $this->assertTrue($uid === 0 || $uid === '0', 'Node authored by anonymous user.');
     // Change the authored by field to another user's name (that is not
     // logged in).
     $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());
     $this->assertIdentical($node->getOwnerId(), $this->webUser->id(), 'Node authored by normal user.');
 }