3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class CRM_Core_BAO_CustomValueTest
22 class CRM_Core_BAO_CustomValueTest
extends CiviUnitTestCase
{
24 public function testTypeCheckWithValidInput() {
31 'Date' => '2008-06-24',
33 'StateProvince' => 'California',
35 'Link' => 'http://civicrm.org',
37 foreach ($values as $type => $value) {
38 $valid = CRM_Core_BAO_CustomValue
::typecheck($type, $value);
39 if ($type == 'Date') {
40 $this->assertEquals($valid, '2008-06-24', 'Checking type ' . $type . ' for returned CustomField Type.');
43 $this->assertEquals($valid, TRUE, 'Checking type ' . $type . ' for returned CustomField Type.');
48 public function testTypeCheckWithInvalidInput() {
49 $values = ['check1' => 'chk'];
50 foreach ($values as $type => $value) {
51 $valid = CRM_Core_BAO_CustomValue
::typecheck($type, $value);
52 $this->assertEquals($valid, NULL, 'Checking invalid type for returned CustomField Type.');
56 public function testTypeCheckWithWrongInput() {
61 foreach ($values as $type => $value) {
62 $valid = CRM_Core_BAO_CustomValue
::typecheck($type, $value);
63 $this->assertEquals($valid, NULL, 'Checking type ' . $type . ' for returned CustomField Type.');
67 public function testTypeToFieldWithValidInput() {
69 'String' => 'char_data',
70 'File' => 'char_data',
71 'Boolean' => 'int_data',
73 'StateProvince' => 'int_data',
74 'Country' => 'int_data',
75 'Float' => 'float_data',
76 'Memo' => 'memo_data',
77 'Money' => 'decimal_data',
78 'Date' => 'date_data',
79 'Link' => 'char_data',
82 foreach ($values as $type => $value) {
83 $valid = CRM_Core_BAO_CustomValue
::typeToField($type);
84 $this->assertEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.');
88 public function testTypeToFieldWithWrongInput() {
90 'String' => 'memo_data',
91 'File' => 'date_data',
92 'Boolean' => 'char_data',
94 foreach ($values as $type => $value) {
95 $valid = CRM_Core_BAO_CustomValue
::typeToField($type);
96 $this->assertNotEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.');
100 public function fixCustomFieldValue() {
101 $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
104 'custom_group_id' => $customGroup['id'],
105 'data_type' => 'Memo',
106 'html_type' => 'TextArea',
107 'default_value' => '',
110 $customField = $this->customFieldCreate($fields);
112 $custom = 'custom_' . $customField['id'];
114 'email' => 'abc@webaccess.co.in',
118 CRM_Core_BAO_CustomValue
::fixCustomFieldValue($params);
119 $this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.');
121 $this->customFieldDelete($customField['id']);
122 $this->customGroupDelete($customGroup['id']);
125 public function testFixCustomFieldValueWithEmptyParams() {
127 $result = CRM_Core_BAO_CustomValue
::fixCustomFieldValue($params);
128 $this->assertEquals($result, NULL, 'Checking the returned value of type Memo.');