public function BlockContentTypeTest::testBlockContentTypeEditing in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block_content/src/Tests/BlockContentTypeTest.php \Drupal\block_content\Tests\BlockContentTypeTest::testBlockContentTypeEditing()
Tests editing a block type using the UI.
File
- core/
modules/ block_content/ src/ Tests/ BlockContentTypeTest.php, line 98 - Contains \Drupal\block_content\Tests\BlockContentTypeTest.
Class
- BlockContentTypeTest
- Ensures that custom block type functions work correctly.
Namespace
Drupal\block_content\TestsCode
public function testBlockContentTypeEditing() {
// 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::entityManager()
->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
->assertRaw('Block description', 'Block info field was found.');
$this
->assertRaw('Body', 'Body field was found.');
// Change the block type name.
$edit = array(
'label' => 'Bar',
);
$this
->drupalGet('admin/structure/block/block-content/manage/basic');
$this
->assertTitle(format_string('Edit @type custom block type | Drupal', [
'@type' => 'basic',
]));
$this
->drupalPostForm(NULL, $edit, t('Save'));
\Drupal::entityManager()
->clearCachedFieldDefinitions();
$this
->drupalGet('block/add');
$this
->assertRaw('Bar', 'New name was displayed.');
$this
->clickLink('Bar');
$this
->assertUrl(\Drupal::url('block_content.add_form', [
'block_content_type' => 'basic',
], [
'absolute' => TRUE,
]), [], 'Original machine name was used in URL.');
// Remove the body field.
$this
->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', array(), t('Delete'));
// Resave the settings for this type.
$this
->drupalPostForm('admin/structure/block/block-content/manage/basic', array(), t('Save'));
// Check that the body field doesn't exist.
$this
->drupalGet('block/add/basic');
$this
->assertNoRaw('Body', 'Body field was not found.');
}