1 block.test | BlockTestCase::testCustomBlockFormat() |
Test creating custom block using Raw HTML (full_html).
File
- core/
modules/ block/ tests/ block.test, line 98 - Tests for block.module.
Class
Code
function testCustomBlockFormat() {
// Add a new custom block by filling out the input form on the admin/structure/block/add page.
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['delta'] = strtolower($this->randomName(8));
$custom_block['title'] = $this->randomName(8);
$custom_block['body[value]'] = '<h1>Raw HTML</h1>';
$full_html_format = filter_format_load('full_html');
$custom_block['body[format]'] = $full_html_format->format;
$this->backdropPost('admin/structure/block/add', $custom_block, 'Save block');
// Set the created custom block to a specific region.
$layout = layout_load('default');
$layout->addBlock('block', $custom_block['delta'], 'content');
$layout->save();
// Confirm that the custom block is being displayed using configured text format.
$this->backdropGet('user');
$this->assertRaw('<h1>Raw HTML</h1>', 'Custom block successfully being displayed using Raw HTML.');
// Confirm that a user without access to Raw HTML (full_html) can not see
// the body field, but can still submit the form without errors.
$block_admin = $this->backdropCreateUser(array('administer blocks'));
$this->backdropLogin($block_admin);
$this->backdropGet('admin/structure/block/manage/' . $custom_block['delta'] . '/configure');
$this->assertFieldByXPath("//textarea[@name='body[value]' and @disabled='disabled']", 'This field has been disabled because you do not have sufficient permissions to edit it.', 'Body field contains denied message');
$this->backdropPost('admin/structure/block/manage/' . $custom_block['delta'] . '/configure', array(), 'Save block');
$this->assertNoText(t('Ensure that each block description is unique.'));
// Confirm that the custom block is still being displayed using configured text format.
$this->backdropGet('user');
$this->assertRaw('<h1>Raw HTML</h1>', 'Custom block successfully being displayed using Raw HTML.');
}