function ExampleFunctionalTest::testNewPageApiCreate
Same name in other branches
- 4.0.x modules/testing_example/tests/src/Functional/ExampleFunctionalTest.php \Drupal\Tests\testing_example\Functional\ExampleFunctionalTest::testNewPageApiCreate()
Demonstrate node creation via NodeCreationTrait::createNode.
File
-
modules/
testing_example/ tests/ src/ Functional/ ExampleFunctionalTest.php, line 130
Class
- ExampleFunctionalTest
- Class ExampleFunctionalTest.
Namespace
Drupal\Tests\testing_example\FunctionalCode
public function testNewPageApiCreate() {
$assert = $this->assertSession();
$this->drupalLogin($this->adminUser);
$nodeTitle = 'Test node for testNewPageApiCreate';
// Create new node using API.
$node = $this->drupalCreateNode([
'type' => 'test_content_type',
'title' => $nodeTitle,
'body' => [
[
'format' => filter_default_format($this->adminUser),
'value' => 'Body of test node',
],
],
]);
$node->save();
$url = $node->toUrl();
// Confirm page creation.
$this->drupalGet($url);
$assert->statusCodeEquals(200);
// Log in our normal user and navigate to the node.
$this->drupalLogin($this->authUser);
$this->drupalGet($url);
$assert->statusCodeEquals(200);
// Look at the *page* title.
$assert->titleEquals("{$nodeTitle} | Drupal");
// Find the title of the node itself.
$nodeTitleElement = $this->getSession()
->getPage()
->find('css', 'h1 span');
$this->assertEquals($nodeTitleElement->getText(), $nodeTitle);
}