$group = uniqid('groupc');
$colorField = uniqid('colorc');
+ $multiField = uniqid('chkbx');
$textField = uniqid('txt');
$customGroup = CustomGroup::create()
->addValue('data_type', 'String')
->execute();
+ CustomField::create()
+ ->setCheckPermissions(FALSE)
+ ->addValue('label', $multiField)
+ ->addValue('options', $optionValues)
+ ->addValue('custom_group_id', $customGroup['id'])
+ ->addValue('html_type', 'CheckBox')
+ ->addValue('data_type', 'String')
+ ->execute();
+
CustomField::create()
->setCheckPermissions(FALSE)
->addValue('label', $textField)
$fields = CustomValue::getFields($group)->execute();
$expectedResult = [
[
- 'custom_field_id' => 1,
'custom_group' => $group,
'name' => $colorField,
'title' => $colorField,
'entity' => "Custom_$group",
'data_type' => 'String',
'fk_entity' => NULL,
+ 'serialize' => NULL,
+ ],
+ [
+ 'custom_group' => $group,
+ 'name' => $multiField,
+ 'title' => $multiField,
+ 'entity' => "Custom_$group",
+ 'data_type' => 'String',
+ 'fk_entity' => NULL,
+ 'serialize' => 1,
],
[
- 'custom_field_id' => 2,
'custom_group' => $group,
'name' => $textField,
'title' => $textField,
'entity' => "Custom_$group",
'data_type' => 'String',
'fk_entity' => NULL,
+ 'serialize' => NULL,
],
[
'name' => 'id',
// CASE 1: Test CustomValue::create
// Create two records for a single contact and using CustomValue::get ensure that two records are created
CustomValue::create($group)
- ->addValue($colorField, 'Green')
+ ->addValue($colorField, 'g')
->addValue("entity_id", $this->contactID)
->execute();
CustomValue::create($group)
- ->addValue($colorField, 'Red')
+ ->addValue($colorField, 'r')
->addValue("entity_id", $this->contactID)
->execute();
// fetch custom values using API4 CustomValue::get
$expectedResult = [
[
'id' => 1,
- $colorField => 'Green',
+ $colorField => 'g',
'entity_id' => $this->contactID,
],
[
'id' => 2,
- $colorField => 'Red',
+ $colorField => 'r',
'entity_id' => $this->contactID,
],
];
}
// CASE 2: Test CustomValue::update
- // Update a records whose id is 1 and change the custom field (name = Color) value to 'White' from 'Green'
+ // Update a records whose id is 1 and change the custom field (name = Color) value to 'Blue' from 'Green'
CustomValue::update($group)
->addWhere("id", "=", 1)
- ->addValue($colorField, 'White')
+ ->addValue($colorField, 'b')
->execute();
// ensure that the value is changed for id = 1
->addWhere("id", "=", 1)
->execute()
->first()[$colorField];
- $this->assertEquals('White', $color);
+ $this->assertEquals('b', $color);
// CASE 3: Test CustomValue::replace
// create a second contact which will be used to replace the custom values, created earlier
->execute()
->first()['id'];
// Replace all the records which was created earlier with entity_id = first contact
- // with custom record [$colorField => 'Rainbow', 'entity_id' => $secondContactID]
+ // with custom record [$colorField => 'g', 'entity_id' => $secondContactID]
CustomValue::replace($group)
- ->setRecords([[$colorField => 'Rainbow', 'entity_id' => $secondContactID]])
+ ->setRecords([[$colorField => 'g', $multiField => ['r', 'g'], 'entity_id' => $secondContactID]])
->addWhere('entity_id', '=', $this->contactID)
->execute();
$expectedResult = [
[
'id' => 3,
- $colorField => 'Rainbow',
+ $colorField => 'g',
+ $multiField => ['r', 'g'],
'entity_id' => $secondContactID,
],
];