home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (color.test)

This example Drupal source code file (color.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, color, directory, file, foreach, function, make, php, settings_path, stylesheet_content, stylesheets, sure, the, theme

The color.test Drupal example source code

<?php
// $Id: color.test,v 1.8 2010/11/13 14:06:43 dries Exp $

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

/**
 * Test color functionality.
 */
class ColorTestCase extends DrupalWebTestCase {
  protected $big_user;
  protected $themes;

  public static function getInfo() {
    return array(
      'name' => 'Color functionality',
      'description' => 'Modify the Bartik and Garland theme colors 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'));

    // This tests the color module in both Bartik and Garland.
    $this->themes = array(
      'bartik' => array(
        'palette_input' => 'palette[bg]',
        'scheme' => 'slate',
        'scheme_color' => '#3b3b3b',
      ),
      'garland' => array(
        'palette_input' => 'palette[link]',
        'scheme' => 'greenbeam',
        'scheme_color' => '#0c7a00',
      ),
    );
    theme_enable(array_keys($this->themes));
  }

  /**
   * Test color module functionality.
   */
  function testColor() {
    foreach ($this->themes as $theme => $test_values) {
      $this->_testColor($theme, $test_values);
    }
  }

  /**
   * Tests color module functionality using the given theme.
   */
  function _testColor($theme, $test_values) {
    variable_set('theme_default', $theme);
    $settings_path = 'admin/appearance/settings/' . $theme;

    $this->drupalLogin($this->big_user);
    $this->drupalGet($settings_path);
    $this->assertResponse(200);
    $edit['scheme'] = '';
    $edit[$test_values['palette_input']] = '#123456';
    $this->drupalPost($settings_path, $edit, t('Save configuration'));

    $this->drupalGet('<front>');
    $stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
    $this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');

    $stylesheet_content = join("\n", file($stylesheets[0]));
    $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');

    $this->drupalGet($settings_path);
    $this->assertResponse(200);
    $edit['scheme'] = $test_values['scheme'];
    $this->drupalPost($settings_path, $edit, t('Save configuration'));

    $this->drupalGet('<front>');
    $stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
    $stylesheet_content = join("\n", file($stylesheets[0]));
    $this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');

    // Test with aggregated CSS turned on.
    variable_set('preprocess_css', 1);
    $this->drupalGet('<front>');
    $stylesheets = variable_get('drupal_css_cache_files', array());
    $stylesheet_content = '';
    foreach ($stylesheets as $key => $uri) {
      $stylesheet_content .= join("\n", file(drupal_realpath($uri)));
    }
    $this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
    variable_set('preprocess_css', 0);
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal color.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.