1 color.test ColorTest::testRgbToHex()

Tests Color::rgbToHex().

File

core/modules/simpletest/tests/color.test, line 61
Tests color conversion functions.

Class

ColorTest
@file

Code

function testRgbToHex() {
  $tests = array(
    '#000000' => array('red' => 0, 'green' => 0, 'blue' => 0),
    '#ffffff' => array('red' => 255, 'green' => 255, 'blue' => 255),
    '#777777' => array('red' => 119, 'green' => 119, 'blue' => 119),
    '#010203' => array('red' => 1, 'green' => 2, 'blue' => 3),
  );
  // Input using named RGB array (e.g., as returned by Color::hexToRgb()).
  foreach ($tests as $expected => $rgb) {
    $this->assertIdentical(Color::rgbToHex($rgb), $expected);
  }
  // Input using indexed RGB array (e.g.: array(10, 10, 10)).
  foreach ($tests as $expected => $rgb) {
    $rgb = array_values($rgb);
    $this->assertIdentical(Color::rgbToHex($rgb), $expected);
  }
  // Input using CSS RGB string notation (e.g.: 10, 10, 10).
  foreach ($tests as $expected => $rgb) {
    $rgb = implode(', ', $rgb);
    $this->assertIdentical(Color::rgbToHex($rgb), $expected);
  }
}