From e0efd2d0d92d16e407bd0df001d3bd012df95676 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 18 Aug 2013 20:06:55 +1200 Subject: [PATCH] CRM-13179 add a few extra fields to billing profile get (middle_name, state_province, postal_code) --- CRM/Member/BAO/Membership.php | 6 +++++ api/v3/Profile.php | 2 +- api/v3/examples/ProfileGet.php | 8 ++++-- api/v3/examples/ProfileSet.php | 10 +++---- tests/phpunit/CiviTest/CiviUnitTestCase.php | 2 +- tests/phpunit/api/v3/ProfileTest.php | 30 ++++++++++----------- 6 files changed, 33 insertions(+), 25 deletions(-) diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 89d924dbdf..9614d1e70d 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1487,6 +1487,10 @@ AND civicrm_membership.is_test = %2"; } /** + * @todo - this form method needs to have the interaction with the form layer removed from it + * as a BAO function. Note that the api now supports membership renewals & it is not clear this function does anything + * not done by the membership.create api (with a lot less unit tests) + * * This method will renew / create the membership depending on * whether the given contact has a membership or not. And will add * the modified dates for membership and in the log table. @@ -1526,6 +1530,8 @@ AND civicrm_membership.is_test = %2"; // check is it pending. - CRM-4555 $pending = FALSE; + //@todo this is a BAO function & should not inspect the form - the form should do this + // & pass required params to the BAO if (CRM_Utils_Array::value('minimum_fee', $membershipTypeDetails) > 0.0) { if (((isset($form->_contributeMode) && $form->_contributeMode == 'notify') || CRM_Utils_Array::value('is_pay_later', $form->_params) || diff --git a/api/v3/Profile.php b/api/v3/Profile.php index 36e9e2fdfc..16a0214ec0 100644 --- a/api/v3/Profile.php +++ b/api/v3/Profile.php @@ -366,7 +366,7 @@ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) { 'api.address.get.2' => array('is_billing' => True, 'return' => $addressFields), 'api.email.get.1' => array('location_type_id' => 'Billing',), 'api.email.get.2' => array('is_billing' => True,), - 'return' => 'api.email.get, api.address.get, api.address.getoptions, email, first_name, last_name, middle_name,' . implode($addressFields, ','), + 'return' => 'api.email.get, api.address.get, api.address.getoptions, state_province, email, first_name, last_name, middle_name, ' . implode($addressFields, ','), ) ); diff --git a/api/v3/examples/ProfileGet.php b/api/v3/examples/ProfileGet.php index 295bf073ad..a0d0732adb 100644 --- a/api/v3/examples/ProfileGet.php +++ b/api/v3/examples/ProfileGet.php @@ -44,22 +44,26 @@ function profile_get_expectedresult(){ 'phone-1-1' => '021 512 755', 'country-1' => '1228', 'state_province-1' => '1021', + 'postal_code-1' => '90210', ), '1' => array( 'first_name' => 'abc1', 'last_name' => 'xyz1', + 'postal_code-1' => '90210', 'country-1' => '1228', 'state_province-1' => '1021', ), 'Billing' => array( 'billing_first_name' => 'abc1', - 'billing_middle_name' => '', + 'billing_middle_name' => 'J.', 'billing_last_name' => 'xyz1', 'billing_street_address-5' => '', 'billing_city-5' => '', - 'billing_state_province_id-5' => '', + 'billing_state_province_id-5' => '1021', 'billing_country_id-5' => '', + 'billing_postal_code-5' => '90210', 'billing-email-5' => 'abc1.xyz1@yahoo.com', + 'email-5' => 'abc1.xyz1@yahoo.com', ), ), ); diff --git a/api/v3/examples/ProfileSet.php b/api/v3/examples/ProfileSet.php index 835ae7079a..7d4e51b119 100644 --- a/api/v3/examples/ProfileSet.php +++ b/api/v3/examples/ProfileSet.php @@ -53,7 +53,7 @@ function profile_set_expectedresult(){ 'legal_identifier' => '', 'external_identifier' => '', 'sort_name' => 'xyz2, abc2', - 'display_name' => 'abc2 xyz2', + 'display_name' => 'Mr. abc2 xyz2 II', 'nick_name' => '', 'legal_name' => '', 'image_URL' => '', @@ -63,10 +63,10 @@ function profile_set_expectedresult(){ 'hash' => '67eac7789eaee00', 'api_key' => '', 'first_name' => 'abc2', - 'middle_name' => '', + 'middle_name' => 'J.', 'last_name' => 'xyz2', - 'prefix_id' => '', - 'suffix_id' => '', + 'prefix_id' => '3', + 'suffix_id' => '3', 'email_greeting_id' => '1', 'email_greeting_custom' => '', 'email_greeting_display' => 'Dear abc1', @@ -75,7 +75,7 @@ function profile_set_expectedresult(){ 'postal_greeting_display' => 'Dear abc1', 'addressee_id' => '1', 'addressee_custom' => '', - 'addressee_display' => '{contact.individual_prefix} abc1 xyz1 {contact.individual_suffix}', + 'addressee_display' => '{contact.individual_prefix} abc1 J. xyz1 {contact.individual_suffix}', 'job_title' => '', 'gender_id' => '', 'birth_date' => '', diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 59c8493be5..585bef122e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -875,7 +875,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'suffix_id' => 3, 'email' => 'anthony_anderson@civicrm.org', 'contact_type' => 'Individual', - ),$params); + ), $params); return $this->_contactCreate($params); } diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index c570438989..f84d71cf2c 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -125,13 +125,16 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $this->assertFalse(array_key_exists('email-Primary', $result['values'][1]), 'profile 1 doesn not include email'); $this->assertEquals($result['values']['Billing'], array( 'billing_first_name' => 'abc1', - 'billing_middle_name' => '', + 'billing_middle_name' => 'J.', 'billing_last_name' => 'xyz1', 'billing_street_address-5' => '', 'billing_city-5' => '', - 'billing_state_province_id-5' => '', + 'billing_state_province_id-5' => '1021', 'billing_country_id-5' => '', 'billing-email-5' => 'abc1.xyz1@yahoo.com', + 'billing_postal_code-5' => '90210', + 'billing-email-5' => 'abc1.xyz1@yahoo.com', + 'email-5' => 'abc1.xyz1@yahoo.com', )); } @@ -152,13 +155,15 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $this->assertEquals('abc1', $result['values'][1]['first_name']); $this->assertEquals($result['values']['Billing'], array( 'billing_first_name' => 'abc1', - 'billing_middle_name' => '', + 'billing_middle_name' => 'J.', 'billing_last_name' => 'xyz1', 'billing_street_address-5' => '25 Big Street', 'billing_city-5' => 'big city', 'billing_state_province_id-5' => '', 'billing_country_id-5' => '', 'billing-email-5' => 'big@once.com', + 'email-5' => 'big@once.com', + 'billing_postal_code-5' => '', )); } /** @@ -498,11 +503,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { /* * Helper function to create an Individual with address/email/phone info. Import UF Group and UF Fields */ - function _createIndividualContact() { - $contactParams = array( + function _createIndividualContact($params = array()) { + $contactParams = array_merge(array( 'first_name' => 'abc1', 'last_name' => 'xyz1', - 'contact_type' => 'Individual', 'email' => 'abc1.xyz1@yahoo.com', 'api.address.create' => array( 'location_type_id' => 1, @@ -513,6 +517,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'state_province' => 'Michigan', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village', + 'postal_code' => '90210', ), 'api.phone.create' => array( 'location_type_id' => '1', @@ -520,17 +525,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'phone_type_id' => '1', 'is_primary' => '1', ), + ), $params ); - $contact = $this->callAPISuccess('contact', 'create', $contactParams); - - $keys = array_keys($contact['values']); - $contactId = array_pop($keys); - - $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.address.create']) - ); - $this->assertEquals(0, $contact['values'][$contactId]['api.phone.create']['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.phone.create']) - ); + $contactID = $this->individualCreate($contactParams); // Create new profile having group_type: Contact,Individual $op = new PHPUnit_Extensions_Database_Operation_Insert(); @@ -549,7 +547,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { // expected result of above created profile with contact Id $contactId - $profileData[$contactId] = array( + $profileData[$contactID] = array( 'first_name' => 'abc1', 'last_name' => 'xyz1', 'email-Primary' => 'abc1.xyz1@yahoo.com', -- 2.25.1