3 require_once 'CiviTest/CiviUnitTestCase.php';
6 * Class CRM_Utils_TypeTest
8 class CRM_Utils_TypeTest
extends CiviUnitTestCase
{
10 public function setUp() {
15 * @dataProvider validateDataProvider
18 * @param $expectedResult
20 public function testValidate($inputData, $inputType, $expectedResult) {
21 $this->assertTrue($expectedResult === CRM_Utils_Type
::validate($inputData, $inputType, FALSE));
27 public function validateDataProvider() {
30 array('145E+3', 'Int', NULL),
31 array('10', 'Integer', 10),
32 array(-10, 'Int', -10),
33 array('-10', 'Integer', -10),
34 array('-10foo', 'Int', NULL),
35 array(10, 'Positive', 10),
36 array('145.0E+3', 'Positive', NULL),
37 array('10', 'Positive', 10),
38 array(-10, 'Positive', NULL),
39 array('-10', 'Positive', NULL),
40 array('-10foo', 'Positive', NULL),
45 * @dataProvider escapeDataProvider
48 * @param $expectedResult
50 public function testEscape($inputData, $inputType, $expectedResult) {
51 $this->assertTrue($expectedResult === CRM_Utils_Type
::escape($inputData, $inputType, FALSE));
57 public function escapeDataProvider() {
60 array('145E+3', 'Int', NULL),
61 array('10', 'Integer', 10),
62 array(-10, 'Int', -10),
63 array(array(), 'Integer', NULL),
64 array('-10foo', 'Int', NULL),
65 array(10, 'Positive', 10),
66 array('145.0E+3', 'Positive', NULL),
67 array('10', 'Positive', 10),
68 array(-10, 'Positive', NULL),
69 array('-10', 'Positive', NULL),
70 array('-10foo', 'Positive', NULL),
71 array(array('10', 20), 'Country', array('10', 20)),
72 array(array('10', '-10foo'), 'Country', NULL),
73 array('', 'Timestamp', ''),
74 array('', 'ContactReference', ''),
75 array('3', 'ContactReference', 3),
76 array('-3', 'ContactReference', NULL),
77 // Escape function is meant for sql, not xss
78 array('<p onclick="alert(\'xss\');">Hello</p>', 'Memo', '<p onclick=\\"alert(\\\'xss\\\');\\">Hello</p>'),