1 filter.test | FilterHooksTestCase::testFilterHooks() |
Tests hooks on format management.
Tests that hooks run correctly on creating, editing, and deleting a text format.
File
- core/
modules/ filter/ tests/ filter.test, line 2113 - Tests for filter.module.
Class
- FilterHooksTestCase
- Tests for Filter's hook invocations.
Code
function testFilterHooks() {
// Add a text format.
$name = $this->randomName();
$edit = array();
$edit['format'] = backdrop_strtolower($this->randomName());
$edit['name'] = $name;
$edit['roles[anonymous]'] = 1;
$this->backdropPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->assertRaw(t('Added text format %format.', array('%format' => $name)), t('New format created.'));
$this->assertText('hook_filter_format_insert invoked.', t('hook_filter_format_insert was invoked.'));
$format_id = $edit['format'];
// Update text format.
$edit = array();
$edit['roles[authenticated]'] = 1;
$this->backdropPost('admin/config/content/formats/' . $format_id, $edit, t('Save configuration'));
$this->assertRaw(t('Updated text format %format.', array('%format' => $name)), 'Format successfully updated.');
$this->assertText('hook_filter_format_update invoked.', 'hook_filter_format_update() was invoked.');
// Add a new custom block.
$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]'] = $this->randomName(32);
// Use the format created.
$custom_block['body[format]'] = $format_id;
$this->backdropPost('admin/structure/block/add', $custom_block, t('Save block'));
$this->assertText(t('The block has been created.'), 'New block successfully created.');
// Check to see if the custom block was created by checking that it has a configuration file.
$custom_block = config_get('block.custom.' . $custom_block['delta']);
$this->assertNotNull($custom_block['delta'], 'New block found in configuration.');
// Disable the text format.
$this->backdropPost('admin/config/content/formats/' . $format_id . '/disable', array(), t('Disable'));
$this->assertRaw(t('Disabled text format %format.', array('%format' => $name)), 'Format successfully disabled.');
$this->assertText('hook_filter_format_disable invoked.', 'hook_filter_format_disable() was invoked.');
}