=== modified file 'modules/block/block.module'
--- modules/block/block.module	2009-05-31 06:31:00 +0000
+++ modules/block/block.module	2009-05-31 07:22:05 +0000
@@ -483,7 +483,10 @@ function block_form_system_performance_s
  * 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 the default set for the theme will be the derived
+  // from the new admin or default theme instead of the old which is empty.
+  array_unshift($form['#submit'], 'block_system_themes_form_submit');
 }
 
 /**

=== modified file 'modules/block/block.test'
--- modules/block/block.test	2009-05-31 06:31:00 +0000
+++ modules/block/block.test	2009-05-31 07:30:29 +0000
@@ -193,6 +193,41 @@ class NonDefaultBlockAdmin extends Drupa
 }
 
 /**
+ * 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() {
+    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
+    $this->drupalLogin($admin_user);
+    $count = db_query_range("SELECT 1 FROM {block} WHERE theme != 'garland'", 0, 1)->fetchField();
+    $this->assertFalse($count, t('Only Garland has blocks.'));
+    $blocks = array();
+    $result = db_query('SELECT * FROM {block}');
+    foreach ($result as $block) {
+      unset($block->theme, $block->bid);
+      $blocks[$block->module][$block->delta] = $block;
+    }
+    $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.
  */
 class BlockAdminThemeTestCase extends DrupalWebTestCase {

