You are here

public function ExampleFixtureManagementTest::testNodeCreation in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/testing_example/tests/src/Kernel/ExampleFixtureManagementTest.php \Drupal\Tests\testing_example\Kernel\ExampleFixtureManagementTest::testNodeCreation()

Create a node by using createNode() from NodeCreationTrait.

File

testing_example/tests/src/Kernel/ExampleFixtureManagementTest.php, line 92

Class

ExampleFixtureManagementTest
Demonstrate manipulating fixture data in a kernel test.

Namespace

Drupal\Tests\testing_example\Kernel

Code

public function testNodeCreation() {

  // Unless there's a specific reason to do so, strings in tests should not be
  // translated with t().
  $nodeTitle = 'Test Node!';

  /** @var \Drupal\node\NodeInterface $node */
  $node = $this
    ->createNode([
    'title' => $nodeTitle,
    'type' => 'page',
    'uid' => $this->owner
      ->id(),
  ]);

  // Assert that the node we created has the title we expect.
  $this
    ->assertEquals($nodeTitle, $node
    ->getTitle());
}