Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06a1bc01 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
37 | require_once 'CiviTest/Custom.php'; | |
4cbe18b8 EM |
38 | |
39 | /** | |
40 | * Class CRM_Core_BAO_CustomValueTest | |
41 | */ | |
6a488035 | 42 | class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { |
00be9182 | 43 | public function testTypeCheckWithValidInput() { |
6a488035 TO |
44 | |
45 | $values = array(); | |
46 | $values = array( | |
47 | 'Memo' => 'Test1', | |
48 | 'String' => 'Test', | |
49 | 'Int' => 1, | |
50 | 'Float' => 10.00, | |
51 | 'Date' => '2008-06-24', | |
6c6e6187 | 52 | 'Boolean' => TRUE, |
6a488035 TO |
53 | 'StateProvince' => 'California', |
54 | 'Country' => 'US', | |
55 | 'Link' => 'http://civicrm.org', | |
56 | ); | |
57 | foreach ($values as $type => $value) { | |
58 | $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); | |
59 | if ($type == 'Date') { | |
60 | $this->assertEquals($valid, '2008-06-24', 'Checking type ' . $type . ' for returned CustomField Type.'); | |
61 | } | |
62 | else { | |
6c6e6187 | 63 | $this->assertEquals($valid, TRUE, 'Checking type ' . $type . ' for returned CustomField Type.'); |
6a488035 TO |
64 | } |
65 | } | |
66 | } | |
67 | ||
00be9182 | 68 | public function testTypeCheckWithInvalidInput() { |
6a488035 TO |
69 | $values = array(); |
70 | $values = array('check1' => 'chk'); | |
71 | foreach ($values as $type => $value) { | |
72 | $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); | |
73 | $this->assertEquals($valid, NULL, 'Checking invalid type for returned CustomField Type.'); | |
74 | } | |
75 | } | |
76 | ||
00be9182 | 77 | public function testTypeCheckWithWrongInput() { |
6a488035 TO |
78 | $values = array(); |
79 | $values = array( | |
80 | 'String' => 1, | |
81 | 'Boolean' => 'US', | |
82 | ); | |
83 | foreach ($values as $type => $value) { | |
84 | $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); | |
85 | $this->assertEquals($valid, NULL, 'Checking type ' . $type . ' for returned CustomField Type.'); | |
86 | } | |
87 | } | |
88 | ||
00be9182 | 89 | public function testTypeToFieldWithValidInput() { |
6a488035 TO |
90 | $values = array(); |
91 | $values = array( | |
92 | 'String' => 'char_data', | |
93 | 'File' => 'char_data', | |
94 | 'Boolean' => 'int_data', | |
95 | 'Int' => 'int_data', | |
96 | 'StateProvince' => 'int_data', | |
97 | 'Country' => 'int_data', | |
98 | 'Float' => 'float_data', | |
99 | 'Memo' => 'memo_data', | |
100 | 'Money' => 'decimal_data', | |
101 | 'Date' => 'date_data', | |
102 | 'Link' => 'char_data', | |
103 | ); | |
104 | ||
105 | foreach ($values as $type => $value) { | |
106 | $valid = CRM_Core_BAO_CustomValue::typeToField($type); | |
107 | $this->assertEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.'); | |
108 | } | |
109 | } | |
110 | ||
00be9182 | 111 | public function testTypeToFieldWithWrongInput() { |
6a488035 TO |
112 | $values = array(); |
113 | $values = array( | |
114 | 'String' => 'memo_data', | |
115 | 'File' => 'date_data', | |
116 | 'Boolean' => 'char_data', | |
117 | ); | |
118 | foreach ($values as $type => $value) { | |
119 | $valid = CRM_Core_BAO_CustomValue::typeToField($type); | |
120 | $this->assertNotEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.'); | |
121 | } | |
122 | } | |
123 | ||
00be9182 | 124 | public function testFixFieldValueOfTypeMemo() { |
6a488035 TO |
125 | $customGroup = Custom::createGroup(array(), 'Individual'); |
126 | ||
127 | $fields = array( | |
128 | 'groupId' => $customGroup->id, | |
129 | 'dataType' => 'Memo', | |
130 | 'htmlType' => 'TextArea', | |
131 | ); | |
132 | ||
133 | $customField = Custom::createField(array(), $fields); | |
134 | ||
135 | $custom = 'custom_' . $customField->id; | |
136 | $params = array(); | |
137 | $params = array( | |
138 | 'email' => 'abc@webaccess.co.in', | |
139 | $custom => 'note', | |
140 | ); | |
141 | ||
142 | CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($params); | |
143 | $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.'); | |
144 | ||
145 | Custom::deleteField($customField); | |
146 | Custom::deleteGroup($customGroup); | |
147 | } | |
148 | ||
00be9182 | 149 | public function testFixFieldValueOfTypeMemoWithEmptyParams() { |
6a488035 TO |
150 | $params = array(); |
151 | $result = CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($params); | |
152 | $this->assertEquals($result, NULL, 'Checking the returned value of type Memo.'); | |
153 | } | |
154 | } |