function NodeCreationTest::testUnpublishedNodeCreation

Creates an unpublished node and confirms correct redirect behavior.

File

drupal/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php, line 105
Definition of Drupal\node\Tests\NodeCreationTest.

Class

NodeCreationTest
Tests creating and saving a node.

Namespace

Drupal\node\Tests

Code

function testUnpublishedNodeCreation() {

  // Set the front page to the test page.
  config('system.site')
    ->set('page.front', 'test-page')
    ->save();

  // Set "Basic page" content type to be unpublished by default.
  variable_set('node_options_page', array());

  // Create a node.
  $edit = array();
  $edit["title"] = $this
    ->randomName(8);
  $edit["body[" . Language::LANGCODE_NOT_SPECIFIED . "][0][value]"] = $this
    ->randomName(16);
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));

  // Check that the user was redirected to the home page.
  $this
    ->assertUrl('');
  $this
    ->assertText(t('Test page text'));

  // Confirm that the node was created.
  $this
    ->assertRaw(t('!post %title has been created.', array(
    '!post' => 'Basic page',
    '%title' => $edit["title"],
  )));
}