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