Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
4cbe18b8 EM |
34 | /** |
35 | * Class CRM_Core_BAO_CustomValueTest | |
36 | */ | |
6a488035 | 37 | class CRM_Core_BAO_CustomValueTest extends CiviUnitTestCase { |
00be9182 | 38 | public function testTypeCheckWithValidInput() { |
6a488035 | 39 | |
6a488035 TO |
40 | $values = array( |
41 | 'Memo' => 'Test1', | |
42 | 'String' => 'Test', | |
43 | 'Int' => 1, | |
44 | 'Float' => 10.00, | |
45 | 'Date' => '2008-06-24', | |
6c6e6187 | 46 | 'Boolean' => TRUE, |
6a488035 TO |
47 | 'StateProvince' => 'California', |
48 | 'Country' => 'US', | |
49 | 'Link' => 'http://civicrm.org', | |
50 | ); | |
51 | foreach ($values as $type => $value) { | |
52 | $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); | |
53 | if ($type == 'Date') { | |
54 | $this->assertEquals($valid, '2008-06-24', 'Checking type ' . $type . ' for returned CustomField Type.'); | |
55 | } | |
56 | else { | |
6c6e6187 | 57 | $this->assertEquals($valid, TRUE, 'Checking type ' . $type . ' for returned CustomField Type.'); |
6a488035 TO |
58 | } |
59 | } | |
60 | } | |
61 | ||
00be9182 | 62 | public function testTypeCheckWithInvalidInput() { |
6a488035 TO |
63 | $values = array('check1' => 'chk'); |
64 | foreach ($values as $type => $value) { | |
65 | $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); | |
66 | $this->assertEquals($valid, NULL, 'Checking invalid type for returned CustomField Type.'); | |
67 | } | |
68 | } | |
69 | ||
00be9182 | 70 | public function testTypeCheckWithWrongInput() { |
6a488035 TO |
71 | $values = array( |
72 | 'String' => 1, | |
73 | 'Boolean' => 'US', | |
74 | ); | |
75 | foreach ($values as $type => $value) { | |
76 | $valid = CRM_Core_BAO_CustomValue::typecheck($type, $value); | |
77 | $this->assertEquals($valid, NULL, 'Checking type ' . $type . ' for returned CustomField Type.'); | |
78 | } | |
79 | } | |
80 | ||
00be9182 | 81 | public function testTypeToFieldWithValidInput() { |
6a488035 TO |
82 | $values = array( |
83 | 'String' => 'char_data', | |
84 | 'File' => 'char_data', | |
85 | 'Boolean' => 'int_data', | |
86 | 'Int' => 'int_data', | |
87 | 'StateProvince' => 'int_data', | |
88 | 'Country' => 'int_data', | |
89 | 'Float' => 'float_data', | |
90 | 'Memo' => 'memo_data', | |
91 | 'Money' => 'decimal_data', | |
92 | 'Date' => 'date_data', | |
93 | 'Link' => 'char_data', | |
94 | ); | |
95 | ||
96 | foreach ($values as $type => $value) { | |
97 | $valid = CRM_Core_BAO_CustomValue::typeToField($type); | |
98 | $this->assertEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.'); | |
99 | } | |
100 | } | |
101 | ||
00be9182 | 102 | public function testTypeToFieldWithWrongInput() { |
6a488035 TO |
103 | $values = array( |
104 | 'String' => 'memo_data', | |
105 | 'File' => 'date_data', | |
106 | 'Boolean' => 'char_data', | |
107 | ); | |
108 | foreach ($values as $type => $value) { | |
109 | $valid = CRM_Core_BAO_CustomValue::typeToField($type); | |
110 | $this->assertNotEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.'); | |
111 | } | |
112 | } | |
113 | ||
7991e3b2 | 114 | public function fixCustomFieldValue() { |
6a488035 TO |
115 | $customGroup = Custom::createGroup(array(), 'Individual'); |
116 | ||
117 | $fields = array( | |
118 | 'groupId' => $customGroup->id, | |
119 | 'dataType' => 'Memo', | |
120 | 'htmlType' => 'TextArea', | |
121 | ); | |
122 | ||
123 | $customField = Custom::createField(array(), $fields); | |
124 | ||
125 | $custom = 'custom_' . $customField->id; | |
6a488035 TO |
126 | $params = array( |
127 | 'email' => 'abc@webaccess.co.in', | |
128 | $custom => 'note', | |
129 | ); | |
130 | ||
7991e3b2 | 131 | CRM_Core_BAO_CustomValue::fixCustomFieldValue($params); |
6a488035 TO |
132 | $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.'); |
133 | ||
134 | Custom::deleteField($customField); | |
135 | Custom::deleteGroup($customGroup); | |
136 | } | |
137 | ||
7991e3b2 | 138 | public function testFixCustomFieldValueWithEmptyParams() { |
6a488035 | 139 | $params = array(); |
7991e3b2 | 140 | $result = CRM_Core_BAO_CustomValue::fixCustomFieldValue($params); |
6a488035 TO |
141 | $this->assertEquals($result, NULL, 'Checking the returned value of type Memo.'); |
142 | } | |
96025800 | 143 | |
6a488035 | 144 | } |