From: Tim Otten Date: Thu, 21 Jun 2018 23:19:37 +0000 (-0700) Subject: CRM_Core_BAO_CacheTest - Unit test for CRM_Core_BAO_Cache::cleanKey X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=51cd6dbdbf4228f5cf940cebc05948bf57a23594;p=civicrm-core.git CRM_Core_BAO_CacheTest - Unit test for CRM_Core_BAO_Cache::cleanKey --- diff --git a/tests/phpunit/CRM/Core/BAO/CacheTest.php b/tests/phpunit/CRM/Core/BAO/CacheTest.php index ac181236cb..900b96dc17 100644 --- a/tests/phpunit/CRM/Core/BAO/CacheTest.php +++ b/tests/phpunit/CRM/Core/BAO/CacheTest.php @@ -82,4 +82,24 @@ class CRM_Core_BAO_CacheTest extends CiviUnitTestCase { $this->assertEquals($originalValue, $return_2); } + public function getCleanKeyExamples() { + $es = []; + $es[] = ['hello_world and other.planets', 'hello_world and other.planets']; // allowed chars + $es[] = ['hello/world+-#@{}', 'hello-2fworld-2b-2d-23-40-7b-7d']; // escaped chars + $es[] = ['123456789 123456789 123456789 123456789 123456789 123456789 123', '123456789 123456789 123456789 123456789 123456789 123456789 123']; // long but allowed + $es[] = ['123456789 123456789 123456789 123456789 123456789 123456789 1234', '-2a008e182a4dcd1a78f405f30119e5f2']; // too long, md5 fallback + $es[] = ['123456789 /23456789 +23456789 -23456789 123456789 123456789', '-1b6baab5961431ed443ab321f5dfa0fb']; // too long, md5 fallback + return $es; + } + + /** + * @param $inputKey + * @param $expectKey + * @dataProvider getCleanKeyExamples + */ + public function testCleanKeys($inputKey, $expectKey) { + $actualKey = CRM_Core_BAO_Cache::cleanKey($inputKey); + $this->assertEquals($expectKey, $actualKey); + } + }