summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2012-04-28 01:08:33 (GMT)
committercatch2012-04-28 01:08:33 (GMT)
commit3d4d9505551ec9f321dd6fcc2795633b56575616 (patch)
treec89e9f8198b913e314d1fb31c70240573e9c4faf
parent9f59cdf9375f2cf5a096da52ac3e3b440251b491 (diff)
Issue #1172560 by bas.hr, bellesmanieres, NROTC_Webmaster: Fixed The block X was assigned to the invalid region Y and has been disabled.
-rw-r--r--core/modules/block/block.module4
-rw-r--r--core/modules/block/block.test66
2 files changed, 68 insertions, 2 deletions
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index 069e879..488904c 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -468,10 +468,10 @@ function _block_rehash($theme = NULL) {
if (!isset($block['weight'])) {
$block['weight'] = 0;
}
- if (!empty($block['region']) && $block['region'] != BLOCK_REGION_NONE && !isset($regions[$block['region']])) {
+ if (!empty($block['region']) && $block['region'] != BLOCK_REGION_NONE && !isset($regions[$block['region']]) && $block['status'] == 1) {
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block['info'], '%region' => $block['region'])), 'warning');
// Disabled modules are moved into the BLOCK_REGION_NONE later so no
- // need to move the bock to another region.
+ // need to move the block to another region.
$block['status'] = 0;
}
// Set region to none if not enabled and make sure status is set.
diff --git a/core/modules/block/block.test b/core/modules/block/block.test
index f4a9549..a5bde42 100644
--- a/core/modules/block/block.test
+++ b/core/modules/block/block.test
@@ -1030,3 +1030,69 @@ class BlockLanguageTestCase extends DrupalWebTestCase {
$this->assertTrue($count == 0, t('The block language visibility do not have an entry in the database.'));
}
}
+
+/**
+ * Tests that a block assigned to an invalid region triggers the warning.
+ */
+class BlockInvalidRegionTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Blocks in invalid regions',
+ 'description' => 'Checks that an active block assigned to a non-existing region triggers the warning message and is disabled.',
+ 'group' => 'Block',
+ );
+ }
+
+ function setUp() {
+ parent::setUp(array('block', 'block_test'));
+ // Create an admin user.
+ $admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages'));
+ $this->drupalLogin($admin_user);
+ }
+
+ /**
+ * Tests that blocks assigned to invalid regions work correctly.
+ */
+ function testBlockInInvalidRegion() {
+ // Enable a test block in the default theme and place it in an invalid region.
+ db_merge('block')
+ ->key(array(
+ 'module' => 'block_test',
+ 'delta' => 'test_html_id',
+ 'theme' => variable_get('theme_default', 'stark'),
+ ))
+ ->fields(array(
+ 'status' => 1,
+ 'region' => 'invalid_region',
+ 'cache' => DRUPAL_NO_CACHE,
+ ))
+ ->execute();
+
+ $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => t('Test block html id'), '%region' => 'invalid_region'));
+
+ // Clearing the cache should disable the test block placed in the invalid region.
+ $this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
+ $this->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.');
+
+ // Clear the cache to check if the warning message is not triggered.
+ $this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
+ $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
+
+ // Place disabled test block in the invalid region of the default theme.
+ db_merge('block')
+ ->key(array(
+ 'module' => 'block_test',
+ 'delta' => 'test_html_id',
+ 'theme' => variable_get('theme_default', 'stark'),
+ ))
+ ->fields(array(
+ 'region' => 'invalid_region',
+ 'cache' => DRUPAL_NO_CACHE,
+ ))
+ ->execute();
+
+ // Clear the cache to check if the warning message is not triggered.
+ $this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
+ $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
+ }
+}