* Test retrieve()
*/
public function testRetrieve() {
- $customGrouptitle = 'My Custom Group';
+ $customGroupTitle = 'Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'My_Custom_Group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 1,
'collapse_display' => 1,
'weight' => 2,
- 'version' => 3,
- );
-
- $customGroup = Custom::createGroup($groupParams);
- $customGroupId = $customGroup->id;
-
- $params = array('id' => $customGroupId);
- $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
- $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
- 'Database check for custom group record.'
);
- $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
- //check retieve values
- unset($groupParams['version']);
- $this->assertAttributesEquals($groupParams, $dafaults);
+ $customGroup = $this->customGroupCreate($groupParams);
- //cleanup DB by deleting customGroup
- Custom::deleteGroup($customGroup);
+ $this->getAndCheck($groupParams, $customGroup['id'], 'CustomGroup');
}
/**
* Test setIsActive()
*/
public function testSetIsActive() {
- $customGrouptitle = 'My Custom Group';
+ $customGroupTitle = 'My Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 0,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
- $customGroupId = $customGroup->id;
+ $customGroup = $this->customGroupCreate($groupParams);
+ $customGroupId = $customGroup['id'];
//update is_active
$result = CRM_Core_BAO_CustomGroup::setIsActive($customGroupId, TRUE);
$this->assertDBCompareValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'is_active', 'id', 1,
'Database check for custom group is_active field.'
);
- //cleanup DB by deleting customGroup
- Custom::deleteGroup($customGroup);
+
+ $this->customGroupDelete($customGroup['id']);
}
/**
}
/**
- * Test getGroupDetail() with Inalid Params
+ * Test getGroupDetail with Invalid Params.
*/
public function testGetGroupDetailInvalidParams() {
$customGroupId = 99;
}
/**
- * Test getGroupDetail()
+ * Test getGroupDetail().
*/
public function testGetGroupDetail() {
- $customGrouptitle = 'My Custom Group';
+ $customGroupTitle = 'My Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'My_Custom_Group',
'extends' => 'Individual',
'help_pre' => 'Custom Group Help Pre',
'help_post' => 'Custom Group Help Post',
'is_active' => 1,
'collapse_display' => 1,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
- $customGroupId = $customGroup->id;
+ $customGroup = $this->customGroupCreate($groupParams);
+ $customGroupId = $customGroup['id'];
$fieldParams = array(
'custom_group_id' => $customGroupId,
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
- 'version' => 3,
);
- $customField = Custom::createField($fieldParams);
- $customFieldId = $customField->id;
+ $customField = $this->customFieldCreate($fieldParams);
+ $customFieldId = $customField['id'];
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId);
- $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
+ $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
'Database check for custom group record.'
);
//check retieve values of custom group
unset($fieldParams['version']);
$this->assertAttributesEquals($fieldParams, $groupTree[$customGroupId]['fields'][$customFieldId], " in line " . __LINE__);
- //cleanup DB by deleting customGroup
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
+ $this->customFieldDelete($customField['id']);
+ $this->customGroupDelete($customGroup['id']);
}
/**
* Test getTitle()
*/
public function testGetTitle() {
- $customGrouptitle = 'My Custom Group';
+ $customGroupTitle = 'Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 0,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
- $customGroupId = $customGroup->id;
+ $customGroup = $this->customGroupCreate($groupParams);
+ $customGroupId = $customGroup['id'];
//get the custom group title
$title = CRM_Core_BAO_CustomGroup::getTitle($customGroupId);
//check for object update
- $this->assertEquals($customGrouptitle, $title);
+ $this->assertEquals($customGroupTitle, $title);
- //cleanup DB by deleting customGroup
- Custom::deleteGroup($customGroup);
+ $this->customGroupDelete($customGroupId);
}
/**
- * Test deleteGroup()
+ * Test deleteGroup.
*/
public function testDeleteGroup() {
- $customGrouptitle = 'My Custom Group';
+ $customGroupTitle = 'My Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 1,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
-
- $customGroupId = $customGroup->id;
-
- //get the custom group title
- $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
- 'Database check for custom group record.'
- );
- //check for group title
- $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
+ $customGroup = $this->customGroupCreate($groupParams);
+ $groupObject = new CRM_Core_BAO_CustomGroup();
+ $groupObject->id = $customGroup['id'];
+ $groupObject->find(TRUE);
- //delete the group
- $isDelete = CRM_Core_BAO_CustomGroup::deleteGroup($customGroup);
+ $isDelete = CRM_Core_BAO_CustomGroup::deleteGroup($groupObject);
- //check for delete
+ // Check it worked!
$this->assertEquals(TRUE, $isDelete);
-
- //check the DB
- $this->assertDBNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
+ $this->assertDBNull('CRM_Core_DAO_CustomGroup', $customGroup['id'], 'title', 'id',
'Database check for custom group record.'
);
}
* Test createTable()
*/
public function testCreateTable() {
- $customGrouptitle = 'My Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => 'My Custom Group',
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
$tableName = 'civicrm_value_test_group_' . $customGroup->id;
$customGroup->table_name = $tableName;
$customGroup = $customGroupBAO->save();
- $customTable = CRM_Core_BAO_CustomGroup::createTable($customGroup);
+ CRM_Core_BAO_CustomGroup::createTable($customGroup);
$customGroupId = $customGroup->id;
//check db for custom group.
$tableName, 'Database check for custom group table name.'
);
- //check for group title
- $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
-
- //cleanup DB by deleting customGroup
- Custom::deleteGroup($customGroup);
+ $this->customGroupDelete($customGroup->id);
}
/**
* Test checkCustomField()
*/
public function testCheckCustomField() {
- $customGroupTitle = 'My Custom Group';
$groupParams = array(
- 'title' => $customGroupTitle,
+ 'title' => 'My Custom Group',
'name' => 'my_custom_group',
'extends' => 'Individual',
'help_pre' => 'Custom Group Help Pre',
'help_post' => 'Custom Group Help Post',
'is_active' => 1,
'collapse_display' => 1,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
- $this->assertNotNull($customGroup->id, 'pre-requisite group not created successfully');
- $customGroupId = $customGroup->id;
+ $customGroup = $this->customGroupCreate($groupParams);
+ $this->assertNotNull($customGroup['id'], 'pre-requisite group not created successfully');
+ $customGroupId = $customGroup['id'];
$customFieldLabel = 'Test Custom Field';
$fieldParams = array(
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
- 'version' => 3,
);
- $customField = Custom::createField($fieldParams);
- $this->assertNotNull($customField->id, 'pre-requisite field not created successfully');
-
- $customFieldId = $customField->id;
+ $customField = $this->customFieldCreate($fieldParams);
+ $customField = $customField['values'][$customField['id']];
- //check db for custom group
- $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id',
- 'Database check for custom group record.'
- );
- $this->assertEquals($customGroupTitle, $dbCustomGroupTitle);
+ $customFieldId = $customField['id'];
//check db for custom field
$dbCustomFieldLabel = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customFieldId, 'label', 'id',
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(TRUE, $usedFor);
- //cleanup DB by deleting customGroup
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
+ $this->customFieldDelete($customField['id']);
+ $this->customGroupDelete($customGroup['id']);
}
/**
public function testGetActiveGroups() {
$contactId = $this->individualCreate();
- $customGrouptitle = 'Test Custom Group';
+ $customGroupTitle = 'Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'test_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'weight' => 10,
'is_active' => 1,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
+ $customGroup = $this->customGroupCreate($groupParams);
$activeGroup = CRM_Core_BAO_CustomGroup::getActiveGroups('Individual', 'civicrm/contact/view/cd', $contactId);
foreach ($activeGroup as $key => $value) {
- if ($value['id'] == $customGroup->id) {
+ if ($value['id'] == $customGroup['id']) {
$this->assertEquals($value['path'], 'civicrm/contact/view/cd');
- $this->assertEquals($value['title'], $customGrouptitle);
- $query = 'reset=1&gid=' . $customGroup->id . '&cid=' . $contactId;
+ $this->assertEquals($value['title'], $customGroupTitle);
+ $query = 'reset=1&gid=' . $customGroup['id'] . '&cid=' . $contactId;
$this->assertEquals($value['query'], $query);
}
}
- Custom::deleteGroup($customGroup);
+ $this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactId);
}
$this->assertEquals(strtolower("civicrm_value_{$params['name']}_{$customGroup->id}"), $dbCustomGroupTableName,
"The table name should be suffixed with '_ID' unless specified.");
- Custom::deleteGroup($customGroup);
+ $this->customGroupDelete($customGroup->id);
}
/**
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- 'version' => 3,
);
$customGroup = CRM_Core_BAO_CustomGroup::create($params);
);
$this->assertEquals($params['table_name'], $dbCustomGroupTableName);
- Custom::deleteGroup($customGroup);
+ $this->customGroupDelete($customGroup->id);
}
/**
* Test isGroupEmpty()
*/
public function testIsGroupEmpty() {
- $customGrouptitle = 'Test Custom Group';
+ $customGroupTitle = 'Test Custom Group';
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => $customGroupTitle,
'name' => 'test_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'weight' => 10,
'is_active' => 1,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
- $customGroupId = $customGroup->id;
+ $customGroup = $this->customGroupCreate($groupParams);
+ $customGroupId = $customGroup['id'];
$isEmptyGroup = CRM_Core_BAO_CustomGroup::isGroupEmpty($customGroupId);
$this->assertEquals($isEmptyGroup, TRUE, 'Check that custom Group is Empty.');
- Custom::deleteGroup($customGroup);
+ $this->customGroupDelete($customGroup['id']);
}
/**
* Test getGroupTitles() with Invalid Params()
*/
- public function testgetGroupTitlesWithInvalidParams() {
+ public function testGetGroupTitlesWithInvalidParams() {
$params = array(99);
$groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params);
- $this->assertTrue(empty($groupTitles), 'Check that no titles are recieved');
+ $this->assertTrue(empty($groupTitles), 'Check that no titles are received');
}
/**
* Test getGroupTitles()
*/
- public function testgetGroupTitles() {
- $customGrouptitle = 'Test Custom Group';
+ public function testGetGroupTitles() {
$groupParams = array(
- 'title' => $customGrouptitle,
+ 'title' => 'Test Group',
'name' => 'test_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'weight' => 10,
'is_active' => 1,
- 'version' => 3,
);
- $customGroup = Custom::createGroup($groupParams);
-
- $customGroupId = $customGroup->id;
+ $customGroup = $this->customGroupCreate($groupParams);
- $customFieldLabel = 'Test Custom Field';
$fieldParams = array(
- 'custom_group_id' => $customGroupId,
- 'label' => $customFieldLabel,
+ 'label' => 'Custom Field',
'html_type' => 'Text',
'data_type' => 'String',
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
- 'version' => 3,
+ 'custom_group_id' => $customGroup['id'],
);
- $customField = Custom::createField($fieldParams);
- $customFieldId = $customField->id;
+ $customField = $this->customFieldCreate($fieldParams);
+ $customFieldId = $customField['id'];
$params = array($customFieldId);
$groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params);
- $this->assertEquals($groupTitles[$customFieldId]['groupTitle'], 'Test Custom Group', 'Check Group Title.');
- Custom::deleteGroup($customGroup);
+ $this->assertEquals($groupTitles[$customFieldId]['groupTitle'], 'Test Group', 'Check Group Title.');
+ $this->customGroupDelete($customGroup['id']);
}
}
}
public function testCustomGroupMultipleSingle() {
- $params = array();
$contactID = $this->individualCreate();
- $customGroup = Custom::createGroup($params, 'Individual', TRUE);
+ $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
$fields = array(
- 'groupId' => $customGroup->id,
+ 'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
);
- $customField = Custom::createField($params, $fields);
+ $customField = $this->customFieldCreate($fields);
$params = array(
'entityID' => $contactID,
- "custom_{$customField->id}_-1" => 'First String',
+ "custom_{$customField['id']}_-1" => 'First String',
);
- $error = CRM_Core_BAO_CustomValueTable::setValues($params);
+ CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array(
'entityID' => $contactID,
- "custom_{$customField->id}" => 1,
+ "custom_{$customField['id']}" => 1,
);
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
- $this->assertEquals($params["custom_{$customField->id}_-1"], $result["custom_{$customField->id}_1"]);
+ $this->assertEquals($params["custom_{$customField['id']}_-1"], $result["custom_{$customField['id']}_1"]);
$this->assertEquals($params['entityID'], $result['entityID']);
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
+ $this->customFieldDelete($customField['id']);
+ $this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
public function testCustomGroupMultipleDouble() {
- $params = array();
$contactID = $this->individualCreate();
- $customGroup = Custom::createGroup($params, 'Individual', TRUE);
+ $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
$fields = array(
- 'groupId' => $customGroup->id,
+ 'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
);
- $customField = Custom::createField($params, $fields);
+ $customField = $this->customFieldCreate($fields);
$params = array(
'entityID' => $contactID,
- "custom_{$customField->id}_-1" => 'First String',
- "custom_{$customField->id}_-2" => 'Second String',
+ "custom_{$customField['id']}_-1" => 'First String',
+ "custom_{$customField['id']}_-2" => 'Second String',
);
- $error = CRM_Core_BAO_CustomValueTable::setValues($params);
+ CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array(
'entityID' => $contactID,
- "custom_{$customField->id}" => 1,
+ "custom_{$customField['id']}" => 1,
);
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
- $this->assertEquals($params["custom_{$customField->id}_-1"], $result["custom_{$customField->id}_1"]);
- $this->assertEquals($params["custom_{$customField->id}_-2"], $result["custom_{$customField->id}_2"]);
+ $this->assertEquals($params["custom_{$customField['id']}_-1"], $result["custom_{$customField['id']}_1"]);
+ $this->assertEquals($params["custom_{$customField['id']}_-2"], $result["custom_{$customField['id']}_2"]);
$this->assertEquals($params['entityID'], $result['entityID']);
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
+ $this->customFieldDelete($customField['id']);
+ $this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
public function testCustomGroupMultipleUpdate() {
- $params = array();
$contactID = $this->individualCreate();
- $customGroup = Custom::createGroup($params, 'Individual', TRUE);
+ $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
$fields = array(
- 'groupId' => $customGroup->id,
+ 'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
);
- $customField = Custom::createField($params, $fields);
+ $customField = $this->customFieldCreate($fields);
$params = array(
'entityID' => $contactID,
- "custom_{$customField->id}_-1" => 'First String',
- "custom_{$customField->id}_-2" => 'Second String',
- "custom_{$customField->id}_-3" => 'Third String',
+ "custom_{$customField['id']}_-1" => 'First String',
+ "custom_{$customField['id']}_-2" => 'Second String',
+ "custom_{$customField['id']}_-3" => 'Third String',
);
- $error = CRM_Core_BAO_CustomValueTable::setValues($params);
+ CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array(
'entityID' => $contactID,
- "custom_{$customField->id}_1" => 'Updated First String',
- "custom_{$customField->id}_3" => 'Updated Third String',
+ "custom_{$customField['id']}_1" => 'Updated First String',
+ "custom_{$customField['id']}_3" => 'Updated Third String',
);
- $result = CRM_Core_BAO_CustomValueTable::setValues($newParams);
+ CRM_Core_BAO_CustomValueTable::setValues($newParams);
$getParams = array(
'entityID' => $contactID,
- "custom_{$customField->id}" => 1,
+ "custom_{$customField['id']}" => 1,
);
$result = CRM_Core_BAO_CustomValueTable::getValues($getParams);
- $this->assertEquals($newParams["custom_{$customField->id}_1"], $result["custom_{$customField->id}_1"]);
- $this->assertEquals($params["custom_{$customField->id}_-2"], $result["custom_{$customField->id}_2"]);
- $this->assertEquals($newParams["custom_{$customField->id}_3"], $result["custom_{$customField->id}_3"]);
+ $this->assertEquals($newParams["custom_{$customField['id']}_1"], $result["custom_{$customField['id']}_1"]);
+ $this->assertEquals($params["custom_{$customField['id']}_-2"], $result["custom_{$customField['id']}_2"]);
+ $this->assertEquals($newParams["custom_{$customField['id']}_3"], $result["custom_{$customField['id']}_3"]);
$this->assertEquals($params['entityID'], $result['entityID']);
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
+ $this->customFieldDelete($customField['id']);
+ $this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}
- public function testCustomGroupMultipleOldFormate() {
- $params = array();
+ public function testCustomGroupMultipleOldFormat() {
$contactID = $this->individualCreate();
- $customGroup = Custom::createGroup($params, 'Individual', TRUE);
+ $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
$fields = array(
- 'groupId' => $customGroup->id,
+ 'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
);
- $customField = Custom::createField($params, $fields);
+ $customField = $this->customFieldCreate($fields);
$params = array(
'entityID' => $contactID,
- "custom_{$customField->id}" => 'First String',
+ "custom_{$customField['id']}" => 'First String',
);
- $error = CRM_Core_BAO_CustomValueTable::setValues($params);
+ CRM_Core_BAO_CustomValueTable::setValues($params);
$newParams = array(
'entityID' => $contactID,
- "custom_{$customField->id}" => 1,
+ "custom_{$customField['id']}" => 1,
);
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
- $this->assertEquals($params["custom_{$customField->id}"], $result["custom_{$customField->id}_1"]);
+ $this->assertEquals($params["custom_{$customField['id']}"], $result["custom_{$customField['id']}_1"]);
$this->assertEquals($params['entityID'], $result['entityID']);
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
+ $this->customFieldDelete($customField['id']);
+ $this->customGroupDelete($customGroup['id']);
$this->contactDelete($contactID);
}