<?php
// $Id: color.test,v 1.4 2010/04/11 18:33:43 dries Exp $

/**
 * @file
 * Tests for color module.
 */

/**
 * Test color functionality.
 */
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',
    );
  }

  function setUp() {
    parent::setUp('color');
    // Create users.
    $this->big_user = $this->drupalCreateUser(array('administer themes'));
  }

  /**
   * Test color module functionality.
   */
  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'));

    $this->drupalGet('<front>');
    $stylesheets = variable_get('color_garland_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.');

    $this->drupalGet('admin/appearance/settings/garland');
    $this->assertResponse(200);
    $edit['scheme'] = 'greenbeam';
    $this->drupalPost('admin/appearance/settings/garland', $edit, t('Save configuration'));

    $this->drupalGet('<front>');
    $stylesheets = variable_get('color_garland_stylesheets', array());
    $stylesheet_content = join("\n", file($stylesheets[0]));
    $matched = preg_match('/(.*color: #0c7a00.*)/i', $stylesheet_content, $matches);
    $this->assertTrue($matched == 1, 'Make sure the color we changed is in the color stylesheet.');

  }

}
