From 9a35064457a46620a57e89626036c4d7c7364925 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 7 Oct 2019 17:50:12 +0200 Subject: [PATCH] [NFC] minor simplification This just changes how return vars are handled to make it clearer that ONLY contact::Create cares about location_block::create return values --- CRM/Event/Form/ManageEvent/Location.php | 3 +- api/v3/LocBlock.php | 1 + tests/phpunit/CRM/Core/BAO/LocationTest.php | 103 +------------------- 3 files changed, 4 insertions(+), 103 deletions(-) diff --git a/CRM/Event/Form/ManageEvent/Location.php b/CRM/Event/Form/ManageEvent/Location.php index 7e2c8a8889..3573106ad5 100644 --- a/CRM/Event/Form/ManageEvent/Location.php +++ b/CRM/Event/Form/ManageEvent/Location.php @@ -262,8 +262,7 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { } // create/update event location - $location = CRM_Core_BAO_Location::create($params, TRUE, 'event'); - $params['loc_block_id'] = $location['id']; + $params['loc_block_id'] = CRM_Core_BAO_Location::create($params, TRUE, 'event')['id']; // finally update event params $params['id'] = $this->_id; diff --git a/api/v3/LocBlock.php b/api/v3/LocBlock.php index 0e7ef7c642..7572e0fc00 100644 --- a/api/v3/LocBlock.php +++ b/api/v3/LocBlock.php @@ -41,6 +41,7 @@ * API result array. * * @throws \API_Exception + * @throws \CiviCRM_API3_Exception */ function civicrm_api3_loc_block_create($params) { $entities = []; diff --git a/tests/phpunit/CRM/Core/BAO/LocationTest.php b/tests/phpunit/CRM/Core/BAO/LocationTest.php index 7df8d0ec80..8c78000759 100644 --- a/tests/phpunit/CRM/Core/BAO/LocationTest.php +++ b/tests/phpunit/CRM/Core/BAO/LocationTest.php @@ -148,9 +148,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $params['contact_id'] = $contactId; - $location = CRM_Core_BAO_Location::create($params); - - $locBlockId = CRM_Utils_Array::value('id', $location); + $locBlockId = CRM_Core_BAO_Location::create($params); //Now check DB for contact $searchParams = [ @@ -201,8 +199,6 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $compareParams = ['phone' => '9833910234']; $this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams); - //delete the location block - CRM_Core_BAO_Location::deleteLocBlock($locBlockId); $this->contactDelete($contactId); } @@ -267,8 +263,7 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { //create location block. //with various element of location block //like address, phone, email, im. - $location = CRM_Core_BAO_Location::create($params, NULL, TRUE); - $locBlockId = CRM_Utils_Array::value('id', $location); + $locBlockId = CRM_Core_BAO_Location::create($params, NULL, TRUE)['id']; //update event record with location block id $eventParams = [ @@ -356,100 +351,6 @@ class CRM_Core_BAO_LocationTest extends CiviUnitTestCase { $this->contactDelete($this->_contactId); } - /** - * DeleteLocBlock() method - * delete the location block - * created with various elements. - */ - public function testDeleteLocBlock() { - $this->_contactId = $this->individualCreate(); - //create test event record. - $event = $this->eventCreate(); - $params['location'][1] = [ - 'location_type_id' => 1, - 'is_primary' => 1, - 'address' => [ - 'street_address' => 'Saint Helier St', - 'supplemental_address_1' => 'Hallmark Ct', - 'supplemental_address_2' => 'Jersey Village', - 'supplemental_address_3' => 'My Town', - 'city' => 'Newark', - 'postal_code' => '01903', - 'country_id' => 1228, - 'state_province_id' => 1029, - 'geo_code_1' => '18.219023', - 'geo_code_2' => '-105.00973', - ], - 'email' => [ - '1' => ['email' => 'john.smith@example.org'], - ], - 'phone' => [ - '1' => [ - 'phone_type_id' => 1, - 'phone' => '303443689', - ], - '2' => [ - 'phone_type_id' => 2, - 'phone' => '9833910234', - ], - ], - 'im' => [ - '1' => [ - 'name' => 'jane.doe', - 'provider_id' => 1, - ], - ], - ]; - $params['entity_id'] = $event['id']; - $params['entity_table'] = 'civicrm_event'; - - //create location block. - //with various elements - //like address, phone, email, im. - $location = CRM_Core_BAO_Location::create($params, NULL, TRUE); - $locBlockId = CRM_Utils_Array::value('id', $location); - //update event record with location block id - $eventParams = [ - 'id' => $event['id'], - 'loc_block_id' => $locBlockId, - ]; - CRM_Event_BAO_Event::add($eventParams); - - //delete the location block - CRM_Core_BAO_Location::deleteLocBlock($locBlockId); - - //Now check DB for location elements. - //Now check DB for Address - $this->assertDBNull('CRM_Core_DAO_Address', 'Saint Helier St', 'id', 'street_address', - 'Database check, Address deleted successfully.' - ); - //Now check DB for Email - $this->assertDBNull('CRM_Core_DAO_Email', 'john.smith@example.org', 'id', 'email', - 'Database check, Email deleted successfully.' - ); - //Now check DB for Phone - $this->assertDBNull('CRM_Core_DAO_Phone', '303443689', 'id', 'phone', - 'Database check, Phone deleted successfully.' - ); - //Now check DB for Mobile - $this->assertDBNull('CRM_Core_DAO_Phone', '9833910234', 'id', 'phone', - 'Database check, Mobile deleted successfully.' - ); - //Now check DB for IM - $this->assertDBNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name', - 'Database check, IM deleted successfully.' - ); - - //cleanup DB by deleting the record. - $this->eventDelete($event['id']); - $this->contactDelete($this->_contactId); - - //Now check DB for Event - $this->assertDBNull('CRM_Event_DAO_Event', $event['id'], 'id', 'id', - 'Database check, Event deleted successfully.' - ); - } - /** * GetValues() method * get the values of various location elements -- 2.25.1