public function NodeCreationTest::testUnpublishedNodeCreation in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::testUnpublishedNodeCreation()
Creates an unpublished node and confirms correct redirect behavior.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeCreationTest.php, line 149
Class
- NodeCreationTest
- Create a node and test saving it.
Namespace
Drupal\Tests\node\FunctionalCode
public function testUnpublishedNodeCreation() {
// Set the front page to the test page.
$this
->config('system.site')
->set('page.front', '/test-page')
->save();
// Set "Basic page" content type to be unpublished by default.
$fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions('node', 'page');
$fields['status']
->getConfig('page')
->setDefaultValue(FALSE)
->save();
// Create a node.
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName(8);
$edit['body[0][value]'] = $this
->randomMachineName(16);
$this
->drupalGet('node/add/page');
$this
->submitForm($edit, 'Save');
// Check that the user was redirected to the home page.
$this
->assertSession()
->addressEquals('');
$this
->assertSession()
->pageTextContains('Test page text');
// Confirm that the node was created.
$this
->assertSession()
->pageTextContains('Basic page ' . $edit['title[0][value]'] . ' has been created.');
// Verify that the creation message contains a link to a node.
$this
->assertSession()
->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
}