You are here

public function NodeTypeExampleTest::testNodeCreation in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/node_type_example/tests/src/Functional/NodeTypeExampleTest.php \Drupal\Tests\node_type_example\Functional\NodeTypeExampleTest::testNodeCreation()

Test that all fields are displayed when content is created.

File

node_type_example/tests/src/Functional/NodeTypeExampleTest.php, line 135

Class

NodeTypeExampleTest
Test that our content types are successfully created.

Namespace

Drupal\Tests\node_type_example\Functional

Code

public function testNodeCreation() {

  // Login content creator.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'create basic_content_type content',
    'create locked_content_type content',
  ]));

  // Create random strings to insert data into fields.
  $title = 'Test title.';
  $body = 'Test body.';
  $edit = [];
  $edit['title[0][value]'] = $title;
  $edit['body[0][value]'] = $body;

  // Create a basic_content_type content.
  $this
    ->drupalPostForm('/node/add/basic_content_type', $edit, 'Save');

  // Verify all fields and data of created content is shown.
  $this
    ->assertText($title);
  $this
    ->assertText($body);

  // Create a locked_content_type content.
  $this
    ->drupalPostForm('/node/add/locked_content_type', $edit, 'Save');

  // Verify all fields and data of created content is shown.
  $this
    ->assertText($title);
  $this
    ->assertText($body);
}