protected $customFieldID;
- public function setUp() {
- parent::setUp();
+ /**
+ * Clean up after test.
+ *
+ * @throws \Exception
+ */
+ public function tearDown() {
+ $this->quickCleanup([], TRUE);
+ parent::tearDown();
}
+ /**
+ * Test creating a custom field.
+ */
public function testCreateCustomField() {
$customGroup = $this->createCustomField();
$customFieldID = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup['id'], 'id', 'custom_group_id',
$this->customGroupDelete($customGroup['id']);
}
+ /**
+ * Test custom field create accepts passed column name.
+ */
public function testCreateCustomFieldColumnName() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);
$fields = [
$this->customGroupDelete($customGroup['id']);
}
+ /**
+ * Test that name is used for the column.
+ */
public function testCreateCustomFieldName() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);
$fields = [
$this->customGroupDelete($customGroup['id']);
}
+ /**
+ * Test get fields function.
+ */
public function testGetFields() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);
$fields = [
$this->customGroupDelete($customGroup['id']);
}
+ /**
+ * @throws \Exception
+ */
public function testGetDisplayedValues() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);
$fieldsToCreate = [
],
];
foreach ($fieldsToCreate as $num => $field) {
- $params = $field + [
- 'label' => 'test field ' . $num,
- 'custom_group_id' => $customGroup['id'],
- ];
+ $params = $field + ['label' => 'test field ' . $num, 'custom_group_id' => $customGroup['id']];
unset($params['tests']);
$createdField = $this->callAPISuccess('customField', 'create', $params);
foreach ($field['tests'] as $expected => $input) {
$this->customGroupDelete($customGroup['id']);
}
+ /**
+ * Test CRM_Core_BAO_CustomField::displayValue.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \Exception
+ */
public function testGetDisplayedValuesContactRef() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);
$params = [
* Move a custom field from $groupA to $groupB.
*
* Make sure that data records are correctly matched and created.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testMoveField() {
$countriesByName = array_flip(CRM_Core_PseudoConstant::country(FALSE, FALSE));
/**
* Test get custom field id function.
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public function testGetCustomFieldID() {
$this->createCustomField();
}
/**
- * Tet the getFieldsForImport function.
+ * Test the getFieldsForImport function.
+ *
+ * @throws \Exception
*/
public function testGetFieldsForImport() {
$this->entity = 'Contact';
$this->createCustomGroupWithFieldsOfAllTypes();
+ $customGroupID = $this->ids['CustomGroup']['Custom Group'];
$expected = [
$this->getCustomFieldName('country') => [
- 'name' => $this->getCustomFieldName('country') ,
+ 'name' => $this->getCustomFieldName('country'),
'type' => 1,
'title' => 'Country',
'headerPattern' => '//',
'data_type' => 'Int',
'html_type' => 'Select Country',
'is_search_range' => '0',
+ 'id' => $this->getCustomFieldID('country'),
+ 'label' => 'Country',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => NULL,
+ 'custom_group_id' => $customGroupID,
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => NULL,
+ 'date_format' => NULL,
+ 'time_format' => NULL,
+ 'is_required' => '0',
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => 'country_' . $this->getCustomFieldID('country'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.country_' . $this->getCustomFieldID('country'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
],
- $this->getCustomFieldName('file') => [
+ $this->getCustomFieldName('file') => [
'name' => $this->getCustomFieldName('file'),
'type' => 2,
'title' => 'Custom Field',
'data_type' => 'File',
'html_type' => 'File',
'is_search_range' => '0',
+ 'id' => $this->getCustomFieldID('file'),
+ 'label' => 'Custom Field',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => NULL,
+ 'custom_group_id' => $customGroupID,
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => NULL,
+ 'date_format' => NULL,
+ 'time_format' => NULL,
+ 'is_required' => '0',
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => 'custom_field_' . $this->getCustomFieldID('file'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.custom_field_' . $this->getCustomFieldID('file'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
],
$this->getCustomFieldName('text') => [
'name' => $this->getCustomFieldName('text'),
'data_type' => 'String',
'html_type' => 'Text',
'is_search_range' => '0',
+ 'id' => $this->getCustomFieldID('text'),
+ 'label' => 'Enter text here',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => 'xyz',
+ 'custom_group_id' => '1',
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => NULL,
+ 'date_format' => NULL,
+ 'time_format' => NULL,
+ 'is_required' => '1',
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => 'enter_text_here_' . $this->getCustomFieldID('text'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.enter_text_here_' . $this->getCustomFieldID('text'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
],
$this->getCustomFieldName('select_string') => [
- 'name' => $this->getCustomFieldName('select_string'),
+ 'name' => $this->getCustomFieldName('select_string'),
'type' => 2,
'title' => 'Pick Color',
'headerPattern' => '//',
'data_type' => 'String',
'html_type' => 'Select',
'is_search_range' => '0',
+ 'id' => $this->getCustomFieldID('select_string'),
+ 'label' => 'Pick Color',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => NULL,
+ 'custom_group_id' => $customGroupID,
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id']),
+ 'date_format' => NULL,
+ 'time_format' => NULL,
+ 'is_required' => '1',
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => 'pick_color_' . $this->getCustomFieldID('select_string'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.pick_color_' . $this->getCustomFieldID('select_string'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
+ 'pseudoconstant' => [
+ 'optionGroupName' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']),
+ 'optionEditPath' => 'civicrm/admin/options/' . $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']),
+ ],
],
$this->getCustomFieldName('select_date') => [
'name' => $this->getCustomFieldName('select_date'),
'is_search_range' => '0',
'date_format' => 'mm/dd/yy',
'time_format' => '1',
+ 'id' => $this->getCustomFieldID('select_date'),
+ 'label' => 'test_date',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => '20090711',
+ 'custom_group_id' => $customGroupID,
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => NULL,
+ 'is_required' => '0',
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => 'test_date_' . $this->getCustomFieldID('select_date'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_date_' . $this->getCustomFieldID('select_date'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
],
$this->getCustomFieldName('link') => [
'name' => $this->getCustomFieldName('link'),
'data_type' => 'Link',
'html_type' => 'Link',
'is_search_range' => '0',
+ 'id' => $this->getCustomFieldID('link'),
+ 'label' => 'test_link',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => 'http://civicrm.org',
+ 'custom_group_id' => $customGroupID,
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => NULL,
+ 'date_format' => NULL,
+ 'time_format' => NULL,
+ 'is_required' => '1',
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => 'test_link_' . $this->getCustomFieldID('link'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_link_' . $this->getCustomFieldID('link'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
],
];
$this->assertEquals($expected, CRM_Core_BAO_CustomField::getFieldsForImport());