From 2c1bb05313377c9df76bd068f52c9ec632ce13bb Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sun, 31 May 2009 07:46:54 +0000 Subject: #473080 by chx: Fix bug where switching themes would result in zero blocks (including content area). with tests. --- modules/block/block.module | 5 ++++- modules/block/block.test | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/block/block.module b/modules/block/block.module index 841761cdf..b12f44113 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -483,7 +483,10 @@ function block_form_system_performance_settings_alter(&$form, &$form_state) { * Implement hook_form_FORM_ID_alter(). */ function block_form_system_themes_form_alter(&$form, &$form_state) { - $form['#submit'][] = 'block_system_themes_form_submit'; + // This function needs to fire before the theme changes are recorded in the + // database, otherwise it will populate the default list of blocks from the + // new theme, which is empty. + array_unshift($form['#submit'], 'block_system_themes_form_submit'); } /** diff --git a/modules/block/block.test b/modules/block/block.test index 9cef03036..9dcd199b6 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -192,6 +192,50 @@ class NonDefaultBlockAdmin extends DrupalWebTestCase { } } +/** + * Test blocks correctly initialized when picking a new default theme. + */ +class NewDefaultThemeBlocks extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => t('New default theme blocks'), + 'description' => t('Checks that the new default theme gets blocks.'), + 'group' => t('Block'), + ); + } + + /** + * Check the enabled Garland blocks are correctly copied over. + */ + function testNewDefaultThemeBlocks() { + // Create administrative user. + $admin_user = $this->drupalCreateUser(array('administer site configuration')); + $this->drupalLogin($admin_user); + + // Ensure no other theme's blocks are in the block table yet. + $count = db_query_range("SELECT 1 FROM {block} WHERE theme != 'garland'", 0, 1)->fetchField(); + $this->assertFalse($count, t('Only Garland has blocks.')); + + // Populate list of all blocks for matching against new theme. + $blocks = array(); + $result = db_query('SELECT * FROM {block}'); + foreach ($result as $block) { + // $block->theme and $block->bid will not match, so remove them. + unset($block->theme, $block->bid); + $blocks[$block->module][$block->delta] = $block; + } + + // Turn on the Stark theme and ensure that it contains all of the blocks + // that Garland did. + $this->drupalPost('admin/build/themes', array('theme_default' => 'stark'), t('Save configuration')); + $result = db_query("SELECT * FROM {block} WHERE theme='stark'"); + foreach ($result as $block) { + unset($block->theme, $block->bid); + $this->assertEqual($blocks[$block->module][$block->delta], $block, t('Block matched')); + } + } +} + /** * Test the block system with admin themes. */ -- cgit v1.2.3