Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
aba1cd8b EM |
3 | /** |
4 | * Class CRM_Core_BAO_CustomValueTableMultipleTest | |
5 | */ | |
6a488035 | 6 | class CRM_Core_BAO_CustomValueTableMultipleTest extends CiviUnitTestCase { |
6a488035 | 7 | |
00be9182 | 8 | public function setUp() { |
6a488035 TO |
9 | parent::setUp(); |
10 | } | |
11 | ||
00be9182 | 12 | public function testCustomGroupMultipleSingle() { |
92915c55 TO |
13 | $params = array(); |
14 | $contactID = Contact::createIndividual(); | |
6a488035 | 15 | $customGroup = Custom::createGroup($params, 'Individual', TRUE); |
92915c55 | 16 | $fields = array( |
6a488035 TO |
17 | 'groupId' => $customGroup->id, |
18 | 'dataType' => 'String', | |
19 | 'htmlType' => 'Text', | |
20 | ); | |
21 | $customField = Custom::createField($params, $fields); | |
22 | ||
23 | $params = array( | |
24 | 'entityID' => $contactID, | |
25 | "custom_{$customField->id}_-1" => 'First String', | |
26 | ); | |
27 | $error = CRM_Core_BAO_CustomValueTable::setValues($params); | |
28 | ||
29 | $newParams = array( | |
30 | 'entityID' => $contactID, | |
31 | "custom_{$customField->id}" => 1, | |
32 | ); | |
33 | $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); | |
34 | ||
35 | $this->assertEquals($params["custom_{$customField->id}_-1"], $result["custom_{$customField->id}_1"]); | |
36 | $this->assertEquals($params['entityID'], $result['entityID']); | |
37 | ||
38 | Custom::deleteField($customField); | |
39 | Custom::deleteGroup($customGroup); | |
40 | Contact::delete($contactID); | |
41 | } | |
42 | ||
00be9182 | 43 | public function testCustomGroupMultipleDouble() { |
92915c55 TO |
44 | $params = array(); |
45 | $contactID = Contact::createIndividual(); | |
6a488035 | 46 | $customGroup = Custom::createGroup($params, 'Individual', TRUE); |
92915c55 | 47 | $fields = array( |
6a488035 TO |
48 | 'groupId' => $customGroup->id, |
49 | 'dataType' => 'String', | |
50 | 'htmlType' => 'Text', | |
51 | ); | |
52 | $customField = Custom::createField($params, $fields); | |
53 | ||
54 | $params = array( | |
55 | 'entityID' => $contactID, | |
56 | "custom_{$customField->id}_-1" => 'First String', | |
57 | "custom_{$customField->id}_-2" => 'Second String', | |
58 | ); | |
59 | $error = CRM_Core_BAO_CustomValueTable::setValues($params); | |
60 | ||
61 | $newParams = array( | |
62 | 'entityID' => $contactID, | |
63 | "custom_{$customField->id}" => 1, | |
64 | ); | |
65 | $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); | |
66 | ||
67 | $this->assertEquals($params["custom_{$customField->id}_-1"], $result["custom_{$customField->id}_1"]); | |
68 | $this->assertEquals($params["custom_{$customField->id}_-2"], $result["custom_{$customField->id}_2"]); | |
69 | $this->assertEquals($params['entityID'], $result['entityID']); | |
70 | ||
71 | Custom::deleteField($customField); | |
72 | Custom::deleteGroup($customGroup); | |
73 | Contact::delete($contactID); | |
74 | } | |
75 | ||
00be9182 | 76 | public function testCustomGroupMultipleUpdate() { |
92915c55 TO |
77 | $params = array(); |
78 | $contactID = Contact::createIndividual(); | |
6a488035 | 79 | $customGroup = Custom::createGroup($params, 'Individual', TRUE); |
92915c55 | 80 | $fields = array( |
6a488035 TO |
81 | 'groupId' => $customGroup->id, |
82 | 'dataType' => 'String', | |
83 | 'htmlType' => 'Text', | |
84 | ); | |
85 | $customField = Custom::createField($params, $fields); | |
86 | ||
87 | $params = array( | |
88 | 'entityID' => $contactID, | |
89 | "custom_{$customField->id}_-1" => 'First String', | |
90 | "custom_{$customField->id}_-2" => 'Second String', | |
91 | "custom_{$customField->id}_-3" => 'Third String', | |
92 | ); | |
93 | $error = CRM_Core_BAO_CustomValueTable::setValues($params); | |
94 | ||
95 | $newParams = array( | |
96 | 'entityID' => $contactID, | |
97 | "custom_{$customField->id}_1" => 'Updated First String', | |
98 | "custom_{$customField->id}_3" => 'Updated Third String', | |
99 | ); | |
100 | $result = CRM_Core_BAO_CustomValueTable::setValues($newParams); | |
101 | ||
102 | $getParams = array( | |
103 | 'entityID' => $contactID, | |
104 | "custom_{$customField->id}" => 1, | |
105 | ); | |
106 | $result = CRM_Core_BAO_CustomValueTable::getValues($getParams); | |
107 | ||
108 | $this->assertEquals($newParams["custom_{$customField->id}_1"], $result["custom_{$customField->id}_1"]); | |
109 | $this->assertEquals($params["custom_{$customField->id}_-2"], $result["custom_{$customField->id}_2"]); | |
110 | $this->assertEquals($newParams["custom_{$customField->id}_3"], $result["custom_{$customField->id}_3"]); | |
111 | $this->assertEquals($params['entityID'], $result['entityID']); | |
112 | ||
113 | Custom::deleteField($customField); | |
114 | Custom::deleteGroup($customGroup); | |
115 | Contact::delete($contactID); | |
116 | } | |
117 | ||
00be9182 | 118 | public function testCustomGroupMultipleOldFormate() { |
92915c55 TO |
119 | $params = array(); |
120 | $contactID = Contact::createIndividual(); | |
6a488035 | 121 | $customGroup = Custom::createGroup($params, 'Individual', TRUE); |
92915c55 | 122 | $fields = array( |
6a488035 TO |
123 | 'groupId' => $customGroup->id, |
124 | 'dataType' => 'String', | |
125 | 'htmlType' => 'Text', | |
126 | ); | |
127 | $customField = Custom::createField($params, $fields); | |
128 | ||
129 | $params = array( | |
130 | 'entityID' => $contactID, | |
131 | "custom_{$customField->id}" => 'First String', | |
132 | ); | |
133 | $error = CRM_Core_BAO_CustomValueTable::setValues($params); | |
134 | ||
135 | $newParams = array( | |
136 | 'entityID' => $contactID, | |
137 | "custom_{$customField->id}" => 1, | |
138 | ); | |
139 | $result = CRM_Core_BAO_CustomValueTable::getValues($newParams); | |
140 | ||
141 | $this->assertEquals($params["custom_{$customField->id}"], $result["custom_{$customField->id}_1"]); | |
142 | $this->assertEquals($params['entityID'], $result['entityID']); | |
143 | ||
144 | Custom::deleteField($customField); | |
145 | Custom::deleteGroup($customGroup); | |
146 | Contact::delete($contactID); | |
147 | } | |
96025800 | 148 | |
6a488035 | 149 | } |