From f8de858335c469e28d4945c9186a091a8464fc9f Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Tue, 24 Mar 2015 10:23:00 +0100 Subject: [PATCH] CRM-16168 - Added 2 unit tests. In the two tests, I try to get an event and its loc block in one chained call. In the first test, a loc block exists, so it should be returned. In the second test, no loc block exists. This should not crash the API. ---------------------------------------- * CRM-16168: Chained call event-loc block returns an error if no loc block exists. https://issues.civicrm.org/jira/browse/CRM-16168 --- tests/phpunit/api/v3/EventTest.php | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index 6407c635e6..891010ef67 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -280,6 +280,66 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->callAPISuccess('event', 'delete', array('id' => $result['id'])); } + /** + * Chaining get event and loc block. + */ + public function testChainingGetLocBlock() { + // create a loc block and an event for that loc block. + $eventParams = $this->_params[0]; + $eventParams['loc_bloc_id'] = '$value.id'; + $locBlockParams = array( + 'address' => array( + 'street_address' => 'Kipdorp 24', + 'postal_code' => '2000', + 'city' => 'Antwerpen', + 'country_id' => '1020', + 'location_type_id' => '1', + ), + 'api.Event.create' => $eventParams, + 'sequential' => 1, + ); + $createResult = $this->callAPIAndDocument('LocBlock', 'create', $locBlockParams, __FUNCTION__, __FILE__); + $locBlockId = $createResult['id']; + $addressId = $createResult['values'][0]['address_id']; + $eventId = $createResult['values'][0]['api.Event.create']['id']; + + // request the event with its loc block: + $check = $this->callAPISuccess($this->_entity, 'getsingle', array( + 'id' => $eventId, + 'api.LocBlock.get' => array('id' => '$value.loc_block_id'), + 'sequential' => 1, + )); + + // assert + $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__); + $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__); + $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__); + + // cleanup + $this->callAPISuccess($this->_entity, 'delete', array('id' => $eventId)); + } + + /** + * Chaining get event and non existing loc block. + * + * Even if there is no loc block, at least the event should be returned. + * http://forum.civicrm.org/index.php/topic,36113.0.html + */ + public function testChainingGetNonExistingLocBlock() { + $params = $this->_params[0]; + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); + + $check = $this->callAPISuccess($this->_entity, 'get', array( + 'id' => $result['id'], + // this chaining request should not break things: + 'api.LocBlock.get' => array('id' => '$value.loc_block_id'), + )); + $this->assertEquals(0, $check['is_error'], ' in line ' . __LINE__); + $this->assertEquals($result['id'], $check['id'], ' in line ' . __LINE__); + + $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); + } + /** * Check with complete array + custom field. * -- 2.25.1