From 49f42e3c553798d7d345caea0feec668f71f7d62 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 14 Dec 2016 23:43:33 -0500 Subject: [PATCH] CRM-19769 - Add color contrast utility function --- CRM/Utils/Color.php | 56 +++++++++++++++++++++++++++ tests/phpunit/CRM/Utils/ColorTest.php | 29 ++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 CRM/Utils/Color.php create mode 100644 tests/phpunit/CRM/Utils/ColorTest.php diff --git a/CRM/Utils/Color.php b/CRM/Utils/Color.php new file mode 100644 index 0000000000..6349f8b7a5 --- /dev/null +++ b/CRM/Utils/Color.php @@ -0,0 +1,56 @@ += 128) ? 'black' : 'white'; + } + +} diff --git a/tests/phpunit/CRM/Utils/ColorTest.php b/tests/phpunit/CRM/Utils/ColorTest.php new file mode 100644 index 0000000000..77b894f2a9 --- /dev/null +++ b/tests/phpunit/CRM/Utils/ColorTest.php @@ -0,0 +1,29 @@ +assertEquals($text, CRM_Utils_Color::getContrast($background)); + } + + public function contrastExamples() { + return array( + array('ef4444', 'white'), + array('FAA31B', 'black'), + array('FFF000', 'black'), + array(' 82c341', 'black'), + array('#009F75', 'white'), + array('#88C6eD', 'black'), + array('# 394ba0', 'white'), + array(' #D54799', 'white'), + ); + } + +} -- 2.25.1