function NodeTypeExampleTest::testNodeCreation

Same name in other branches
  1. 4.0.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

modules/node_type_example/tests/src/Functional/NodeTypeExampleTest.php, line 138

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->drupalGet('/node/add/basic_content_type');
    $this->submitForm($edit, 'Save');
    // Verify all fields and data of created content is shown.
    $this->assertSession()
        ->pageTextContains($title);
    $this->assertSession()
        ->pageTextContains($body);
    // Create a locked_content_type content.
    $this->drupalGet('/node/add/locked_content_type');
    $this->submitForm($edit, 'Save');
    // Verify all fields and data of created content is shown.
    $this->assertSession()
        ->pageTextContains($title);
    $this->assertSession()
        ->pageTextContains($body);
}