diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php b/core/tests/Drupal/Tests/Core/Utility/ColorTest.php similarity index 75% rename from core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php rename to core/tests/Drupal/Tests/Core/Utility/ColorTest.php index 2c32b31..c3e9fd2 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/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,12 +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.'); @@ -48,7 +47,7 @@ function testHexToRgb() { $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.'); + $this->assertTrue(TRUE, 'Color::hexToRgb(' . var_export($test, TRUE) . ') threw an exception.'); } } @@ -66,9 +65,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 +105,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..a0c6b7f 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -11,3 +11,20 @@ } // Look into removing this later. define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']); + +if (!function_exists('drupal_strlen')) { + define('UNICODE_MULTIBYTE', 1); + + function drupal_strlen($text) { + global $multibyte; + if ($multibyte == UNICODE_MULTIBYTE) { + return mb_strlen($text); + } + else { + // Do not count UTF-8 continuation bytes. + return strlen(preg_replace("/[\x80-\xBF]/", '', $text)); + } + } + +} +