Commit d789fcbf authored by catch's avatar catch

Issue #2064591 by larowlan: Missing test coverage for multiple custom block types.

parent c3ee9656
......@@ -24,7 +24,14 @@ function template_preprocess_custom_block_add_list(&$variables) {
$variables['types'] = array();
foreach ($variables['content'] as $type) {
$variables['types'][$type->id] = array();
$variables['types'][$type->id]['link'] = l($type->label(), 'block/add/' . $type->id());
$query = array();
if (($destination = drupal_get_destination()) && $destination['destination'] !== current_path()) {
// A destination parameter is set other than the current path so we
// respect that by adding it to the generated links. If the current path
// is returned, we ignore it as we don't want to end up back at block/add.
$query = $destination;
}
$variables['types'][$type->id]['link'] = l($type->label(), 'block/add/' . $type->id(), array('query' => $query));
$variables['types'][$type->id]['description'] = filter_xss_admin($type->description);
}
}
......
......@@ -137,4 +137,58 @@ public function testCustomBlockTypeDeletion() {
$this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.');
}
/**
* Tests that redirects work as expected when multiple block types exist.
*/
public function testsCustomBlockAddTypes() {
$this->drupalLogin($this->adminUser);
// Create two block types programmatically.
$type = $this->createCustomBlockType('foo');
$type = $this->createCustomBlockType('bar');
// Get the default theme.
$theme = $this->container->get('config.factory')->get('system.theme')->get('default');
// Get the custom block storage controller.
$storage_controller = $this->container
->get('plugin.manager.entity')
->getStorageController('custom_block');
// Test that adding a block from the 'place blocks' form sends you to the
// block configure form.
$this->drupalGet('admin/structure/block/list/' . $theme . '/add');
$this->clickLink(t('Add custom block'));
$this->clickLink('foo');
$edit = array('info' => $this->randomName(8));
$this->drupalPost(NULL, $edit, t('Save'));
$blocks = $storage_controller->loadByProperties(array('info' => $edit['info']));
if (!empty($blocks)) {
$block = reset($blocks);
$destination = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . $theme;
$this->assertUrl(url($destination, array('absolute' => TRUE)));
}
else {
$this->fail('Could not load created block.');
}
// Test that adding a block from the 'custom blocks list' doesn't send you
// to the block configure form.
$this->drupalGet('admin/structure/custom-blocks');
$this->clickLink(t('Add custom block'));
$this->clickLink('foo');
$edit = array('info' => $this->randomName(8));
$this->drupalPost(NULL, $edit, t('Save'));
$blocks = $storage_controller->loadByProperties(array('info' => $edit['info']));
if (!empty($blocks)) {
$block = reset($blocks);
$destination = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . $theme;
$this->assertUrl(url('admin/structure/custom-blocks', array(
'absolute' => TRUE
)));
}
else {
$this->fail('Could not load created block.');
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment