From d6238393e205423cdaffab5b4ed5b47a3751d1e8 Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Mon, 2 Oct 2017 22:24:36 +0200 Subject: [PATCH] A unit test to illustrate CRM-21246. Chaining Contact.get - Relationship.get - Contact.get does not work. Added a test that passes as well. --- tests/phpunit/api/v3/RelationshipTest.php | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index 040b98df5a..da50d23f1d 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -778,6 +778,61 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $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 -- 2.25.1