Index: modules/color/color.info
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.info,v
retrieving revision 1.9
diff -u -p -r1.9 color.info
--- modules/color/color.info	11 Oct 2008 02:32:40 -0000	1.9
+++ modules/color/color.info	20 Aug 2009 20:29:16 -0000
@@ -7,3 +7,4 @@ version = VERSION
 core = 7.x
 files[] = color.module
 files[] = color.install
+files[] = color.test
Index: modules/color/color.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.module,v
retrieving revision 1.66
diff -u -p -r1.66 color.module
--- modules/color/color.module	20 Aug 2009 10:48:02 -0000	1.66
+++ modules/color/color.module	20 Aug 2009 20:29:16 -0000
@@ -31,7 +31,7 @@ function color_theme() {
  * Implement hook_form_FORM_ID_alter().
  */
 function color_form_system_theme_settings_alter(&$form, &$form_state) {
-  if (color_get_info(arg(4)) && function_exists('gd_info')) {
+  if (color_get_info(arg(3)) && function_exists('gd_info')) {
     $form['color'] = array(
       '#type' => 'fieldset',
       '#title' => t('Color scheme'),
@@ -39,7 +39,7 @@ function color_form_system_theme_setting
       '#attributes' => array('id' => 'color_scheme_form'),
       '#theme' => 'color_scheme_form',
     );
-    $form['color'] += color_scheme_form($form_state, arg(4));
+    $form['color'] += color_scheme_form($form_state, arg(3));
     $form['#submit'][] = 'color_scheme_form_submit';
   }
 }
@@ -71,44 +71,26 @@ function _color_theme_select_form_alter(
  */
 function _color_page_alter(&$vars) {
   global $language, $theme_key;
+  $themes = list_themes();
 
   // Override stylesheets.
   $color_paths = variable_get('color_' . $theme_key . '_stylesheets', array());
   if (!empty($color_paths)) {
-    // Loop over theme CSS files and try to rebuild CSS array with rewritten
-    // stylesheets. Keep the original order intact for CSS cascading.
-    $new_theme_css = array();
-
-    foreach ($vars['css']['all']['theme'] as $old_path => $old_preprocess) {
-      // Add the non-colored stylesheet first as we might not find a
-      // re-colored stylesheet for replacement later.
-      $new_theme_css[$old_path] = $old_preprocess;
 
+    foreach ($themes[$theme_key]->stylesheets['all'] as $base_filename => $old_path) {
       // Loop over the path array with recolored CSS files to find matching
       // paths which could replace the non-recolored paths.
       foreach ($color_paths as $color_path) {
         // Color module currently requires unique file names to be used,
         // which allows us to compare different file paths.
         if (basename($old_path) == basename($color_path)) {
-          // Pull out the non-colored and add rewritten stylesheet.
-          unset($new_theme_css[$old_path]);
-          $new_theme_css[$color_path] = $old_preprocess;
-
-          // If the current language is RTL and the CSS file had an RTL variant,
-          // pull out the non-colored and add rewritten RTL stylesheet.
-          if ($language->direction == LANGUAGE_RTL) {
-            $rtl_old_path = str_replace('.css', '-rtl.css', $old_path);
-            $rtl_color_path = str_replace('.css', '-rtl.css', $color_path);
-            if (file_exists($rtl_color_path)) {
-              unset($new_theme_css[$rtl_old_path]);
-              $new_theme_css[$rtl_color_path] = $old_preprocess;
-            }
-          }
-          break;
+          // Replace the path to the new css file.  
+          // This keeps the order of the stylesheets intact.
+          $vars['css'][$old_path]['data'] = $color_path;
         }
       }
     }
-    $vars['css']['all']['theme'] = $new_theme_css;
+
     $vars['styles'] = drupal_get_css($vars['css']);
   }
 
@@ -196,7 +178,7 @@ function color_scheme_form(&$form_state,
       '#size' => 8,
     );
   }
-  $form['theme'] = array('#type' => 'value', '#value' => arg(4));
+  $form['theme'] = array('#type' => 'value', '#value' => arg(3));
   $form['info'] = array('#type' => 'value', '#value' => $info);
 
   return $form;
@@ -290,7 +272,7 @@ function color_scheme_form_submit($form,
 
   // Prepare target locations for generated files.
   $id = $theme . '-' . substr(md5(serialize($palette) . microtime()), 0, 8);
-  $paths['color'] = file_directory_path() . '/color';
+  $paths['color'] = 'public://color';
   $paths['target'] = $paths['color'] . '/' . $id;
   foreach ($paths as $path) {
     file_prepare_directory($path, FILE_CREATE_DIRECTORY);
@@ -478,7 +460,7 @@ function _color_render_images($theme, &$
   foreach ($info['slices'] as $file => $coord) {
     list($x, $y, $width, $height) = $coord;
     $base = basename($file);
-    $image = $paths['target'] . $base;
+    $image = drupal_realpath($paths['target'] . $base);
 
     // Cut out slice.
     if ($file == 'screenshot.png') {
Index: modules/color/color.test
===================================================================
RCS file: modules/color/color.test
diff -N modules/color/color.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/color/color.test	20 Aug 2009 20:29:16 -0000
@@ -0,0 +1,42 @@
+<?php
+// $Id$
+
+class ColorTestCase extends DrupalWebTestCase {
+  protected $big_user;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Color functionality',
+      'description' => 'Modify the garland theme color and make sure the changes are reflected on the frontend',
+      'group' => 'Color',
+    );
+  }
+
+  /**
+   * Enable modules and create users with specific permissions.
+   */
+  function setUp() {
+    parent::setUp('color');
+    // Create users.
+    $this->big_user = $this->drupalCreateUser(array('administer site configuration'));
+  }
+
+  function testColor() {
+    $this->drupalLogin($this->big_user);
+    $this->drupalGet('admin/appearance/settings/garland');
+    $this->assertResponse(200);
+    $edit['scheme'] = '';
+    $edit['palette[link]'] = '#123456';
+    $this->drupalPost('admin/appearance/settings/garland', $edit, t('Save configuration'));
+
+    global $theme_key;
+    $this->drupalGet('<front>');
+    $stylesheets = variable_get('color_' . $theme_key . '_stylesheets', array());
+    $this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content.');
+
+    $stylesheet_content = join("\n", file($stylesheets[0]));
+    $matched = preg_match('/(.*color: #123456.*)/i', $stylesheet_content, $matches);
+    $this->assertTrue($matched == 1, 'Make sure the color we changed is in the color stylesheet.');
+  }
+
+}
Index: themes/garland/template.php
===================================================================
RCS file: /cvs/drupal/drupal/themes/garland/template.php,v
retrieving revision 1.24
diff -u -p -r1.24 template.php
--- themes/garland/template.php	17 Aug 2009 19:14:42 -0000	1.24
+++ themes/garland/template.php	20 Aug 2009 20:29:16 -0000
@@ -37,6 +37,12 @@ function garland_preprocess_page(&$vars)
   }
   $vars['site_html'] = implode(' ', $site_fields);
 
+}
+
+/**
+ * Override process function used to alter variables as late as possible.
+ */
+function garland_process_page(&$vars) {
   // Hook into color.module
   if (module_exists('color')) {
     _color_page_alter($vars);
