function BlockContentTypeTest::testBlockContentTypeEditing
Same name in other branches
- 9 core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeEditing()
- 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeEditing()
- 10 core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeEditing()
Tests editing a block type using the UI.
File
-
core/
modules/ block_content/ tests/ src/ Functional/ BlockContentTypeTest.php, line 125
Class
- BlockContentTypeTest
- Ensures that block type functions work correctly.
Namespace
Drupal\Tests\block_content\FunctionalCode
public function testBlockContentTypeEditing() : void {
$this->drupalPlaceBlock('system_breadcrumb_block');
// Now create an initial block-type.
$this->createBlockContentType('basic', TRUE);
$this->drupalLogin($this->adminUser);
// We need two block types to prevent /block/add redirecting.
$this->createBlockContentType('other');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'other');
$this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
// Verify that title and body fields are displayed.
$this->drupalGet('block/add/basic');
$this->assertSession()
->pageTextContains('Block description');
$this->assertNotEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was found.');
// Change the block type name.
$edit = [
'label' => 'Bar',
];
$this->drupalGet('admin/structure/block-content/manage/basic');
$this->assertSession()
->titleEquals('Edit basic block type | Drupal');
$this->submitForm($edit, 'Save');
$front_page_path = Url::fromRoute('<front>')->toString();
$this->assertBreadcrumb('admin/structure/block-content/manage/basic/fields', [
$front_page_path => 'Home',
'admin/structure/block-content' => 'Block types',
'admin/structure/block-content/manage/basic' => 'Edit Bar',
]);
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$this->drupalGet('block/add');
$this->assertSession()
->pageTextContains('Bar');
$this->clickLink('Bar');
// Verify that the original machine name was used in the URL.
$this->assertSession()
->addressEquals(Url::fromRoute('block_content.add_form', [
'block_content_type' => 'basic',
]));
// Remove the body field.
$this->drupalGet('admin/structure/block-content/manage/basic/fields/block_content.basic.body/delete');
$this->submitForm([], 'Delete');
// Resave the settings for this type.
$this->drupalGet('admin/structure/block-content/manage/basic');
$this->submitForm([], 'Save');
// Check that the body field doesn't exist.
$this->drupalGet('block/add/basic');
$this->assertEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was not found.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.