View source
<?php
module_load_include('inc', 'site_banner', 'site_banner_options');
module_load_include('module', 'site_banner', 'site_banner');
class SiteBannerColorUnitTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Site banner color unit tests',
'description' => 'Ensure that the site banner colors are active and valid.',
'group' => 'Site Banner',
);
}
public function testBackgroundColorsExist() {
$background_colors = site_banner_get_background_colors();
$result = count($background_colors) > 0;
$message = 'Background colors should exist.';
$this
->assertTrue($result, $message);
}
public function testTextColorsExist() {
$colors = site_banner_get_text_colors();
$result = count($colors) > 0;
$message = 'Text colors should exist.';
$this
->assertTrue($result, $message);
}
public function testBackgroundColorsAreValid() {
$background_colors = site_banner_get_background_colors();
$result = TRUE;
foreach (array_keys($background_colors) as $color_code) {
$regex_result = preg_match(site_banner_get_html_color_regex_pattern(), $color_code);
$result = !($regex_result === FALSE || $regex_result === 0);
}
$message = 'Background colors should be valid HTML colors.';
$this
->assertTrue($result, $message);
}
public function testTextColorsAreValid() {
$text_colors = site_banner_get_text_colors();
$result = TRUE;
foreach (array_keys($text_colors) as $color_code) {
$regex_result = preg_match(site_banner_get_html_color_regex_pattern(), $color_code);
$result = !($regex_result === FALSE || $regex_result === 0);
}
$message = 'Background colors should be valid HTML colors.';
$this
->assertTrue($result, $message);
}
}
class SiteBannerRenderingUnitTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Site banner rendering unit tests',
'description' => 'Ensure that the site banner renders valid results.',
'group' => 'Site Banner',
);
}
public function setUp() {
parent::setUp('site_banner');
variable_set('site_banner_status', TRUE);
variable_set('site_banner_debug_status', FALSE);
variable_set('site_banner_text', 'TEST BANNER TEXT');
variable_set('site_banner_text_color', '#FFFFFF');
variable_set('site_banner_background_color', '#000000');
}
public function testBannerHeaderTagExists() {
$page = array();
$page = site_banner_build_banner($page);
$result = $page['page_top'][0]['#attributes']['id'] == 'siteBannerHeaderBanner';
$message = 'Banner header tag in page array.';
$this
->assertTrue($result, $message);
}
public function testBannerFooterTagExists() {
$page = array();
site_banner_page_build($page);
$result = $page['page_top'][1]['#attributes']['id'] == 'siteBannerFooterBanner';
$message = 'Banner footer tag in page array.';
$this
->assertTrue($result, $message);
}
public function testBannerHeaderTextExists() {
$banner = variable_get('site_banner_text', '');
$page = array();
site_banner_page_build($page);
$result = $page['page_top'][0]['#value'] == $banner;
$message = 'Banner header displays correct text: "' . $banner . '".';
$this
->assertTrue($result, $message);
}
public function testBannerFooterTextExists() {
$banner = variable_get('site_banner_text', '');
$page = array();
site_banner_page_build($page);
$result = $page['page_top'][1]['#value'] == $banner;
$message = 'Banner footer displays correct text: "' . $banner . '".';
$this
->assertTrue($result, $message);
}
public function testBannerColorsRendered() {
$background_color = variable_get('site_banner_background_color', '');
$text_color = variable_get('site_banner_text_color', '');
$page = array();
site_banner_page_build($page);
$css_string = "#siteBannerFooterBanner, #siteBannerHeaderBanner {background-color:{$background_color}; color:{$text_color};}";
$result = FALSE;
foreach (drupal_add_css() as $css_tags) {
$result |= $css_string === $css_tags['data'];
}
$message = 'Banner colors appear in HEAD tag in correct format. Current CSS string: ' . $css_string;
$this
->assertTrue($result, $message);
}
public function testBannerContextTextChange() {
$result = FALSE;
$baseline_banner_text = 'Example Text PrependText01 Text1/Text2 AppendText01';
$banner_text = variable_get('site_banner_text', '');
$existing_banner_text = $banner_text;
$contexts = array(
'context_1' => (object) array(
'name' => 'context_1',
'description' => 'context_1',
'tag' => 'tag1',
'conditions' => array(
'node_taxonomy' => array(
'values' => array(
1 => 1,
),
'options' => array(
'node_form' => '1',
),
),
),
'reactions' => array(
'change_banner_background_color' => '#ffffcc',
'change_banner_text' => array(
'site_banner_text' => 'Example Text',
'site_banner_tag_prepend_text' => '',
'site_banner_tag_delimiter_text' => '',
'site_banner_tag_append_text' => '',
),
'change_banner_text_color' => '#000000',
),
'condition_mode' => '0',
'table' => 'context',
'type' => 'Normal',
'export_type' => 1,
),
'context_2' => (object) array(
'name' => 'context_2',
'description' => 'context_2',
'tag' => 'tag2',
'conditions' => array(
'node_taxonomy' => array(
'values' => array(
12 => 12,
),
'options' => array(
'node_form' => '1',
),
),
),
'reactions' => array(
'change_banner_text' => array(
'site_banner_text' => 'Text1',
'site_banner_tag_prepend_text' => 'PrependText01 ',
'site_banner_tag_delimiter_text' => '/',
'site_banner_tag_append_text' => ' AppendText01',
),
),
'condition_mode' => '0',
'table' => 'context',
'type' => 'Normal',
'export_type' => 1,
),
'context_3' => (object) array(
'name' => 'context_3',
'description' => 'context_3',
'tag' => 'tag2',
'conditions' => array(
'node_taxonomy' => array(
'values' => array(
16 => 16,
),
'options' => array(
'node_form' => '1',
),
),
),
'reactions' => array(
'change_banner_text' => array(
'site_banner_text' => 'Text2',
'site_banner_tag_prepend_text' => 'PrependText01 ',
'site_banner_tag_delimiter_text' => '/',
'site_banner_tag_append_text' => ' AppendText01',
),
),
'condition_mode' => '0',
'table' => 'context',
'type' => 'Normal',
'export_type' => 1,
),
);
site_banner_generate_context_banner_text_from_contexts($contexts, $banner_text);
$result = $banner_text == $baseline_banner_text;
$message = 'Test context can render an altered banner text properly: ';
$message .= "Existing banner text = \"{$existing_banner_text}\", Updated banner text = \"{$banner_text}\"";
$message .= ", Baseline banner text = \"{$baseline_banner_text}\".";
$this
->assertTrue($result, $message);
}
}