public function NodeTypeTest::testNodeTypeCreation in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeCreation()
Tests creating a content type programmatically and via a form.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeTypeTest.php, line 55
Class
- NodeTypeTest
- Ensures that node type functions work correctly.
Namespace
Drupal\Tests\node\FunctionalCode
public function testNodeTypeCreation() {
// Create a content type programmatically.
$type = $this
->drupalCreateContentType();
$type_exists = (bool) NodeType::load($type
->id());
$this
->assertTrue($type_exists, 'The new content type has been created in the database.');
// Log in a test user.
$web_user = $this
->drupalCreateUser([
'create ' . $type
->label() . ' content',
]);
$this
->drupalLogin($web_user);
$this
->drupalGet('node/add/' . $type
->id());
$this
->assertSession()
->statusCodeEquals(200);
// Create a content type via the user interface.
$web_user = $this
->drupalCreateUser([
'bypass node access',
'administer content types',
]);
$this
->drupalLogin($web_user);
$this
->drupalGet('node/add');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config:node_type_list');
$this
->assertCacheContext('user.permissions');
$elements = $this
->cssSelect('dl.node-type-list dt');
$this
->assertCount(3, $elements);
$edit = [
'name' => 'foo',
'title_label' => 'title for foo',
'type' => 'foo',
];
$this
->drupalGet('admin/structure/types/add');
$this
->submitForm($edit, 'Save and manage fields');
$type_exists = (bool) NodeType::load('foo');
$this
->assertTrue($type_exists, 'The new content type has been created in the database.');
$this
->drupalGet('node/add');
$elements = $this
->cssSelect('dl.node-type-list dt');
$this
->assertCount(4, $elements);
}