protected function NodeEditFormTest::checkVariousAuthoredByValues in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/NodeEditFormTest.php \Drupal\node\Tests\NodeEditFormTest::checkVariousAuthoredByValues()
 
Checks that the "authored by" works correctly with various values.
Parameters
\Drupal\node\NodeInterface $node: A node object.
string $form_element_name: The name of the form element to populate.
1 call to NodeEditFormTest::checkVariousAuthoredByValues()
- NodeEditFormTest::testNodeEditAuthoredBy in core/
modules/ node/ src/ Tests/ NodeEditFormTest.php  - Tests changing a node's "authored by" field.
 
File
- core/
modules/ node/ src/ Tests/ NodeEditFormTest.php, line 188  - Contains \Drupal\node\Tests\NodeEditFormTest.
 
Class
- NodeEditFormTest
 - Create a node and test node edit functionality.
 
Namespace
Drupal\node\TestsCode
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.');
}