From 92d270fdd0ca6ea4387397844f8f648d82e488c2 Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Tue, 10 Mar 2015 13:11:24 +0100 Subject: [PATCH] CRM-16084 Unit test: direction of chaining relationships. ---------------------------------------- * CRM-16084: API: when getting contact chaining relationships, the relationship direction is ignored https://issues.civicrm.org/jira/browse/CRM-16084 --- tests/phpunit/api/v3/ContactTest.php | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 8bf5780212..8247cbaca8 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -865,6 +865,78 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccess('contact', 'delete', $result); } + /** + * Test for direction when chaining relationships. + * + * https://issues.civicrm.org/jira/browse/CRM-16084 + */ + public function testDirectionChainingRelationshipsCRM16084() { + // Some contact, called Jules. + $create_result_1 = $this->callAPISuccess('contact', 'create', array( + 'first_name' => 'Jules', + 'last_name' => 'Smos', + 'contact_type' => 'Individual', + )); + + // Another contact: Jos, child of Jules. + $create_params = array( + 'first_name' => 'Jos', + 'last_name' => 'Smos', + 'contact_type' => 'Individual', + 'api.relationship.create' => array( + array( + 'contact_id_a' => '$value.id', + 'contact_id_b' => $create_result_1['id'], + // child of + 'relationship_type_id' => 1, + ), + ), + ); + $create_result_2 = $this->callAPISuccess('contact', 'create', $create_params); + + // Mia is the child of Jos. + $create_params = array( + 'first_name' => 'Mia', + 'last_name' => 'Smos', + 'contact_type' => 'Individual', + 'api.relationship.create' => array( + array( + 'contact_id_a' => '$value.id', + 'contact_id_b' => $create_result_2['id'], + // child of + 'relationship_type_id' => 1, + ), + ), + ); + $create_result_3 = $this->callAPISuccess('contact', 'create', $create_params); + + // Get Jos and his children. + $get_params = array( + 'sequential' => 1, + 'id' => $create_result_2['id'], + 'api.relationship.get' => array( + 'contact_id_b' => '$value.id', + 'relationship_type_id' => 1, + ), + ); + $get_result = $this->callAPISuccess('contact', 'getsingle', $get_params); + + // Clean up first. + $this->callAPISuccess('contact', 'delete', array( + 'id' => $create_result_1['id'], + )); + $this->callAPISuccess('contact', 'delete', array( + 'id' => $create_result_2['id'], + )); + $this->callAPISuccess('contact', 'delete', array( + 'id' => $create_result_2['id'], + )); + + // Assert. + $this->assertEquals(1, $get_result['api.relationship.get']['count']); + $this->assertEquals($create_result_3['id'], $get_result['api.relationship.get']['values'][0]['contact_id_a']); + } + /** * Verify that attempt to create individual contact with first, and last names and email succeeds. */ -- 2.25.1