}
/**
- * This function is called when the form is submitted.
+ * This function is called when the form is submitted and also from unit test.
+ * @param array $params
+ *
+ * @return array
*/
- public function postProcess() {
- // Store the submitted values in an array.
- $params = $this->controller->exportValues($this->_name);
-
+ public function submit($params) {
switch ($this->getAction()) {
case CRM_Core_Action::DELETE:
$this->deleteAction($this->_relationshipId);
- return;
+ return array();
case CRM_Core_Action::UPDATE:
- list ($params, $relationshipIds) = $this->updateAction($params);
- break;
+ return $this->updateAction($params);
default:
- list ($params, $relationshipIds) = $this->createAction($params);
- break;
+ return $this->createAction($params);
}
+ }
+
+ /**
+ * This function is called when the form is submitted.
+ */
+ public function postProcess() {
+ // Store the submitted values in an array.
+ $params = $this->controller->exportValues($this->_name);
+
+ $values = $this->submit($params);
+ if (empty($values)) {
+ return;
+ }
+ list ($params, $relationshipIds) = $values;
// if this is called from case view,
//create an activity for case role removal.CRM-4480
$params = $this->preparePostProcessParameters($params);
$params = $params[0];
- CRM_Contact_BAO_Relationship::create($params);
+ try {
+ civicrm_api3('relationship', 'create', $params);
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ throw new CRM_Core_Exception('Relationship create error ' . $e->getMessage());
+ }
$this->clearCurrentEmployer($params);
/**
* Check relationship creation with custom data.
*/
- public function testRelationshipCreateWithCustomData() {
+ public function testRelationshipCreateEditWithCustomData() {
$this->createCustomGroup();
$this->_ids = $this->createCustomField();
//few custom Values for comparing
);
$this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
+ //Test Edit of custom field from the form.
+ $getParams = array('id' => $result['id']);
+ $updateParams = array_merge($getParams, array(
+ "custom_{$this->_ids[0]}" => 'Edited Text Value',
+ 'relationship_type_id' => $this->_relTypeID . '_b_a',
+ 'related_contact_id' => $this->_cId_a,
+ ));
+ $reln = new CRM_Contact_Form_Relationship();
+ $reln->_action = CRM_Core_Action::UPDATE;
+ $reln->_relationshipId = $result['id'];
+ $reln->submit($updateParams);
+
+ $check = $this->callAPISuccess('relationship', 'get', $getParams);
+ $this->assertEquals("Edited Text Value", $check['values'][$check['id']]["custom_{$this->_ids[0]}"]);
+
$params['id'] = $result['id'];
$this->callAPISuccess('relationship', 'delete', $params);
$this->relationshipTypeDelete($this->_relTypeID);
'is_active' => 1,
);
- $this->callAPISuccess('CustomField', 'create', $params);
-
- $customField = NULL;
- $ids[] = $customField['result']['customFieldId'];
+ $customField = $this->callAPISuccess('CustomField', 'create', $params);
+ $ids[] = $customField['id'];
$optionValue[] = array(
'label' => 'Red',