You are here

function NodeCreationTest::testUnpublishedNodeCreation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeCreationTest.php \Drupal\node\Tests\NodeCreationTest::testUnpublishedNodeCreation()

Creates an unpublished node and confirms correct redirect behavior.

File

core/modules/node/src/Tests/NodeCreationTest.php, line 123
Contains \Drupal\node\Tests\NodeCreationTest.

Class

NodeCreationTest
Create a node and test saving it.

Namespace

Drupal\node\Tests

Code

function testUnpublishedNodeCreation() {

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

  // Set "Basic page" content type to be unpublished by default.
  $fields = \Drupal::entityManager()
    ->getFieldDefinitions('node', 'page');
  $fields['status']
    ->getConfig('page')
    ->setDefaultValue(FALSE)
    ->save();

  // Create a node.
  $edit = array();
  $edit['title[0][value]'] = $this
    ->randomMachineName(8);
  $edit['body[0][value]'] = $this
    ->randomMachineName(16);
  $this
    ->drupalPostForm('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[0][value]'],
  )));
}