You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nextcloud/lib/composer/mexitek/phpcolors/tests/colorConvertRgbToHex.phpt

73 lines
1.3 KiB
PHP

<?php
require __DIR__ . '/bootstrap.php';
use Mexitek\PHPColors\Color;
use Tester\Assert;
// Colors in RGB, for testing.
$blue = [
'R' => 0,
'G' => 158,
'B' => 204,
];
$yellow = [
'R' => 244,
'G' => 231,
'B' => 15,
];
$black = [
'R' => 0,
'G' => 0,
'B' => 0,
];
$white = [
'R' => 255,
'G' => 255,
'B' => 255,
];
// Test cases.
$colorsToConvert = array(
'blue' => [ // rgb(0, 158, 204)
'hex' => '009ecc',
'rgb' => $blue,
],
'yellow' => [ // rgb(244, 231, 15)
'hex' => 'f4e70f',
'rgb' => $yellow,
],
'black' => [
'hex' => '000000',
'rgb' => $black,
],
'white' => [
'hex' => 'ffffff',
'rgb' => $white,
],
);
foreach ($colorsToConvert as $color) {
$rgb = $color['rgb'];
$hex = $color['hex'];
$answer = Color::rgbToHex($rgb);
Assert::same(
$hex,
$answer,
'Incorrect hex result: "' . Color::rgbToString($rgb) .
'" should convert to "' . $hex .
'", but output was: "' . $answer . '".'
);
$revertAnswer = Color::hexToRgb($hex);
Assert::same(
$rgb,
$revertAnswer,
'Incorrect rgb result: "' . $hex .
'" should convert to "' . Color::rgbToString($rgb) .
'", but output was: "' . Color::rgbToString($revertAnswer) . '".'
);
}