function NodeCreationTest::testNodeCreation

Creates a "Basic page" node and verifies its consistency in the database.

File

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

Class

NodeCreationTest
Tests creating and saving a node.

Namespace

Drupal\node\Tests

Code

function testNodeCreation() {

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

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

  // Check that the node exists in the database.
  $node = $this
    ->drupalGetNodeByTitle($edit["title"]);
  $this
    ->assertTrue($node, 'Node found in database.');
}