Skip to content
Snippets Groups Projects
Commit aa078127 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #1078176 by franz, agentrickard: block module renders blocks that are...

- Patch #1078176 by franz, agentrickard: block module renders blocks that are set to display on no pages.
parent a8d2c8e8
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -761,6 +761,12 @@ function block_block_list_alter(&$blocks) {
else {
$enabled = TRUE;
}
// Limited visibility blocks must list at least one page.
if ($block->visibility == BLOCK_VISIBILITY_LISTED && empty($block->pages)) {
$enabled = FALSE;
}
if (!$enabled) {
unset($blocks[$key]);
continue;
......
......@@ -192,6 +192,49 @@ class BlockTestCase extends DrupalWebTestCase {
$this->assertNoText($title, t('Block was not displayed to anonymous users.'));
}
/**
* Test block visibility when using "pages" restriction but leaving
* "pages" textarea empty
*/
function testBlockVisibilityListedEmpty() {
$block = array();
// Create a random title for the block
$title = $this->randomName(8);
// Create the custom block
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $title;
$custom_block['body[value]'] = $this->randomName(32);
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
$block['module'] = 'block';
$block['delta'] = $bid;
$block['title'] = $title;
// Move block to the first sidebar.
$this->moveBlockToRegion($block, $this->regions[1]);
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
$edit = array();
$edit['visibility'] = BLOCK_VISIBILITY_LISTED;
$this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block'));
$this->drupalGet('');
$this->assertNoText($title, t('Block was not displayed according to block visibility rules.'));
$this->drupalGet('user');
$this->assertNoText($title, t('Block was not displayed according to block visibility rules regardless of path case.'));
// Confirm that the block is not displayed to anonymous users.
$this->drupalLogout();
$this->drupalGet('');
$this->assertNoText($title, t('Block was not displayed to anonymous users.'));
}
/**
* Test user customization of block visibility.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment