function NodeTypeTest::testNodeTypeEditing
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeEditing()
- 8.9.x core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeEditing()
- 11.x core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeEditing()
Tests editing a node type using the UI.
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeTypeTest.php, line 107
Class
- NodeTypeTest
- Ensures that node type functions work correctly.
Namespace
Drupal\Tests\node\FunctionalCode
public function testNodeTypeEditing() : void {
$assert = $this->assertSession();
$this->drupalPlaceBlock('system_breadcrumb_block');
$web_user = $this->drupalCreateUser([
'bypass node access',
'administer content types',
'administer node fields',
]);
$this->drupalLogin($web_user);
$field = FieldConfig::loadByName('node', 'page', 'body');
$this->assertEquals('Body', $field->getLabel(), 'Body field was found.');
// Verify that title and body fields are displayed.
$this->drupalGet('node/add/page');
$assert->pageTextContains('Title');
$assert->pageTextContains('Body');
// Rename the title field.
$edit = [
'title_label' => 'Foo',
];
$this->drupalGet('admin/structure/types/manage/page');
$this->submitForm($edit, 'Save');
$this->drupalGet('node/add/page');
$assert->pageTextContains('Foo');
$assert->pageTextNotContains('Title');
// Change the name and the description.
$edit = [
'name' => 'Bar',
'description' => 'Lorem ipsum.',
];
$this->drupalGet('admin/structure/types/manage/page');
$this->submitForm($edit, 'Save');
$this->drupalGet('node/add');
$assert->pageTextContains('Bar');
$assert->pageTextContains('Lorem ipsum');
$this->clickLink('Bar');
$assert->pageTextContains('Foo');
$assert->pageTextContains('Body');
// Change the name through the API
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_type = NodeType::load('page');
$node_type->set('name', 'NewBar');
$node_type->save();
/** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
$bundle_info = \Drupal::service('entity_type.bundle.info');
$node_bundles = $bundle_info->getBundleInfo('node');
$this->assertEquals('NewBar', $node_bundles['page']['label'], 'Node type bundle cache is updated');
// Remove the body field.
$this->drupalGet('admin/structure/types/manage/page/fields/node.page.body/delete');
$this->submitForm([], 'Delete');
// Resave the settings for this type.
$this->drupalGet('admin/structure/types/manage/page');
$this->submitForm([], 'Save');
$front_page_path = Url::fromRoute('<front>')->toString();
$this->assertBreadcrumb('admin/structure/types/manage/page/fields', [
$front_page_path => 'Home',
'admin/structure/types' => 'Content types',
'admin/structure/types/manage/page' => 'NewBar',
]);
// Check that the body field doesn't exist.
$this->drupalGet('node/add/page');
$assert->pageTextNotContains('Body');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.