$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.
*/