From: Johan Vervloet Date: Tue, 10 Mar 2015 13:42:23 +0000 (+0100) Subject: A unit test for CRM-15983. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c4bc3d5ab666b0b314bdf5bc993c11cbbdf3423a;p=civicrm-core.git A unit test for CRM-15983. This hack seems to fix CRM-15983 as well. (At least in the case that contact_id_a or contact_id_b is given.) I copied the unit test for CRM-15983. ---------------------------------------- * CRM-15983: limit and sort options don't work inside chained call to relationship API https://issues.civicrm.org/jira/browse/CRM-15983 --- diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 8247cbaca8..be633e4ec9 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -631,6 +631,70 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id'])); } + /** + * Test sort and limit for chained relationship get. + * + * https://issues.civicrm.org/jira/browse/CRM-15983 + */ + public function testSortLimitChainedRelationshipGetCRM15983() { + // Some contact + $create_result_1 = $this->callAPISuccess('contact', 'create', array( + 'first_name' => 'Jules', + 'last_name' => 'Smos', + 'contact_type' => 'Individual', + )); + + // Create another contact with two relationships. + $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'], + // spouse of: + 'relationship_type_id' => 2, + 'start_date' => '2005-01-12', + 'end_date' => '2006-01-11', + 'description' => 'old', + ), + array( + 'contact_id_a' => '$value.id', + 'contact_id_b' => $create_result_1['id'], + // spouse of (was married twice :)) + 'relationship_type_id' => 2, + 'start_date' => '2006-07-01', + 'end_date' => '2010-07-01', + 'description' => 'new', + ), + ), + ); + $create_result = $this->callAPISuccess('contact', 'create', $create_params); + + // Try to retrieve the contact and the most recent relationship. + $get_params = array( + 'sequential' => 1, + 'id' => $create_result['id'], + 'api.relationship.get' => array( + 'contact_id_a' => '$value.id', + 'options' => array( + 'limit' => '1', + 'sort' => 'start_date DESC', + )), + ); + $get_result = $this->callAPISuccess('contact', 'getsingle', $get_params); + + // Clean up. + $this->callAPISuccess('contact', 'delete', array( + 'id' => $create_result['id'], + )); + + // Assert. + $this->assertEquals(1, $get_result['api.relationship.get']['count']); + $this->assertEquals('new', $get_result['api.relationship.get']['values'][0]['description']); + } + /** * Test apostrophe works in get & create. */