* +--------------------------------------------------------------------+
* | CiviCRM version 4.7 |
* +--------------------------------------------------------------------+
- * | Copyright CiviCRM LLC (c) 2004-2017 |
+ * | Copyright CiviCRM LLC (c) 2004-2018 |
* +--------------------------------------------------------------------+
* | This file is a part of CiviCRM. |
* | |
/**
* 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',
$this->assertEquals($result['count'], 0);
}
+ /**
+ * Chain Relationship.get and to Contact.get.
+ */
+ public function testRelationshipGetWithChainedCall() {
+ // Create a relationship.
+ $createResult = $this->callAPISuccess('relationship', 'create', $this->_params);
+ $id = $createResult['id'];
+
+ // Try to retrieve it using chaining.
+ $params = array(
+ 'relationship_type_id' => $this->_relTypeID,
+ 'id' => $id,
+ 'api.Contact.get' => array(
+ 'id' => '$value.contact_id_b',
+ ),
+ );
+
+ $result = $this->callAPISuccess('relationship', 'get', $params);
+
+ $this->assertEquals(1, $result['count']);
+ $relationship = CRM_Utils_Array::first($result['values']);
+ $this->assertEquals(1, $relationship['api.Contact.get']['count']);
+ $contact = CRM_Utils_Array::first($relationship['api.Contact.get']['values']);
+ $this->assertEquals($this->_cId_b, $contact['id']);
+ }
+
+ /**
+ * Chain Contact.get to Relationship.get and again to Contact.get.
+ */
+ public function testRelationshipGetInChainedCall() {
+ // Create a relationship.
+ $this->callAPISuccess('relationship', 'create', $this->_params);
+
+ // Try to retrieve it using chaining.
+ $params = array(
+ 'id' => $this->_cId_a,
+ 'api.Relationship.get' => array(
+ 'relationship_type_id' => $this->_relTypeID,
+ 'contact_id_a' => '$value.id',
+ 'api.Contact.get' => array(
+ 'id' => '$value.contact_id_b',
+ ),
+ ),
+ );
+
+ $result = $this->callAPISuccess('contact', 'get', $params);
+ $this->assertEquals(1, $result['count']);
+ $contact = CRM_Utils_Array::first($result['values']);
+ $this->assertEquals(1, $contact['api.Relationship.get']['count']);
+ $relationship = CRM_Utils_Array::first($contact['api.Relationship.get']['values']);
+ $this->assertEquals(1, $relationship['api.Contact.get']['count']);
+ $contact = CRM_Utils_Array::first($relationship['api.Contact.get']['values']);
+ $this->assertEquals($this->_cId_b, $contact['id']);
+ }
+
/**
* Check with valid params array.
* (The get function will behave differently without 'contact_id' passed