diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php b/core/tests/Drupal/Tests/Core/Utility/Color/ColorTest.php similarity index 82% rename from core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php rename to core/tests/Drupal/Tests/Core/Utility/Color/ColorTest.php index 2c32b31..d62d69b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/Color/ColorTest.php @@ -2,18 +2,23 @@ /** * @file - * Definition of Drupal\system\Tests\Common\ColorTest. + * Definition of Drupal\Core\Utility\Color\ColorTest. */ -namespace Drupal\system\Tests\Common; +namespace Drupal\Tests\Core\Utility\Color\ColorTest; use Drupal\Core\Utility\Color; -use Drupal\simpletest\UnitTestBase; +use Drupal\Tests\UnitTestCase; /** * Tests color conversion functions. + * + * @group Core_Utility + * @group Color + * + * @expectedException InvalidArgumentException */ -class ColorTest extends UnitTestBase { +class ColorTest extends UnitTestCase { public static function getInfo() { return array( @@ -34,23 +39,6 @@ function testHexToRgb() { foreach ($values as $value) { $values[] = '#' . $value; } - // Add invalid data types (hex value must be a string). - $values = array_merge($values, array( - 1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789, - -1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, - 0x0, 0x010, - )); - - foreach ($values as $test) { - $this->assertFalse(Color::validateHex($test), var_export($test, TRUE) . ' is invalid.'); - try { - Color::hexToRgb($test); - $this->fail('Color::hexToRgb(' . var_export($test, TRUE) . ') did not throw an exception.'); - } - catch (\InvalidArgumentException $e) { - $this->pass('Color::hexToRgb(' . var_export($test, TRUE) . ') threw an exception.'); - } - } // PHP automatically casts a numeric array key into an integer. // Since hex values may consist of 0-9 only, they need to be defined as @@ -66,9 +54,31 @@ function testHexToRgb() { array('hex' => '#ffffff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)), array('hex' => '#010203', 'rgb' => array('red' => 1, 'green' => 2, 'blue' => 3)), ); + foreach ($tests as $test) { $result = Color::hexToRgb($test['hex']); - $this->assertIdentical($result, $test['rgb']); + $this->assertSame($result, $test['rgb']); + } + + // Add invalid data types (hex value must be a string). + $values = array_merge($values, array( + 1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789, + -1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, + 0x0, 0x010, + )); + + foreach ($values as $test) { + $this->assertFalse(Color::validateHex($test), var_export($test, TRUE) . ' is invalid.'); + } + + foreach ($values as $test) { + try { + Color::hexToRgb($test); + } + catch (\InvalidArgumentException $e) { + return; + } + $this->fail('Color::hexToRgb(' . var_export($test, TRUE) . ') did not throw an exception.'); } } @@ -84,17 +94,17 @@ function testRgbToHex() { ); // Input using named RGB array (e.g., as returned by Color::hexToRgb()). foreach ($tests as $expected => $rgb) { - $this->assertIdentical(Color::rgbToHex($rgb), $expected); + $this->assertSame(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); + $this->assertSame(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); + $this->assertSame(Color::rgbToHex($rgb), $expected); } } } diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 6c947df..11ff65d 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -10,4 +10,5 @@ $loader->add('Drupal\\' . $module, __DIR__ . "/../modules/" . $module . "/lib"); } // Look into removing this later. -define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']); +require_once __DIR__ . '/../includes/bootstrap.inc'; +require_once __DIR__ . '/../includes/unicode.inc'; \ No newline at end of file