3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
34 require_once 'CiviTest/CiviUnitTestCase.php';
35 require_once 'CiviTest/Custom.php';
38 * Class CRM_Core_BAO_CustomValueTest
40 class CRM_Core_BAO_CustomValueTest
extends CiviUnitTestCase
{
41 public function testTypeCheckWithValidInput() {
48 'Date' => '2008-06-24',
50 'StateProvince' => 'California',
52 'Link' => 'http://civicrm.org',
54 foreach ($values as $type => $value) {
55 $valid = CRM_Core_BAO_CustomValue
::typecheck($type, $value);
56 if ($type == 'Date') {
57 $this->assertEquals($valid, '2008-06-24', 'Checking type ' . $type . ' for returned CustomField Type.');
60 $this->assertEquals($valid, TRUE, 'Checking type ' . $type . ' for returned CustomField Type.');
65 public function testTypeCheckWithInvalidInput() {
66 $values = array('check1' => 'chk');
67 foreach ($values as $type => $value) {
68 $valid = CRM_Core_BAO_CustomValue
::typecheck($type, $value);
69 $this->assertEquals($valid, NULL, 'Checking invalid type for returned CustomField Type.');
73 public function testTypeCheckWithWrongInput() {
78 foreach ($values as $type => $value) {
79 $valid = CRM_Core_BAO_CustomValue
::typecheck($type, $value);
80 $this->assertEquals($valid, NULL, 'Checking type ' . $type . ' for returned CustomField Type.');
84 public function testTypeToFieldWithValidInput() {
86 'String' => 'char_data',
87 'File' => 'char_data',
88 'Boolean' => 'int_data',
90 'StateProvince' => 'int_data',
91 'Country' => 'int_data',
92 'Float' => 'float_data',
93 'Memo' => 'memo_data',
94 'Money' => 'decimal_data',
95 'Date' => 'date_data',
96 'Link' => 'char_data',
99 foreach ($values as $type => $value) {
100 $valid = CRM_Core_BAO_CustomValue
::typeToField($type);
101 $this->assertEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.');
105 public function testTypeToFieldWithWrongInput() {
107 'String' => 'memo_data',
108 'File' => 'date_data',
109 'Boolean' => 'char_data',
111 foreach ($values as $type => $value) {
112 $valid = CRM_Core_BAO_CustomValue
::typeToField($type);
113 $this->assertNotEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.');
117 public function fixCustomFieldValue() {
118 $customGroup = Custom
::createGroup(array(), 'Individual');
121 'groupId' => $customGroup->id
,
122 'dataType' => 'Memo',
123 'htmlType' => 'TextArea',
126 $customField = Custom
::createField(array(), $fields);
128 $custom = 'custom_' . $customField->id
;
130 'email' => 'abc@webaccess.co.in',
134 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($params);
135 $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.');
137 Custom
::deleteField($customField);
138 Custom
::deleteGroup($customGroup);
141 public function testFixCustomFieldValueWithEmptyParams() {
143 $result = CRM_Core_BAO_CustomValue
::fixCustomFieldValue($params);
144 $this->assertEquals($result, NULL, 'Checking the returned value of type Memo.');